Skip to content

Commit 154f905

Browse files
axdankthomasskk
authored andcommitted
add statusline element to display file line endings (helix-editor#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 935369a commit 154f905

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

book/src/configuration.md

+2-1
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

+2-3
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

+26
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

+3
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ pub enum StatusLineElement {
297297
/// The file encoding
298298
FileEncoding,
299299

300+
/// The file line endings (CRLF or LF)
301+
FileLineEnding,
302+
300303
/// The file type (language ID or "text")
301304
FileType,
302305

0 commit comments

Comments
 (0)