Skip to content

Commit 846a6b6

Browse files
authored
add configurable / theme-able statusline separator string (#3175)
* add configurable separator element to statusline * themable separator * clippy fixes * changed default separator to │ * doc updates
1 parent 61856f1 commit 846a6b6

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

book/src/configuration.md

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Statusline elements can be defined as follows:
6363
left = ["mode", "spinner"]
6464
center = ["file-name"]
6565
right = ["diagnostics", "selections", "position", "file-encoding", "file-line-ending", "file-type"]
66+
separator = ""
6667
```
6768

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

8486
### `[editor.lsp]` Section

book/src/themes.md

+1
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ These scopes are used for theming the editor interface.
224224
| `ui.statusline.normal` | Statusline mode during normal mode ([only if `editor.color-modes` is enabled][editor-section]) |
225225
| `ui.statusline.insert` | Statusline mode during insert mode ([only if `editor.color-modes` is enabled][editor-section]) |
226226
| `ui.statusline.select` | Statusline mode during select mode ([only if `editor.color-modes` is enabled][editor-section]) |
227+
| `ui.statusline.separator` | Separator character in statusline |
227228
| `ui.popup` | Documentation popups (e.g space-k) |
228229
| `ui.popup.info` | Prompt for multiple key options |
229230
| `ui.window` | Border lines separating splits |

helix-term/src/ui/statusline.rs

+14
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ where
144144
helix_view::editor::StatusLineElement::Selections => render_selections,
145145
helix_view::editor::StatusLineElement::Position => render_position,
146146
helix_view::editor::StatusLineElement::PositionPercentage => render_position_percentage,
147+
helix_view::editor::StatusLineElement::Separator => render_separator,
147148
helix_view::editor::StatusLineElement::Spacer => render_spacer,
148149
}
149150
}
@@ -353,6 +354,19 @@ where
353354
write(context, title, None);
354355
}
355356

357+
fn render_separator<F>(context: &mut RenderContext, write: F)
358+
where
359+
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
360+
{
361+
let sep = &context.editor.config().statusline.separator;
362+
363+
write(
364+
context,
365+
sep.to_string(),
366+
Some(context.editor.theme.get("ui.statusline.separator")),
367+
);
368+
}
369+
356370
fn render_spacer<F>(context: &mut RenderContext, write: F)
357371
where
358372
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,

helix-view/src/editor.rs

+6
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ pub struct StatusLineConfig {
203203
pub left: Vec<StatusLineElement>,
204204
pub center: Vec<StatusLineElement>,
205205
pub right: Vec<StatusLineElement>,
206+
pub separator: String,
206207
}
207208

208209
impl Default for StatusLineConfig {
@@ -213,6 +214,7 @@ impl Default for StatusLineConfig {
213214
left: vec![E::Mode, E::Spinner, E::FileName],
214215
center: vec![],
215216
right: vec![E::Diagnostics, E::Selections, E::Position, E::FileEncoding],
217+
separator: String::from("│"),
216218
}
217219
}
218220
}
@@ -247,8 +249,12 @@ pub enum StatusLineElement {
247249
/// The cursor position
248250
Position,
249251

252+
/// The separator string
253+
Separator,
254+
250255
/// The cursor position as a percent of the total file
251256
PositionPercentage,
257+
252258
/// A single space
253259
Spacer,
254260
}

0 commit comments

Comments
 (0)