on master help sign in
Add configureable statusline mode names (#3311)

* Added 'long-mode' statusline element * Added customizable statusline mode names * Removed a string clone * Added documentation * Updated documentation, moved modenames to a seperate section * Update configuration.md * Documentation update * Documentation update * Documentation update * Update configuration.md * Update configuration.md * Fixed merge error * Update configuration.md * Update configuration.md

commit77f33e7b20bb84c6506d745ce05ec6835eee6756 authorPeepNSheep <peepnsheep@gmail.com> dateMon 3 Oct 2022, 10:45 (4 years ago) parent589d17c
3 files changed+40−6
book/src/configuration.md+16−2 helix-term/src/ui/statusline.rs+4−4 helix-view/src/editor.rs+20
book/src/configuration.md+16−2
@@ -68,13 +68,27 @@ left = ["mode", "spinner"]
6868center = ["file-name"]
6969right = ["diagnostics", "selections", "position", "file-encoding", "file-line-ending", "file-type"]
7070separator = "│"
71+mode.normal = "NORMAL"
72+mode.insert = "INSERT"
73+mode.select = "SELECT"
7174```
75+The `[editor.statusline]` key takes the following sub-keys:
7276
73−The following elements can be configured:
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+
87+The following statusline elements can be configured:
7488
7589| Key | Description |
7690| ------ | ----------- |
77−| `mode` | The current editor mode (`NOR`/`INS`/`SEL`) |
91+| `mode` | The current editor mode (`mode.normal`/`mode.insert`/`mode.select`) |
7892| `spinner` | A progress spinner indicating LSP activity |
7993| `file-name` | The path/name of the opened file |
8094| `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
154154 F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
155155{
156156 let visible = context.focused;
157−
157+ let modenames = &context.editor.config().statusline.mode;
158158 write(
159159 context,
160160 format!(
161161 " {} ",
162162 if visible {
163163 match context.editor.mode() {
164− Mode::Insert => "INS",
165− Mode::Select => "SEL",
166− Mode::Normal => "NOR",
164+ Mode::Insert => &modenames.insert,
165+ Mode::Select => &modenames.select,
166+ Mode::Normal => &modenames.normal,
167167 }
168168 } else {
169169 // 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 {
260260 pub center: Vec<StatusLineElement>,
261261 pub right: Vec<StatusLineElement>,
262262 pub separator: String,
263+ pub mode: ModeConfig,
263264}
264265
265266impl Default for StatusLineConfig {
@@ -271,6 +272,25 @@ impl Default for StatusLineConfig {
271272 center: vec![],
272273 right: vec![E::Diagnostics, E::Selections, E::Position, E::FileEncoding],
273274 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"),
274294 }
275295 }
276296}