on master help sign in
Render indent-style status in status line.

Also cleaned up the status line code a little.

commit8648e483f772b4791e5618c4c8b3db8926ae356d authorNathan Vegdahl <cessen@cessen.com> dateSun 13 Jun 2021, 16:35 (5 years ago) parent5ca043c
2 files changed+43−17
helix-term/src/ui/editor.rs+40−16 helix-view/src/document.rs+3−1
helix-term/src/ui/editor.rs+40−16
@@ -11,7 +11,10 @@ use helix_core::{
1111 syntax::{self, HighlightEvent},
1212 Position, Range,
1313};
14−use helix_view::{document::Mode, Document, Editor, Theme, View};
14+use helix_view::{
15+ document::{IndentStyle, Mode},
16+ Document, Editor, Theme, View,
17+};
1518use std::borrow::Cow;
1619
1720use crossterm::{
@@ -455,6 +458,10 @@ impl EditorView {
455458 theme: &Theme,
456459 is_focused: bool,
457460 ) {
461+ //-------------------------------
462+ // Left side of the status line.
463+ //-------------------------------
464+
458465 let mode = match doc.mode() {
459466 Mode::Insert => "INS",
460467 Mode::Select => "SEL",
@@ -487,24 +494,41 @@ impl EditorView {
487494 );
488495 }
489496
490− surface.set_stringn(
491− viewport.x + viewport.width.saturating_sub(15),
492− viewport.y,
493− format!("{}", doc.diagnostics().len()),
494− 4,
495− text_color,
496− );
497−
498− // render line:col
499− 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
502− let len = text.len();
497+ //-------------------------------
498+ // Right side of the status line.
499+ //-------------------------------
500+
501+ // Compute the individual info strings.
502+ let diag_count = format!("{}", doc.diagnostics().len());
503+ let indent_info = match doc.indent_style {
504+ IndentStyle::Tabs => "tab",
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 = {
516+ let pos = coords_at_pos(doc.text().slice(..), doc.selection(view.id).cursor());
517+ format!("{}:{}", pos.row + 1, pos.col + 1) // convert to 1-indexing
518+ };
503519
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;
504528 surface.set_string(
505− viewport.x + viewport.width.saturating_sub(len as u16 + 1),
529+ viewport.x + viewport.width.saturating_sub(text_len),
506530 viewport.y,
507− text,
531+ right_side_text,
508532 text_color,
509533 );
510534 }
helix-view/src/document.rs+3−1
@@ -32,7 +32,6 @@ pub struct Document {
3232 pub(crate) id: DocumentId,
3333 text: Rope,
3434 pub(crate) selections: HashMap<ViewId, Selection>,
35− pub(crate) indent_style: IndentStyle,
3635
3736 path: Option<PathBuf>,
3837
@@ -40,6 +39,9 @@ pub struct Document {
4039 pub mode: Mode,
4140 pub restore_cursor: bool,
4241
42+ /// Current indent style.
43+ pub indent_style: IndentStyle,
44+
4345 syntax: Option<Syntax>,
4446 // /// Corresponding language scope name. Usually `source.<lang>`.
4547 pub(crate) language: Option<Arc<LanguageConfiguration>>,