Skip to content

Commit

Permalink
add configurable / theme-able statusline separator string (helix-edit…
Browse files Browse the repository at this point in the history
…or#3175)

* add configurable separator element to statusline

* themable separator

* clippy fixes

* changed default separator to │

* doc updates
  • Loading branch information
sbromberger authored and thomasskk committed Sep 9, 2022
1 parent ee81ce9 commit a380cc1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Statusline elements can be defined as follows:
left = ["mode", "spinner"]
center = ["file-name"]
right = ["diagnostics", "selections", "position", "file-encoding", "file-line-ending", "file-type"]
separator = ""
```

The following elements can be configured:
Expand All @@ -79,6 +80,7 @@ The following elements can be configured:
| `selections` | The number of active selections |
| `position` | The cursor position |
| `position-percentage` | The cursor position as a percentage of the total number of lines |
| `separator` | The string defined in `editor.statusline.separator` (defaults to `"│"`) |
| `spacer` | Inserts a space between elements (multiple/contiguous spacers may be specified) |

### `[editor.lsp]` Section
Expand Down
1 change: 1 addition & 0 deletions book/src/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ These scopes are used for theming the editor interface.
| `ui.statusline.normal` | Statusline mode during normal mode ([only if `editor.color-modes` is enabled][editor-section]) |
| `ui.statusline.insert` | Statusline mode during insert mode ([only if `editor.color-modes` is enabled][editor-section]) |
| `ui.statusline.select` | Statusline mode during select mode ([only if `editor.color-modes` is enabled][editor-section]) |
| `ui.statusline.separator` | Separator character in statusline |
| `ui.popup` | Documentation popups (e.g space-k) |
| `ui.popup.info` | Prompt for multiple key options |
| `ui.window` | Border lines separating splits |
Expand Down
14 changes: 14 additions & 0 deletions helix-term/src/ui/statusline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ where
helix_view::editor::StatusLineElement::Selections => render_selections,
helix_view::editor::StatusLineElement::Position => render_position,
helix_view::editor::StatusLineElement::PositionPercentage => render_position_percentage,
helix_view::editor::StatusLineElement::Separator => render_separator,
helix_view::editor::StatusLineElement::Spacer => render_spacer,
}
}
Expand Down Expand Up @@ -353,6 +354,19 @@ where
write(context, title, None);
}

fn render_separator<F>(context: &mut RenderContext, write: F)
where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
{
let sep = &context.editor.config().statusline.separator;

write(
context,
sep.to_string(),
Some(context.editor.theme.get("ui.statusline.separator")),
);
}

fn render_spacer<F>(context: &mut RenderContext, write: F)
where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
Expand Down
6 changes: 6 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ pub struct StatusLineConfig {
pub left: Vec<StatusLineElement>,
pub center: Vec<StatusLineElement>,
pub right: Vec<StatusLineElement>,
pub separator: String,
}

impl Default for StatusLineConfig {
Expand All @@ -278,6 +279,7 @@ impl Default for StatusLineConfig {
left: vec![E::Mode, E::Spinner, E::FileName],
center: vec![],
right: vec![E::Diagnostics, E::Selections, E::Position, E::FileEncoding],
separator: String::from("│"),
}
}
}
Expand Down Expand Up @@ -312,8 +314,12 @@ pub enum StatusLineElement {
/// The cursor position
Position,

/// The separator string
Separator,

/// The cursor position as a percent of the total file
PositionPercentage,

/// A single space
Spacer,
}
Expand Down

0 comments on commit a380cc1

Please sign in to comment.