add 'file-absolute-path' to statusline (#4535)

* feat: add 'file-abs-path' to statusline (#4434)

* cleanup implementation

* rename to be non-abbreviated names

---------

Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
pull/8727/head^2
Dan Cardamore 8 months ago committed by GitHub
parent e36774c2c8
commit 3890376a23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -108,6 +108,7 @@ The following statusline elements can be configured:
| `mode` | The current editor mode (`mode.normal`/`mode.insert`/`mode.select`) | | `mode` | The current editor mode (`mode.normal`/`mode.insert`/`mode.select`) |
| `spinner` | A progress spinner indicating LSP activity | | `spinner` | A progress spinner indicating LSP activity |
| `file-name` | The path/name of the opened file | | `file-name` | The path/name of the opened file |
| `file-absolute-path` | The absolute path/name of the opened file |
| `file-base-name` | The basename of the opened file | | `file-base-name` | The basename of the opened file |
| `file-modification-indicator` | The indicator to show whether the file is modified (a `[+]` appears when there are unsaved changes) | | `file-modification-indicator` | The indicator to show whether the file is modified (a `[+]` appears when there are unsaved changes) |
| `file-encoding` | The encoding of the opened file if it differs from UTF-8 | | `file-encoding` | The encoding of the opened file if it differs from UTF-8 |

@ -142,6 +142,7 @@ where
helix_view::editor::StatusLineElement::Spinner => render_lsp_spinner, helix_view::editor::StatusLineElement::Spinner => render_lsp_spinner,
helix_view::editor::StatusLineElement::FileBaseName => render_file_base_name, helix_view::editor::StatusLineElement::FileBaseName => render_file_base_name,
helix_view::editor::StatusLineElement::FileName => render_file_name, helix_view::editor::StatusLineElement::FileName => render_file_name,
helix_view::editor::StatusLineElement::FileAbsolutePath => render_file_absolute_path,
helix_view::editor::StatusLineElement::FileModificationIndicator => { helix_view::editor::StatusLineElement::FileModificationIndicator => {
render_file_modification_indicator render_file_modification_indicator
} }
@ -430,6 +431,22 @@ where
write(context, title, None); write(context, title, None);
} }
fn render_file_absolute_path<F>(context: &mut RenderContext, write: F)
where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
{
let title = {
let path = context.doc.path();
let path = path
.as_ref()
.map(|p| p.to_string_lossy())
.unwrap_or_else(|| SCRATCH_BUFFER_NAME.into());
format!(" {} ", path)
};
write(context, title, None);
}
fn render_file_modification_indicator<F>(context: &mut RenderContext, write: F) fn render_file_modification_indicator<F>(context: &mut RenderContext, write: F)
where where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy, F: Fn(&mut RenderContext, String, Option<Style>) + Copy,

@ -487,6 +487,9 @@ pub enum StatusLineElement {
/// The relative file path /// The relative file path
FileName, FileName,
/// The file absolute path
FileAbsolutePath,
// The file modification indicator // The file modification indicator
FileModificationIndicator, FileModificationIndicator,

Loading…
Cancel
Save