From fcbac485f885d90f6341d7acaf75157a01d81892 Mon Sep 17 00:00:00 2001 From: Connortsui20 <87130162+Connortsui20@users.noreply.github.com> Date: Tue, 8 Aug 2023 08:51:34 -0400 Subject: [PATCH] Show whether file readonly in statusline (#7740) --- Cargo.lock | 1 + book/src/configuration.md | 3 ++- helix-term/src/commands/typed.rs | 2 +- helix-term/src/ui/statusline.rs | 14 +++++++++++++ helix-view/Cargo.toml | 1 + helix-view/src/document.rs | 35 ++++++++++++++++++++++++++++++++ helix-view/src/editor.rs | 4 ++++ 7 files changed, 58 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9a7dee720..128d8825f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1392,6 +1392,7 @@ dependencies = [ "log", "once_cell", "parking_lot", + "rustix 0.38.4", "serde", "serde_json", "slotmap", diff --git a/book/src/configuration.md b/book/src/configuration.md index 4c152bf4d..eb2cf473c 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -89,7 +89,7 @@ ### `[editor.statusline]` Section | Key | Description | Default | | --- | --- | --- | -| `left` | A list of elements aligned to the left of the statusline | `["mode", "spinner", "file-name", "file-modification-indicator"]` | +| `left` | A list of elements aligned to the left of the statusline | `["mode", "spinner", "file-name", "read-only-indicator", "file-modification-indicator"]` | | `center` | A list of elements aligned to the middle of the statusline | `[]` | | `right` | A list of elements aligned to the right of the statusline | `["diagnostics", "selections", "register", "position", "file-encoding"]` | | `separator` | The character used to separate elements in the statusline | `"│"` | @@ -108,6 +108,7 @@ ### `[editor.statusline]` Section | `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-line-ending` | The file line endings (CRLF or LF) | +| `read-only-indicator` | An indicator that shows `[readonly]` when a file cannot be written | | `total-line-numbers` | The total line numbers of the opened file | | `file-type` | The type of the opened file | | `diagnostics` | The number of warnings and/or errors | diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 67640f797..5bb9c6c41 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -672,7 +672,7 @@ pub fn write_all_impl( } if doc.path().is_none() { if write_scratch { - errors.push("cannot write a buffer without a filename\n"); + errors.push("cannot write a buffer without a filename"); } return None; } diff --git a/helix-term/src/ui/statusline.rs b/helix-term/src/ui/statusline.rs index 61fca609b..52dd49f9e 100644 --- a/helix-term/src/ui/statusline.rs +++ b/helix-term/src/ui/statusline.rs @@ -145,6 +145,7 @@ fn get_render_function(element_id: StatusLineElementID) -> impl Fn(&mut Rende helix_view::editor::StatusLineElement::FileModificationIndicator => { render_file_modification_indicator } + helix_view::editor::StatusLineElement::ReadOnlyIndicator => render_read_only_indicator, 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, @@ -442,6 +443,19 @@ fn render_file_modification_indicator(context: &mut RenderContext, write: F) write(context, title, None); } +fn render_read_only_indicator(context: &mut RenderContext, write: F) +where + F: Fn(&mut RenderContext, String, Option