on master help sign in
add statusline element to display file line endings (#3113)
8b2a141Alexis Kalabura
book/src/configuration.md+2−1
@@ -62,7 +62,7 @@ Statusline elements can be defined as follows:
62[editor.statusline]
62[editor.statusline]
63left = ["mode", "spinner"]
63left = ["mode", "spinner"]
64center = ["file-name"]
64center = ["file-name"]
65−right = ["diagnostics", "selections", "position", "file-encoding", "file-type"]
65+right = ["diagnostics", "selections", "position", "file-encoding", "file-line-ending", "file-type"]
66```
66```
67
67
68The following elements can be configured:
68The following elements can be configured:
@@ -73,6 +73,7 @@ The following elements can be configured:
73| `spinner` | A progress spinner indicating LSP activity |
73| `spinner` | A progress spinner indicating LSP activity |
74| `file-name` | The path/name of the opened file |
74| `file-name` | The path/name of the opened file |
75| `file-encoding` | The encoding of the opened file if it differs from UTF-8 |
75| `file-encoding` | The encoding of the opened file if it differs from UTF-8 |
76+| `file-line-ending` | The file line endings (CRLF or LF) |
76| `file-type` | The type of the opened file |
77| `file-type` | The type of the opened file |
77| `diagnostics` | The number of warnings and/or errors |
78| `diagnostics` | The number of warnings and/or errors |
78| `selections` | The number of active selections |
79| `selections` | The number of active selections |
helix-term/src/commands/typed.rs+2−3
@@ -413,12 +413,11 @@ fn set_line_ending(
413
413
414 // Attempt to parse argument as a line ending.
414 // Attempt to parse argument as a line ending.
415 let line_ending = match arg {
415 let line_ending = match arg {
416− // We check for CR first because it shares a common prefix with CRLF.
417− #[cfg(feature = "unicode-lines")]
418− arg if arg.starts_with("cr") => CR,
419 arg if arg.starts_with("crlf") => Crlf,
416 arg if arg.starts_with("crlf") => Crlf,
420 arg if arg.starts_with("lf") => LF,
417 arg if arg.starts_with("lf") => LF,
421 #[cfg(feature = "unicode-lines")]
418 #[cfg(feature = "unicode-lines")]
419+ arg if arg.starts_with("cr") => CR,
420+ #[cfg(feature = "unicode-lines")]
422 arg if arg.starts_with("ff") => FF,
421 arg if arg.starts_with("ff") => FF,
423 #[cfg(feature = "unicode-lines")]
422 #[cfg(feature = "unicode-lines")]
424 arg if arg.starts_with("nel") => Nel,
423 arg if arg.starts_with("nel") => Nel,
helix-term/src/ui/statusline.rs+26
@@ -138,6 +138,7 @@ where
138 helix_view::editor::StatusLineElement::Spinner => render_lsp_spinner,
138 helix_view::editor::StatusLineElement::Spinner => render_lsp_spinner,
139 helix_view::editor::StatusLineElement::FileName => render_file_name,
139 helix_view::editor::StatusLineElement::FileName => render_file_name,
140 helix_view::editor::StatusLineElement::FileEncoding => render_file_encoding,
140 helix_view::editor::StatusLineElement::FileEncoding => render_file_encoding,
141+ helix_view::editor::StatusLineElement::FileLineEnding => render_file_line_ending,
141 helix_view::editor::StatusLineElement::FileType => render_file_type,
142 helix_view::editor::StatusLineElement::FileType => render_file_type,
142 helix_view::editor::StatusLineElement::Diagnostics => render_diagnostics,
143 helix_view::editor::StatusLineElement::Diagnostics => render_diagnostics,
143 helix_view::editor::StatusLineElement::Selections => render_selections,
144 helix_view::editor::StatusLineElement::Selections => render_selections,
@@ -280,6 +281,31 @@ where
280 }
281 }
281}
282}
282
283
284+fn render_file_line_ending<F>(context: &mut RenderContext, write: F)
285+where
286+ F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
287+{
288+ use helix_core::LineEnding::*;
289+ let line_ending = match context.doc.line_ending {
290+ Crlf => "CRLF",
291+ LF => "LF",
292+ #[cfg(feature = "unicode-lines")]
293+ VT => "VT", // U+000B -- VerticalTab
294+ #[cfg(feature = "unicode-lines")]
295+ FF => "FF", // U+000C -- FormFeed
296+ #[cfg(feature = "unicode-lines")]
297+ CR => "CR", // U+000D -- CarriageReturn
298+ #[cfg(feature = "unicode-lines")]
299+ Nel => "NEL", // U+0085 -- NextLine
300+ #[cfg(feature = "unicode-lines")]
301+ LS => "LS", // U+2028 -- Line Separator
302+ #[cfg(feature = "unicode-lines")]
303+ PS => "PS", // U+2029 -- ParagraphSeparator
304+ };
305+
306+ write(context, format!(" {} ", line_ending), None);
307+}
308+
283fn render_file_type<F>(context: &mut RenderContext, write: F)
309fn render_file_type<F>(context: &mut RenderContext, write: F)
284where
310where
285 F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
311 F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
helix-view/src/editor.rs+3
@@ -232,6 +232,9 @@ pub enum StatusLineElement {
232 /// The file encoding
232 /// The file encoding
233 FileEncoding,
233 FileEncoding,
234
234
235+ /// The file line endings (CRLF or LF)
236+ FileLineEnding,
237+
235 /// The file type (language ID or "text")
238 /// The file type (language ID or "text")
236 FileType,
239 FileType,
237
240