on master help sign in
Render indent-style status in status line.
8648e48Nathan Vegdahl
helix-term/src/ui/editor.rs+40−16
@@ -11,7 +11,10 @@ use helix_core::{
11 syntax::{self, HighlightEvent},
11 syntax::{self, HighlightEvent},
12 Position, Range,
12 Position, Range,
13};
13};
14+use helix_view::{
15+ document::{IndentStyle, Mode},
14−use helix_view::{document::Mode, Document, Editor, Theme, View};
16+ Document, Editor, Theme, View,
17+};
15use std::borrow::Cow;
18use std::borrow::Cow;
16
19
17use crossterm::{
20use crossterm::{
@@ -455,6 +458,10 @@ impl EditorView {
455 theme: &Theme,
458 theme: &Theme,
456 is_focused: bool,
459 is_focused: bool,
457 ) {
460 ) {
461+ //-------------------------------
462+ // Left side of the status line.
463+ //-------------------------------
464+
458 let mode = match doc.mode() {
465 let mode = match doc.mode() {
459 Mode::Insert => "INS",
466 Mode::Insert => "INS",
460 Mode::Select => "SEL",
467 Mode::Select => "SEL",
@@ -487,24 +494,41 @@ impl EditorView {
487 );
494 );
488 }
495 }
489
496
490− surface.set_stringn(
497+ //-------------------------------
491− viewport.x + viewport.width.saturating_sub(15),
498+ // Right side of the status line.
492− viewport.y,
499+ //-------------------------------
493− format!("{}", doc.diagnostics().len()),
500+
494− 4,
501+ // Compute the individual info strings.
495− text_color,
502+ let diag_count = format!("{}", doc.diagnostics().len());
496− );
503+ let indent_info = match doc.indent_style {
497−
504+ IndentStyle::Tabs => "tab",
498− // render line:col
505+ IndentStyle::Spaces(1) => "spaces:1",
506+ IndentStyle::Spaces(2) => "spaces:2",
507+ IndentStyle::Spaces(3) => "spaces:3",
508+ IndentStyle::Spaces(4) => "spaces:4",
509+ IndentStyle::Spaces(5) => "spaces:5",
510+ IndentStyle::Spaces(6) => "spaces:6",
511+ IndentStyle::Spaces(7) => "spaces:7",
512+ IndentStyle::Spaces(8) => "spaces:8",
513+ _ => "indent:ERROR",
514+ };
515+ let position_info = {
499− let pos = coords_at_pos(doc.text().slice(..), doc.selection(view.id).cursor());
516+ let pos = coords_at_pos(doc.text().slice(..), doc.selection(view.id).cursor());
500−
501− let text = format!("{}:{}", pos.row + 1, pos.col + 1); // convert to 1-indexing
517+ format!("{}:{}", pos.row + 1, pos.col + 1) // convert to 1-indexing
502− let len = text.len();
518+ };
503
519
520+ // Render them to the status line together.
521+ let right_side_text = format!(
522+ "{} {} {} ",
523+ &diag_count[..diag_count.len().min(4)],
524+ indent_info,
525+ position_info
526+ );
527+ let text_len = right_side_text.len() as u16;
504 surface.set_string(
528 surface.set_string(
505− viewport.x + viewport.width.saturating_sub(len as u16 + 1),
529+ viewport.x + viewport.width.saturating_sub(text_len),
506 viewport.y,
530 viewport.y,
507− text,
531+ right_side_text,
508 text_color,
532 text_color,
509 );
533 );
510 }
534 }
helix-view/src/document.rs+3−1
@@ -32,7 +32,6 @@ pub struct Document {
32 pub(crate) id: DocumentId,
32 pub(crate) id: DocumentId,
33 text: Rope,
33 text: Rope,
34 pub(crate) selections: HashMap<ViewId, Selection>,
34 pub(crate) selections: HashMap<ViewId, Selection>,
35− pub(crate) indent_style: IndentStyle,
36
35
37 path: Option<PathBuf>,
36 path: Option<PathBuf>,
38
37
@@ -40,6 +39,9 @@ pub struct Document {
40 pub mode: Mode,
39 pub mode: Mode,
41 pub restore_cursor: bool,
40 pub restore_cursor: bool,
42
41
42+ /// Current indent style.
43+ pub indent_style: IndentStyle,
44+
43 syntax: Option<Syntax>,
45 syntax: Option<Syntax>,
44 // /// Corresponding language scope name. Usually `source.<lang>`.
46 // /// Corresponding language scope name. Usually `source.<lang>`.
45 pub(crate) language: Option<Arc<LanguageConfiguration>>,
47 pub(crate) language: Option<Arc<LanguageConfiguration>>,