Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configureable statusline mode names #3311

Merged
merged 25 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
67ea926
Added 'long-mode' statusline element
PeepNSheep Aug 2, 2022
3290ad1
Added customizable statusline mode names
PeepNSheep Aug 3, 2022
1aeec48
Removed a string clone
PeepNSheep Aug 3, 2022
4849657
Added documentation
PeepNSheep Aug 3, 2022
fe46e25
Merge branch 'helix-editor:master' into master
PeepNSheep Aug 3, 2022
2d78425
Merge branch 'helix-editor:master' into master
PeepNSheep Aug 4, 2022
3678b20
Updated documentation, moved modenames to a seperate section
PeepNSheep Aug 4, 2022
34637c4
Update configuration.md
PeepNSheep Aug 4, 2022
1507cc2
Merge branch 'helix-editor:master' into master
PeepNSheep Aug 5, 2022
df1ae8c
Documentation update
PeepNSheep Aug 5, 2022
49d1f80
Merge branch 'helix-editor:master' into master
PeepNSheep Aug 6, 2022
0d0201c
Documentation update
PeepNSheep Aug 6, 2022
5ecdb6d
Merge remote-tracking branch 'refs/remotes/origin/master'
PeepNSheep Aug 6, 2022
6711359
Documentation update
PeepNSheep Aug 6, 2022
9690470
Merge branch 'helix-editor:master' into master
PeepNSheep Aug 7, 2022
40bea4a
Update configuration.md
PeepNSheep Aug 7, 2022
02ad482
Merge branch 'helix-editor:master' into master
PeepNSheep Aug 7, 2022
09aad52
Merge branch 'helix-editor:master' into master
PeepNSheep Aug 11, 2022
9dcd4d9
Update configuration.md
PeepNSheep Aug 13, 2022
db3a6b0
Merge branch 'master' into master
PeepNSheep Sep 1, 2022
2ffe06b
Fixed merge error
PeepNSheep Sep 2, 2022
c4aea8e
Merge branch 'helix-editor:master' into master
PeepNSheep Sep 2, 2022
f3b4a8f
Update configuration.md
PeepNSheep Sep 2, 2022
09ca2ae
Merge branch 'helix-editor:master' into master
PeepNSheep Sep 12, 2022
211833b
Update configuration.md
PeepNSheep Sep 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,27 @@ left = ["mode", "spinner"]
center = ["file-name"]
right = ["diagnostics", "selections", "position", "file-encoding", "file-line-ending", "file-type"]
separator = "│"
mode.normal = "NORMAL"
mode.insert = "INSERT"
mode.select = "SELECT"
```
The `[editor.statusline]` key takes the following sub-keys

The following elements can be configured:
| Key | Description | Default |
| --- | --- | --- |
| `left` | A list of elements aligned to the left of the statusline | `["mode", "spinner", "file-name"]` |
| `center` | A list of elements aligned to the middle of the statusline | `[]` |
| `right` | A list of elements aligned to the right of the statusline | `["diagnostics", "selections", "position", "file-encoding"]` |
| `separator` | The character used to separate elements in the statusline | `"|"` |
| `mode.normal` | The text shown in the `mode` element for normal mode | `"NOR"` |
| `mode.insert` | The text shown in the `mode` element for insert mode | `"INS"` |
| `mode.select` | The text shown in the `mode` element for select mode | `"SEL"` |

The following statusline elements can be configured as follows:

| Key | Description |
| ------ | ----------- |
| `mode` | The current editor mode (`NOR`/`INS`/`SEL`) |
| `mode` | The current editor mode (`mode.normal`/`mode.insert`/`mode.select`) |
| `spinner` | A progress spinner indicating LSP activity |
| `file-name` | The path/name of the opened file |
| `file-encoding` | The encoding of the opened file if it differs from UTF-8 |
Expand All @@ -83,7 +97,6 @@ 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 `"│"`) |
the-mikedavis marked this conversation as resolved.
Show resolved Hide resolved
| `spacer` | Inserts a space between elements (multiple/contiguous spacers may be specified) |

### `[editor.lsp]` Section
Expand Down
8 changes: 4 additions & 4 deletions helix-term/src/ui/statusline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,16 @@ where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
{
let visible = context.focused;

let modenames = &context.editor.config().statusline.mode;
write(
context,
format!(
" {} ",
if visible {
match context.doc.mode() {
Mode::Insert => "INS",
Mode::Select => "SEL",
Mode::Normal => "NOR",
Mode::Insert => &modenames.insert,
Mode::Select => &modenames.select,
Mode::Normal => &modenames.normal,
}
} else {
// If not focused, explicitly leave an empty space instead of returning None.
Expand Down
20 changes: 20 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ pub struct StatusLineConfig {
pub center: Vec<StatusLineElement>,
pub right: Vec<StatusLineElement>,
pub separator: String,
pub mode: ModeConfig,
}

impl Default for StatusLineConfig {
Expand All @@ -215,6 +216,25 @@ impl Default for StatusLineConfig {
center: vec![],
right: vec![E::Diagnostics, E::Selections, E::Position, E::FileEncoding],
separator: String::from("│"),
mode: ModeConfig::default(),
}
}
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct ModeConfig {
pub normal: String,
pub insert: String,
pub select: String,
}

impl Default for ModeConfig {
fn default() -> Self {
Self {
normal: String::from("NOR"),
insert: String::from("INS"),
select: String::from("SEL"),
}
}
}
Expand Down