mirror of https://github.com/helix-editor/helix
Merge 738bdb429d
into fed3edcab7
commit
04555726e9
|
@ -286,7 +286,7 @@ These scopes are used for theming the editor interface:
|
||||||
| `ui.gutter.selected` | Gutter for the line the cursor is on |
|
| `ui.gutter.selected` | Gutter for the line the cursor is on |
|
||||||
| `ui.linenr` | Line numbers |
|
| `ui.linenr` | Line numbers |
|
||||||
| `ui.linenr.selected` | Line number for the line the cursor is on |
|
| `ui.linenr.selected` | Line number for the line the cursor is on |
|
||||||
| `ui.statusline` | Statusline |
|
| `ui.statusline` | Statusline (support element style e.g. `ui.statusline.file-name`) |
|
||||||
| `ui.statusline.inactive` | Statusline (unfocused document) |
|
| `ui.statusline.inactive` | Statusline (unfocused document) |
|
||||||
| `ui.statusline.normal` | Statusline mode during normal mode ([only if `editor.color-modes` is enabled][editor-section]) |
|
| `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.insert` | Statusline mode during insert mode ([only if `editor.color-modes` is enabled][editor-section]) |
|
||||||
|
|
|
@ -68,6 +68,7 @@ pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface
|
||||||
for element_id in &config.statusline.left {
|
for element_id in &config.statusline.left {
|
||||||
let render = get_render_function(*element_id);
|
let render = get_render_function(*element_id);
|
||||||
(render)(context, |context, span| {
|
(render)(context, |context, span| {
|
||||||
|
let base_style = statusline_style(context, &element_id.to_string());
|
||||||
append(&mut context.parts.left, span, base_style)
|
append(&mut context.parts.left, span, base_style)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -84,6 +85,7 @@ pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface
|
||||||
for element_id in &config.statusline.right {
|
for element_id in &config.statusline.right {
|
||||||
let render = get_render_function(*element_id);
|
let render = get_render_function(*element_id);
|
||||||
(render)(context, |context, span| {
|
(render)(context, |context, span| {
|
||||||
|
let base_style = statusline_style(context, &element_id.to_string());
|
||||||
append(&mut context.parts.right, span, base_style)
|
append(&mut context.parts.right, span, base_style)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -103,6 +105,7 @@ pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface
|
||||||
for element_id in &config.statusline.center {
|
for element_id in &config.statusline.center {
|
||||||
let render = get_render_function(*element_id);
|
let render = get_render_function(*element_id);
|
||||||
(render)(context, |context, span| {
|
(render)(context, |context, span| {
|
||||||
|
let base_style = statusline_style(context, &element_id.to_string());
|
||||||
append(&mut context.parts.center, span, base_style)
|
append(&mut context.parts.center, span, base_style)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -161,6 +164,22 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn statusline_style(context: &RenderContext, scope: &str) -> Style {
|
||||||
|
let scope = if context.focused {
|
||||||
|
format!("ui.statusline.{scope}")
|
||||||
|
} else {
|
||||||
|
format!("ui.statusline.inactive.{scope}")
|
||||||
|
};
|
||||||
|
|
||||||
|
let config = context.editor.config();
|
||||||
|
|
||||||
|
if config.color_modes {
|
||||||
|
context.editor.theme.get(&scope)
|
||||||
|
} else {
|
||||||
|
Style::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn render_mode<'a, F>(context: &mut RenderContext<'a>, write: F)
|
fn render_mode<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
|
@ -396,7 +415,7 @@ where
|
||||||
let maxrows = context.doc.text().len_lines();
|
let maxrows = context.doc.text().len_lines();
|
||||||
write(
|
write(
|
||||||
context,
|
context,
|
||||||
format!("{}%", (position.row + 1) * 100 / maxrows).into(),
|
format!(" {}% ", (position.row + 1) * 100 / maxrows).into(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -481,11 +500,7 @@ fn render_file_modification_indicator<'a, F>(context: &mut RenderContext<'a>, wr
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
let title = if context.doc.is_modified() {
|
let title = if context.doc.is_modified() { "[+]" } else { "" };
|
||||||
"[+]"
|
|
||||||
} else {
|
|
||||||
" "
|
|
||||||
};
|
|
||||||
|
|
||||||
write(context, title.into());
|
write(context, title.into());
|
||||||
}
|
}
|
||||||
|
@ -522,10 +537,9 @@ fn render_separator<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
let sep = &context.editor.config().statusline.separator;
|
let sep = context.editor.config().statusline.separator.clone();
|
||||||
let style = context.editor.theme.get("ui.statusline.separator");
|
|
||||||
|
|
||||||
write(context, Span::styled(sep.to_string(), style));
|
write(context, sep.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_spacer<'a, F>(context: &mut RenderContext<'a>, write: F)
|
fn render_spacer<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
|
@ -561,11 +575,10 @@ fn render_file_indent_style<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
let style = context.doc.indent_style;
|
let indent_style = context.doc.indent_style;
|
||||||
|
|
||||||
write(
|
write(
|
||||||
context,
|
context,
|
||||||
match style {
|
match indent_style {
|
||||||
IndentStyle::Tabs => " tabs ".into(),
|
IndentStyle::Tabs => " tabs ".into(),
|
||||||
IndentStyle::Spaces(indent) => {
|
IndentStyle::Spaces(indent) => {
|
||||||
format!(" {} space{} ", indent, if indent == 1 { "" } else { "s" }).into()
|
format!(" {} space{} ", indent, if indent == 1 { "" } else { "s" }).into()
|
||||||
|
|
|
@ -27,6 +27,7 @@ use std::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
cell::Cell,
|
cell::Cell,
|
||||||
collections::{BTreeMap, HashMap, HashSet},
|
collections::{BTreeMap, HashMap, HashSet},
|
||||||
|
fmt::Display,
|
||||||
fs,
|
fs,
|
||||||
io::{self, stdin},
|
io::{self, stdin},
|
||||||
num::{NonZeroU8, NonZeroUsize},
|
num::{NonZeroU8, NonZeroUsize},
|
||||||
|
@ -624,6 +625,37 @@ pub enum StatusLineElement {
|
||||||
Register,
|
Register,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for StatusLineElement {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
use StatusLineElement::*;
|
||||||
|
let element = match self {
|
||||||
|
Mode => "mode",
|
||||||
|
Spinner => "spinner",
|
||||||
|
FileBaseName => "file-base-name",
|
||||||
|
FileName => "file-name",
|
||||||
|
FileAbsolutePath => "file-absolute-path",
|
||||||
|
FileModificationIndicator => "file-modification-indicator",
|
||||||
|
ReadOnlyIndicator => "read-only-indicator",
|
||||||
|
FileEncoding => "file-encoding",
|
||||||
|
FileLineEnding => "file-line-ending",
|
||||||
|
FileIndentStyle => "file-indent-style",
|
||||||
|
FileType => "file-type",
|
||||||
|
Diagnostics => "diagnostics",
|
||||||
|
WorkspaceDiagnostics => "workspace-diagnostics",
|
||||||
|
Selections => "selections",
|
||||||
|
PrimarySelectionLength => "primary-selection-length",
|
||||||
|
Position => "position",
|
||||||
|
Separator => "separator",
|
||||||
|
PositionPercentage => "position-percentage",
|
||||||
|
TotalLineNumbers => "total-line-numbers",
|
||||||
|
Spacer => "spacer",
|
||||||
|
VersionControl => "version-control",
|
||||||
|
Register => "register",
|
||||||
|
};
|
||||||
|
write!(f, "{element}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Cursor shape is read and used on every rendered frame and so needs
|
// Cursor shape is read and used on every rendered frame and so needs
|
||||||
// to be fast. Therefore we avoid a hashmap and use an enum indexed array.
|
// to be fast. Therefore we avoid a hashmap and use an enum indexed array.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
|
Loading…
Reference in New Issue