Skip to content

Commit 8b2a141

Browse files
authored
add statusline element to display file line endings (#3113)
* add statusline element to display file line endings * run cargo fmt --all * change the word *ending* from plural to singular * support for the unicode-lines feature flag
1 parent 906259c commit 8b2a141

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

book/src/configuration.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Statusline elements can be defined as follows:
6262
[editor.statusline]
6363
left = ["mode", "spinner"]
6464
center = ["file-name"]
65-
right = ["diagnostics", "selections", "position", "file-encoding", "file-type"]
65+
right = ["diagnostics", "selections", "position", "file-encoding", "file-line-ending", "file-type"]
6666
```
6767

6868
The following elements can be configured:
@@ -73,6 +73,7 @@ The following elements can be configured:
7373
| `spinner` | A progress spinner indicating LSP activity |
7474
| `file-name` | The path/name of the opened file |
7575
| `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) |
7677
| `file-type` | The type of the opened file |
7778
| `diagnostics` | The number of warnings and/or errors |
7879
| `selections` | The number of active selections |

helix-term/src/commands/typed.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,11 @@ fn set_line_ending(
413413

414414
// Attempt to parse argument as a line ending.
415415
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,
419416
arg if arg.starts_with("crlf") => Crlf,
420417
arg if arg.starts_with("lf") => LF,
421418
#[cfg(feature = "unicode-lines")]
419+
arg if arg.starts_with("cr") => CR,
420+
#[cfg(feature = "unicode-lines")]
422421
arg if arg.starts_with("ff") => FF,
423422
#[cfg(feature = "unicode-lines")]
424423
arg if arg.starts_with("nel") => Nel,

helix-term/src/ui/statusline.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ where
138138
helix_view::editor::StatusLineElement::Spinner => render_lsp_spinner,
139139
helix_view::editor::StatusLineElement::FileName => render_file_name,
140140
helix_view::editor::StatusLineElement::FileEncoding => render_file_encoding,
141+
helix_view::editor::StatusLineElement::FileLineEnding => render_file_line_ending,
141142
helix_view::editor::StatusLineElement::FileType => render_file_type,
142143
helix_view::editor::StatusLineElement::Diagnostics => render_diagnostics,
143144
helix_view::editor::StatusLineElement::Selections => render_selections,
@@ -280,6 +281,31 @@ where
280281
}
281282
}
282283

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+
283309
fn render_file_type<F>(context: &mut RenderContext, write: F)
284310
where
285311
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,

helix-view/src/editor.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ pub enum StatusLineElement {
232232
/// The file encoding
233233
FileEncoding,
234234

235+
/// The file line endings (CRLF or LF)
236+
FileLineEnding,
237+
235238
/// The file type (language ID or "text")
236239
FileType,
237240

0 commit comments

Comments
 (0)