Skip to content

Commit d28f15b

Browse files
committed
Maintain full functionality of the color_modes option
1 parent 916bba8 commit d28f15b

File tree

21 files changed

+318
-167
lines changed

21 files changed

+318
-167
lines changed

helix-term/src/commands.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2480,12 +2480,18 @@ fn global_search(cx: &mut Context) {
24802480
let config = GlobalSearchConfig {
24812481
smart_case: config.search.smart_case,
24822482
file_picker_config: config.file_picker.clone(),
2483-
directory_style: cx.editor.theme.get(cx.editor.mode, "ui.text.directory"),
2483+
directory_style: cx
2484+
.editor
2485+
.theme
2486+
.get(cx.editor.theme_context(), "ui.text.directory"),
24842487
number_style: cx
24852488
.editor
24862489
.theme
2487-
.get(cx.editor.mode, "constant.numeric.integer"),
2488-
colon_style: cx.editor.theme.get(cx.editor.mode, "punctuation"),
2490+
.get(cx.editor.theme_context(), "constant.numeric.integer"),
2491+
colon_style: cx
2492+
.editor
2493+
.theme
2494+
.get(cx.editor.theme_context(), "punctuation"),
24892495
};
24902496

24912497
let columns = [
@@ -3351,11 +3357,17 @@ fn changed_file_picker(cx: &mut Context) {
33513357
return;
33523358
}
33533359

3354-
let added = cx.editor.theme.get(cx.editor.mode, "diff.plus");
3355-
let modified = cx.editor.theme.get(cx.editor.mode, "diff.delta");
3356-
let conflict = cx.editor.theme.get(cx.editor.mode, "diff.delta.conflict");
3357-
let deleted = cx.editor.theme.get(cx.editor.mode, "diff.minus");
3358-
let renamed = cx.editor.theme.get(cx.editor.mode, "diff.delta.moved");
3360+
let added = cx.editor.theme.get(cx.editor.theme_context(), "diff.plus");
3361+
let modified = cx.editor.theme.get(cx.editor.theme_context(), "diff.delta");
3362+
let conflict = cx
3363+
.editor
3364+
.theme
3365+
.get(cx.editor.theme_context(), "diff.delta.conflict");
3366+
let deleted = cx.editor.theme.get(cx.editor.theme_context(), "diff.minus");
3367+
let renamed = cx
3368+
.editor
3369+
.theme
3370+
.get(cx.editor.theme_context(), "diff.delta.moved");
33593371

33603372
let columns = [
33613373
PickerColumn::new("change", |change: &FileChange, data: &FileChangeData| {

helix-term/src/commands/dap.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,10 @@ pub fn dap_next(cx: &mut Context) {
502502
}
503503

504504
pub fn dap_variables(cx: &mut Context) {
505+
// debugger takes cx.editor as a &mut borrow so this needs to be first
506+
// to satisfy the borrow checker.
507+
let theme_context = cx.editor.theme_context();
508+
505509
let debugger = debugger!(cx.editor);
506510

507511
if debugger.thread_id.is_none() {
@@ -549,9 +553,9 @@ pub fn dap_variables(cx: &mut Context) {
549553
let mut variables = Vec::new();
550554

551555
let theme = &cx.editor.theme;
552-
let scope_style = theme.get(cx.editor.mode, "ui.linenr.selected");
553-
let type_style = theme.get(cx.editor.mode, "ui.text");
554-
let text_style = theme.get(cx.editor.mode, "ui.text.focus");
556+
let scope_style = theme.get(theme_context, "ui.linenr.selected");
557+
let type_style = theme.get(theme_context, "ui.text");
558+
let text_style = theme.get(theme_context, "ui.text.focus");
555559

556560
for scope in scopes.iter() {
557561
// use helix_view::graphics::Style;

helix-term/src/commands/lsp.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,10 @@ fn diag_picker(
239239
});
240240

241241
let styles = DiagnosticStyles {
242-
hint: cx.editor.theme.get(cx.editor.mode, "hint"),
243-
info: cx.editor.theme.get(cx.editor.mode, "info"),
244-
warning: cx.editor.theme.get(cx.editor.mode, "warning"),
245-
error: cx.editor.theme.get(cx.editor.mode, "error"),
242+
hint: cx.editor.theme.get(cx.editor.theme_context(), "hint"),
243+
info: cx.editor.theme.get(cx.editor.theme_context(), "info"),
244+
warning: cx.editor.theme.get(cx.editor.theme_context(), "warning"),
245+
error: cx.editor.theme.get(cx.editor.theme_context(), "error"),
246246
};
247247

248248
let mut columns = vec![

helix-term/src/ui/completion.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ impl Completion {
133133
let preview_completion_insert = editor.config().preview_completion_insert;
134134
let replace_mode = editor.config().completion_replace;
135135

136-
let dir_style = editor.theme.get(editor.mode, "ui.text.directory");
136+
let dir_style = editor
137+
.theme
138+
.get(editor.theme_context(), "ui.text.directory");
137139

138140
// Then create the menu
139141
let menu = Menu::new(items, dir_style, move |editor: &mut Editor, item, event| {
@@ -568,7 +570,7 @@ impl Component for Completion {
568570
};
569571

570572
// clear area
571-
let background = cx.editor.theme.get(cx.editor.mode, "ui.popup");
573+
let background = cx.editor.theme.get(cx.editor.theme_context(), "ui.popup");
572574
surface.clear_with(doc_area, background);
573575

574576
if cx.editor.popup_border() {

helix-term/src/ui/document.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl<'a> TextRenderer<'a> {
245245
" ".to_owned()
246246
};
247247

248-
let text_style = theme.get(editor.mode, "ui.text");
248+
let text_style = theme.get(editor.theme_context(), "ui.text");
249249

250250
let indent_width = doc.indent_style.indent_width(tab_width) as u16;
251251

@@ -258,15 +258,15 @@ impl<'a> TextRenderer<'a> {
258258
space,
259259
tab,
260260
virtual_tab,
261-
whitespace_style: theme.get(editor.mode, "ui.virtual.whitespace"),
261+
whitespace_style: theme.get(editor.theme_context(), "ui.virtual.whitespace"),
262262
indent_width,
263263
starting_indent: offset.col / indent_width as usize
264264
+ (offset.col % indent_width as usize != 0) as usize
265265
+ editor_config.indent_guides.skip_levels as usize,
266266
indent_guide_style: text_style.patch(
267267
theme
268-
.try_get(editor.mode, "ui.virtual.indent-guide")
269-
.unwrap_or_else(|| theme.get(editor.mode, "ui.virtual.whitespace")),
268+
.try_get(editor.theme_context(), "ui.virtual.indent-guide")
269+
.unwrap_or_else(|| theme.get(editor.theme_context(), "ui.virtual.whitespace")),
270270
),
271271
text_style,
272272
draw_indent_guides: editor_config.indent_guides.render,

helix-term/src/ui/editor.rs

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl EditorView {
113113
// Set DAP highlights, if needed.
114114
if let Some(frame) = editor.current_stack_frame() {
115115
let dap_line = frame.line.saturating_sub(1);
116-
let style = theme.get(editor.mode, "ui.highlight.frameline");
116+
let style = theme.get(editor.theme_context(), "ui.highlight.frameline");
117117
let line_decoration = move |renderer: &mut TextRenderer, pos: LinePos| {
118118
if pos.doc_line != dap_line {
119119
return;
@@ -200,7 +200,7 @@ impl EditorView {
200200
decorations.add_decoration(InlineDiagnostics::new(
201201
doc,
202202
theme,
203-
editor.mode,
203+
editor.theme_context(),
204204
primary_cursor,
205205
inline_diagnostic_config,
206206
config.end_of_line_diagnostics,
@@ -221,7 +221,7 @@ impl EditorView {
221221
// if we're not at the edge of the screen, draw a right border
222222
if viewport.right() != view.area.right() {
223223
let x = area.right();
224-
let border_style = theme.get(editor.mode, "ui.window");
224+
let border_style = theme.get(editor.theme_context(), "ui.window");
225225
for y in area.top()..area.bottom() {
226226
surface[(x, y)]
227227
.set_symbol(tui::symbols::line::VERTICAL)
@@ -257,7 +257,7 @@ impl EditorView {
257257
) {
258258
let editor_rulers = &editor.config().rulers;
259259
let ruler_theme = theme
260-
.try_get(editor.mode, "ui.virtual.ruler")
260+
.try_get(editor.theme_context(), "ui.virtual.ruler")
261261
.unwrap_or_else(|| Style::default().bg(Color::Red));
262262

263263
let rulers = doc
@@ -608,19 +608,27 @@ impl EditorView {
608608
viewport,
609609
editor
610610
.theme
611-
.try_get(editor.mode, "ui.bufferline.background")
612-
.unwrap_or_else(|| editor.theme.get(editor.mode, "ui.statusline")),
611+
.try_get(editor.theme_context(), "ui.bufferline.background")
612+
.unwrap_or_else(|| editor.theme.get(editor.theme_context(), "ui.statusline")),
613613
);
614614

615615
let bufferline_active = editor
616616
.theme
617-
.try_get(editor.mode, "ui.bufferline.active")
618-
.unwrap_or_else(|| editor.theme.get(editor.mode, "ui.statusline.active"));
617+
.try_get(editor.theme_context(), "ui.bufferline.active")
618+
.unwrap_or_else(|| {
619+
editor
620+
.theme
621+
.get(editor.theme_context(), "ui.statusline.active")
622+
});
619623

620624
let bufferline_inactive = editor
621625
.theme
622-
.try_get(editor.mode, "ui.bufferline")
623-
.unwrap_or_else(|| editor.theme.get(editor.mode, "ui.statusline.inactive"));
626+
.try_get(editor.theme_context(), "ui.bufferline")
627+
.unwrap_or_else(|| {
628+
editor
629+
.theme
630+
.get(editor.theme_context(), "ui.statusline.inactive")
631+
});
624632

625633
let mut x = viewport.x;
626634
let current_doc = view!(editor).doc;
@@ -672,10 +680,11 @@ impl EditorView {
672680

673681
let mut offset = 0;
674682

675-
let gutter_style = theme.get(editor.mode, "ui.gutter");
676-
let gutter_selected_style = theme.get(editor.mode, "ui.gutter.selected");
677-
let gutter_style_virtual = theme.get(editor.mode, "ui.gutter.virtual");
678-
let gutter_selected_style_virtual = theme.get(editor.mode, "ui.gutter.selected.virtual");
683+
let gutter_style = theme.get(editor.theme_context(), "ui.gutter");
684+
let gutter_selected_style = theme.get(editor.theme_context(), "ui.gutter.selected");
685+
let gutter_style_virtual = theme.get(editor.theme_context(), "ui.gutter.virtual");
686+
let gutter_selected_style_virtual =
687+
theme.get(editor.theme_context(), "ui.gutter.selected.virtual");
679688

680689
for gutter_type in view.gutters() {
681690
let mut gutter = gutter_type.style(editor, doc, view, theme, is_focused);
@@ -743,13 +752,13 @@ impl EditorView {
743752
diagnostic.range.start <= cursor && diagnostic.range.end >= cursor
744753
});
745754

746-
let warning = theme.get(editor.mode, "warning");
747-
let error = theme.get(editor.mode, "error");
748-
let info = theme.get(editor.mode, "info");
749-
let hint = theme.get(editor.mode, "hint");
755+
let warning = theme.get(editor.theme_context(), "warning");
756+
let error = theme.get(editor.theme_context(), "error");
757+
let info = theme.get(editor.theme_context(), "info");
758+
let hint = theme.get(editor.theme_context(), "hint");
750759

751760
let mut lines = Vec::new();
752-
let background_style = theme.get(editor.mode, "ui.background");
761+
let background_style = theme.get(editor.theme_context(), "ui.background");
753762
for diagnostic in diagnostics {
754763
let style = Style::reset()
755764
.patch(background_style)
@@ -806,8 +815,8 @@ impl EditorView {
806815
.map(|range| range.cursor_line(text))
807816
.collect();
808817

809-
let primary_style = theme.get(editor.mode, "ui.cursorline.primary");
810-
let secondary_style = theme.get(editor.mode, "ui.cursorline.secondary");
818+
let primary_style = theme.get(editor.theme_context(), "ui.cursorline.primary");
819+
let secondary_style = theme.get(editor.theme_context(), "ui.cursorline.secondary");
811820
let viewport = view.area;
812821

813822
move |renderer: &mut TextRenderer, pos: LinePos| {
@@ -835,13 +844,13 @@ impl EditorView {
835844
// Manual fallback behaviour:
836845
// ui.cursorcolumn.{p/s} -> ui.cursorcolumn -> ui.cursorline.{p/s}
837846
let primary_style = theme
838-
.try_get_exact(editor.mode, "ui.cursorcolumn.primary")
839-
.or_else(|| theme.try_get_exact(editor.mode, "ui.cursorcolumn"))
840-
.unwrap_or_else(|| theme.get(editor.mode, "ui.cursorline.primary"));
847+
.try_get_exact(editor.theme_context(), "ui.cursorcolumn.primary")
848+
.or_else(|| theme.try_get_exact(editor.theme_context(), "ui.cursorcolumn"))
849+
.unwrap_or_else(|| theme.get(editor.theme_context(), "ui.cursorline.primary"));
841850
let secondary_style = theme
842-
.try_get_exact(editor.mode, "ui.cursorcolumn.secondary")
843-
.or_else(|| theme.try_get_exact(editor.mode, "ui.cursorcolumn"))
844-
.unwrap_or_else(|| theme.get(editor.mode, "ui.cursorline.secondary"));
851+
.try_get_exact(editor.theme_context(), "ui.cursorcolumn.secondary")
852+
.or_else(|| theme.try_get_exact(editor.theme_context(), "ui.cursorcolumn"))
853+
.unwrap_or_else(|| theme.get(editor.theme_context(), "ui.cursorline.secondary"));
845854

846855
let inner_area = view.inner_area(doc);
847856

@@ -1541,7 +1550,12 @@ impl Component for EditorView {
15411550

15421551
fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
15431552
// clear with background color
1544-
surface.set_style(area, cx.editor.theme.get(cx.editor.mode, "ui.background"));
1553+
surface.set_style(
1554+
area,
1555+
cx.editor
1556+
.theme
1557+
.get(cx.editor.theme_context(), "ui.background"),
1558+
);
15451559
let config = cx.editor.config();
15461560

15471561
// check if bufferline should be rendered
@@ -1585,9 +1599,9 @@ impl Component for EditorView {
15851599
status_msg_width = status_msg.width();
15861600
use helix_view::editor::Severity;
15871601
let style = if *severity == Severity::Error {
1588-
cx.editor.theme.get(cx.editor.mode, "error")
1602+
cx.editor.theme.get(cx.editor.theme_context(), "error")
15891603
} else {
1590-
cx.editor.theme.get(cx.editor.mode, "ui.text")
1604+
cx.editor.theme.get(cx.editor.theme_context(), "ui.text")
15911605
};
15921606

15931607
surface.set_string(
@@ -1609,7 +1623,7 @@ impl Component for EditorView {
16091623
for key in &self.pseudo_pending {
16101624
disp.push_str(&key.key_sequence_format());
16111625
}
1612-
let style = cx.editor.theme.get(cx.editor.mode, "ui.text");
1626+
let style = cx.editor.theme.get(cx.editor.theme_context(), "ui.text");
16131627
let macro_width = if cx.editor.macro_recording.is_some() {
16141628
3
16151629
} else {

helix-term/src/ui/info.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ use tui::widgets::{Block, Paragraph, Widget};
77

88
impl Component for Info {
99
fn render(&mut self, viewport: Rect, surface: &mut Surface, cx: &mut Context) {
10-
let text_style = cx.editor.theme.get(cx.editor.mode, "ui.text.info");
11-
let popup_style = cx.editor.theme.get(cx.editor.mode, "ui.popup.info");
10+
let text_style = cx
11+
.editor
12+
.theme
13+
.get(cx.editor.theme_context(), "ui.text.info");
14+
let popup_style = cx
15+
.editor
16+
.theme
17+
.get(cx.editor.theme_context(), "ui.popup.info");
1218

1319
// Calculate the area of the terminal to modify. Because we want to
1420
// render at the bottom right, we use the viewport's width and height

helix-term/src/ui/lsp/hover.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl Component for Hover {
8080
// show header and border only when more than one results
8181
if let Some(header) = header {
8282
// header LSP Name
83-
let header = header.parse(Some((&cx.editor.theme, cx.editor.mode)));
83+
let header = header.parse(Some((&cx.editor.theme, cx.editor.theme_context())));
8484
let header = Paragraph::new(&header);
8585
header.render(area.with_height(HEADER_HEIGHT), surface);
8686

@@ -95,7 +95,7 @@ impl Component for Hover {
9595
}
9696

9797
// hover content
98-
let contents = contents.parse(Some((&cx.editor.theme, cx.editor.mode)));
98+
let contents = contents.parse(Some((&cx.editor.theme, cx.editor.theme_context())));
9999
let contents_area = area.clip_top(if self.has_header() {
100100
HEADER_HEIGHT + SEPARATOR_HEIGHT
101101
} else {

helix-term/src/ui/lsp/signature_help.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl Component for SignatureHelp {
119119
let sig_text = crate::ui::markdown::highlighted_code_block(
120120
signature.signature.as_str(),
121121
&self.language,
122-
Some((&cx.editor.theme, cx.editor.mode)),
122+
Some((&cx.editor.theme, cx.editor.theme_context())),
123123
&self.config_loader.load(),
124124
active_param_span,
125125
);
@@ -155,7 +155,7 @@ impl Component for SignatureHelp {
155155
None => return,
156156
Some(doc) => Markdown::new(doc.clone(), Arc::clone(&self.config_loader)),
157157
};
158-
let sig_doc = sig_doc.parse(Some((&cx.editor.theme, cx.editor.mode)));
158+
let sig_doc = sig_doc.parse(Some((&cx.editor.theme, cx.editor.theme_context())));
159159
let sig_doc_area = area
160160
.clip_top(sig_text_area.height + 2)
161161
.clip_bottom(u16::from(cx.editor.popup_border()));

0 commit comments

Comments
 (0)