on master help sign in
Add configureable statusline mode names (#3311)
77f33e7PeepNSheep
book/src/configuration.md+16−2
@@ -68,13 +68,27 @@ left = ["mode", "spinner"]
68center = ["file-name"]
68center = ["file-name"]
69right = ["diagnostics", "selections", "position", "file-encoding", "file-line-ending", "file-type"]
69right = ["diagnostics", "selections", "position", "file-encoding", "file-line-ending", "file-type"]
70separator = "│"
70separator = "│"
71+mode.normal = "NORMAL"
72+mode.insert = "INSERT"
73+mode.select = "SELECT"
71```
74```
75+The `[editor.statusline]` key takes the following sub-keys:
72
76
77+| Key | Description | Default |
78+| --- | --- | --- |
79+| `left` | A list of elements aligned to the left of the statusline | `["mode", "spinner", "file-name"]` |
80+| `center` | A list of elements aligned to the middle of the statusline | `[]` |
81+| `right` | A list of elements aligned to the right of the statusline | `["diagnostics", "selections", "position", "file-encoding"]` |
82+| `separator` | The character used to separate elements in the statusline | `"│"` |
83+| `mode.normal` | The text shown in the `mode` element for normal mode | `"NOR"` |
84+| `mode.insert` | The text shown in the `mode` element for insert mode | `"INS"` |
85+| `mode.select` | The text shown in the `mode` element for select mode | `"SEL"` |
86+
73−The following elements can be configured:
87+The following statusline elements can be configured:
74
88
75| Key | Description |
89| Key | Description |
76| ------ | ----------- |
90| ------ | ----------- |
77−| `mode` | The current editor mode (`NOR`/`INS`/`SEL`) |
91+| `mode` | The current editor mode (`mode.normal`/`mode.insert`/`mode.select`) |
78| `spinner` | A progress spinner indicating LSP activity |
92| `spinner` | A progress spinner indicating LSP activity |
79| `file-name` | The path/name of the opened file |
93| `file-name` | The path/name of the opened file |
80| `file-encoding` | The encoding of the opened file if it differs from UTF-8 |
94| `file-encoding` | The encoding of the opened file if it differs from UTF-8 |
helix-term/src/ui/statusline.rs+4−4
@@ -154,16 +154,16 @@ where
154 F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
154 F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
155{
155{
156 let visible = context.focused;
156 let visible = context.focused;
157−
157+ let modenames = &context.editor.config().statusline.mode;
158 write(
158 write(
159 context,
159 context,
160 format!(
160 format!(
161 " {} ",
161 " {} ",
162 if visible {
162 if visible {
163 match context.editor.mode() {
163 match context.editor.mode() {
164− Mode::Insert => "INS",
164+ Mode::Insert => &modenames.insert,
165− Mode::Select => "SEL",
165+ Mode::Select => &modenames.select,
166− Mode::Normal => "NOR",
166+ Mode::Normal => &modenames.normal,
167 }
167 }
168 } else {
168 } else {
169 // If not focused, explicitly leave an empty space instead of returning None.
169 // If not focused, explicitly leave an empty space instead of returning None.
helix-view/src/editor.rs+20
@@ -260,6 +260,7 @@ pub struct StatusLineConfig {
260 pub center: Vec<StatusLineElement>,
260 pub center: Vec<StatusLineElement>,
261 pub right: Vec<StatusLineElement>,
261 pub right: Vec<StatusLineElement>,
262 pub separator: String,
262 pub separator: String,
263+ pub mode: ModeConfig,
263}
264}
264
265
265impl Default for StatusLineConfig {
266impl Default for StatusLineConfig {
@@ -271,6 +272,25 @@ impl Default for StatusLineConfig {
271 center: vec![],
272 center: vec![],
272 right: vec![E::Diagnostics, E::Selections, E::Position, E::FileEncoding],
273 right: vec![E::Diagnostics, E::Selections, E::Position, E::FileEncoding],
273 separator: String::from("│"),
274 separator: String::from("│"),
275+ mode: ModeConfig::default(),
276+ }
277+ }
278+}
279+
280+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
281+#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
282+pub struct ModeConfig {
283+ pub normal: String,
284+ pub insert: String,
285+ pub select: String,
286+}
287+
288+impl Default for ModeConfig {
289+ fn default() -> Self {
290+ Self {
291+ normal: String::from("NOR"),
292+ insert: String::from("INS"),
293+ select: String::from("SEL"),
274 }
294 }
275 }
295 }
276}
296}