Skip to content

Commit

Permalink
feat: add 'file-abs-path' to statusline (helix-editor#4434)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcardamo committed Oct 30, 2022
1 parent b4a3dd8 commit cdbf16f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ The following statusline elements can be configured:
| `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-abs-path` | The absolute path/name 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 |
Expand Down
21 changes: 21 additions & 0 deletions helix-term/src/ui/statusline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ where
helix_view::editor::StatusLineElement::Mode => render_mode,
helix_view::editor::StatusLineElement::Spinner => render_lsp_spinner,
helix_view::editor::StatusLineElement::FileName => render_file_name,
helix_view::editor::StatusLineElement::FileAbsPath => render_file_abs_path,
helix_view::editor::StatusLineElement::FileEncoding => render_file_encoding,
helix_view::editor::StatusLineElement::FileLineEnding => render_file_line_ending,
helix_view::editor::StatusLineElement::FileType => render_file_type,
Expand Down Expand Up @@ -344,6 +345,26 @@ where
write(context, format!(" {} ", file_type), None);
}

fn render_file_abs_path<F>(context: &mut RenderContext, write: F)
where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
{
let title = {
let path = context.doc.canonicalized_path();
let path = path
.as_ref()
.map(|p| p.to_string_lossy())
.unwrap_or_else(|| SCRATCH_BUFFER_NAME.into());
format!(
" {}{} ",
path,
if context.doc.is_modified() { "[+]" } else { "" }
)
};

write(context, title, None);
}

fn render_file_name<F>(context: &mut RenderContext, write: F)
where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
Expand Down
11 changes: 11 additions & 0 deletions helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,17 @@ impl Document {
.map(helix_core::path::get_relative_path)
}

pub fn canonicalized_path(&self) -> Option<PathBuf> {
if let Some(path) = self.path.as_deref() {
helix_core::path::get_canonicalized_path(&path).ok()
} else {
None
}
// self.path
// .as_deref()
// .map(helix_core::path::get_canonicalized_path)
}

pub fn display_name(&self) -> Cow<'static, str> {
self.relative_path()
.map(|path| path.to_string_lossy().to_string().into())
Expand Down
3 changes: 3 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ pub enum StatusLineElement {
/// The file nane/path, including a dirty flag if it's unsaved
FileName,

/// The file absolute path, including a dirty flag if it's unsaved
FileAbsPath,

/// The file encoding
FileEncoding,

Expand Down

0 comments on commit cdbf16f

Please sign in to comment.