1
0
Fork 0
mirror of https://github.com/helix-editor/helix synced 2024-06-08 22:16:07 +02:00

Add a status line element that shows just the basename of the file (#5318)

This commit is contained in:
Nick 2022-12-31 19:48:14 +05:30 committed by GitHub
parent 63dcaae1b9
commit c9ed42cdec
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

View File

@ -97,6 +97,7 @@ ### `[editor.statusline]` Section
| `mode` | The current editor mode (`mode.normal`/`mode.insert`/`mode.select`) |
| `spinner` | A progress spinner indicating LSP activity |
| `file-name` | The path/name of the opened file |
| `file-base-name` | The basename of the opened file |
| `file-encoding` | The encoding of the opened file if it differs from UTF-8 |
| `file-line-ending` | The file line endings (CRLF or LF) |
| `total-line-numbers` | The total line numbers of the opened file |

View File

@ -139,6 +139,7 @@ fn get_render_function<F>(element_id: StatusLineElementID) -> impl Fn(&mut Rende
match element_id {
helix_view::editor::StatusLineElement::Mode => render_mode,
helix_view::editor::StatusLineElement::Spinner => render_lsp_spinner,
helix_view::editor::StatusLineElement::FileBaseName => render_file_base_name,
helix_view::editor::StatusLineElement::FileName => render_file_name,
helix_view::editor::StatusLineElement::FileEncoding => render_file_encoding,
helix_view::editor::StatusLineElement::FileLineEnding => render_file_line_ending,
@ -426,6 +427,26 @@ fn render_file_name<F>(context: &mut RenderContext, write: F)
write(context, title, None);
}
fn render_file_base_name<F>(context: &mut RenderContext, write: F)
where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
{
let title = {
let rel_path = context.doc.relative_path();
let path = rel_path
.as_ref()
.and_then(|p| p.as_path().file_name().map(|s| s.to_string_lossy()))
.unwrap_or_else(|| SCRATCH_BUFFER_NAME.into());
format!(
" {}{} ",
path,
if context.doc.is_modified() { "[+]" } else { "" }
)
};
write(context, title, None);
}
fn render_separator<F>(context: &mut RenderContext, write: F)
where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,

View File

@ -314,7 +314,10 @@ pub enum StatusLineElement {
/// The LSP activity spinner
Spinner,
/// The file nane/path, including a dirty flag if it's unsaved
/// The base file name, including a dirty flag if it's unsaved
FileBaseName,
/// The relative file path, including a dirty flag if it's unsaved
FileName,
/// The file encoding