Skip to content

Commit d6fab59

Browse files
committed
feat: add support for basic icons
lint: add 'static lifetime to const's feat: add dap symbols to config refactor: remove `Default` impls and add config parsing chore: add comment for default diagnostic symbols perf: add `#[inline]` attribute to getters refactor: add nerdfont defaults for common mime types perf: switch from `String` to `SmartString` refactor: rename config.rs to icons.rs and move to top level refactor: rename mime get param from type to name refactor: small renames for better clarity doc: add description for `Icons` in `Editor` refactor: tweak with bufferline icon spacing refactor: change lsp icons to `nf-cod-symbol` where possible feat: add more icons for supported languages todo: outline more icon domains and sets
1 parent 3a63e85 commit d6fab59

File tree

8 files changed

+542
-23
lines changed

8 files changed

+542
-23
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

helix-term/src/ui/editor.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use helix_core::{
2424
};
2525
use helix_view::{
2626
annotations::diagnostics::DiagnosticFilter,
27-
document::{Mode, SCRATCH_BUFFER_NAME},
27+
document::{Mode, DEFAULT_LANGUAGE_NAME, SCRATCH_BUFFER_NAME},
2828
editor::{CompleteAction, CursorShapeConfig},
2929
graphics::{Color, CursorKind, Modifier, Rect, Style},
3030
input::{KeyEvent, MouseButton, MouseEvent, MouseEventKind},
@@ -647,7 +647,20 @@ impl EditorView {
647647
bufferline_inactive
648648
};
649649

650-
let text = format!(" {}{} ", fname, if doc.is_modified() { "[+]" } else { "" });
650+
let lang = doc.language_name().unwrap_or(DEFAULT_LANGUAGE_NAME);
651+
let config = editor.config();
652+
let icon = config.icons.mime.get(lang);
653+
654+
let text = if lang == icon {
655+
format!(" {} {}", fname, if doc.is_modified() { "[+] " } else { "" })
656+
} else {
657+
format!(
658+
" {icon} {} {}",
659+
fname,
660+
if doc.is_modified() { "[+] " } else { "" }
661+
)
662+
};
663+
651664
let used_width = viewport.x.saturating_sub(x);
652665
let rem_width = surface.area.width.saturating_sub(used_width);
653666

helix-term/src/ui/statusline.rs

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,13 @@ where
243243
if warnings > 0 {
244244
write(
245245
context,
246-
"●".to_string(),
246+
context
247+
.editor
248+
.config()
249+
.icons
250+
.diagnostic
251+
.warning()
252+
.to_string(),
247253
Some(context.editor.theme.get("warning")),
248254
);
249255
write(context, format!(" {} ", warnings), None);
@@ -252,7 +258,7 @@ where
252258
if errors > 0 {
253259
write(
254260
context,
255-
"●".to_string(),
261+
context.editor.config().icons.diagnostic.error().to_string(),
256262
Some(context.editor.theme.get("error")),
257263
);
258264
write(context, format!(" {} ", errors), None);
@@ -285,7 +291,13 @@ where
285291
if warnings > 0 {
286292
write(
287293
context,
288-
"●".to_string(),
294+
context
295+
.editor
296+
.config()
297+
.icons
298+
.diagnostic
299+
.warning()
300+
.to_string(),
289301
Some(context.editor.theme.get("warning")),
290302
);
291303
write(context, format!(" {} ", warnings), None);
@@ -294,7 +306,7 @@ where
294306
if errors > 0 {
295307
write(
296308
context,
297-
"●".to_string(),
309+
context.editor.config().icons.diagnostic.error().to_string(),
298310
Some(context.editor.theme.get("error")),
299311
);
300312
write(context, format!(" {} ", errors), None);
@@ -410,9 +422,13 @@ fn render_file_type<F>(context: &mut RenderContext, write: F)
410422
where
411423
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
412424
{
413-
let file_type = context.doc.language_name().unwrap_or(DEFAULT_LANGUAGE_NAME);
425+
let icons = &context.editor.config().icons;
414426

415-
write(context, format!(" {} ", file_type), None);
427+
let icon = icons
428+
.mime
429+
.get(context.doc.language_name().unwrap_or(DEFAULT_LANGUAGE_NAME));
430+
431+
write(context, format!(" {} ", icon), None);
416432
}
417433

418434
fn render_file_name<F>(context: &mut RenderContext, write: F)
@@ -514,13 +530,18 @@ fn render_version_control<F>(context: &mut RenderContext, write: F)
514530
where
515531
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
516532
{
517-
let head = context
518-
.doc
519-
.version_control_head()
520-
.unwrap_or_default()
521-
.to_string();
533+
let head = context.doc.version_control_head().unwrap_or_default();
534+
535+
let icons = &context.editor.config().icons;
536+
let icon = icons.vcs.icon();
537+
538+
let vcs = if head.is_empty() {
539+
format!("{head}")
540+
} else {
541+
format!("{icon} {head}")
542+
};
522543

523-
write(context, head, None);
544+
write(context, vcs, None);
524545
}
525546

526547
fn render_register<F>(context: &mut RenderContext, write: F)

helix-view/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ log = "~0.4"
5252
parking_lot.workspace = true
5353
thiserror.workspace = true
5454

55+
smartstring = { version = "1.0.1", features = ["serde"]}
56+
5557
[target.'cfg(windows)'.dependencies]
5658
clipboard-win = { version = "5.4", features = ["std"] }
5759

helix-view/src/editor.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::{
77
events::DocumentFocusLost,
88
graphics::{CursorKind, Rect},
99
handlers::Handlers,
10+
icons,
1011
info::Info,
1112
input::KeyEvent,
1213
register::Registers,
@@ -17,6 +18,7 @@ use crate::{
1718
use dap::StackFrame;
1819
use helix_event::dispatch;
1920
use helix_vcs::DiffProviderRegistry;
21+
use icons::Icons;
2022

2123
use futures_util::stream::select_all::SelectAll;
2224
use futures_util::{future, StreamExt};
@@ -369,6 +371,8 @@ pub struct Config {
369371
/// Whether to read settings from [EditorConfig](https://editorconfig.org) files. Defaults to
370372
/// `true`.
371373
pub editor_config: bool,
374+
/// Centralized location for icons that can be used throughout the UI
375+
pub icons: Icons,
372376
}
373377

374378
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq, PartialOrd, Ord)]
@@ -1013,6 +1017,7 @@ impl Default for Config {
10131017
end_of_line_diagnostics: DiagnosticFilter::Disable,
10141018
clipboard_provider: ClipboardProvider::default(),
10151019
editor_config: true,
1020+
icons: Icons::default(),
10161021
}
10171022
}
10181023
}

helix-view/src/gutter.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl GutterType {
4646
}
4747

4848
pub fn diagnostic<'doc>(
49-
_editor: &'doc Editor,
49+
editor: &'doc Editor,
5050
doc: &'doc Document,
5151
_view: &View,
5252
theme: &Theme,
@@ -57,6 +57,7 @@ pub fn diagnostic<'doc>(
5757
let info = theme.get("info");
5858
let hint = theme.get("hint");
5959
let diagnostics = &doc.diagnostics;
60+
let symbols = editor.config().icons.diagnostic.clone();
6061

6162
Box::new(
6263
move |line: usize, _selected: bool, first_visual_line: bool, out: &mut String| {
@@ -74,13 +75,14 @@ pub fn diagnostic<'doc>(
7475
.any(|ls| ls.id() == d.provider)
7576
});
7677
diagnostics_on_line.max_by_key(|d| d.severity).map(|d| {
77-
write!(out, "●").ok();
78-
match d.severity {
79-
Some(Severity::Error) => error,
80-
Some(Severity::Warning) | None => warning,
81-
Some(Severity::Info) => info,
82-
Some(Severity::Hint) => hint,
83-
}
78+
let (style, symbol) = match d.severity {
79+
Some(Severity::Error) => (error, symbols.error()),
80+
Some(Severity::Warning) | None => (warning, symbols.warning()),
81+
Some(Severity::Info) => (info, symbols.info()),
82+
Some(Severity::Hint) => (hint, symbols.hint()),
83+
};
84+
out.push_str(symbol);
85+
style
8486
})
8587
},
8688
)
@@ -263,7 +265,13 @@ pub fn breakpoints<'doc>(
263265
breakpoint_style
264266
};
265267

266-
let sym = if breakpoint.verified { "●" } else { "◯" };
268+
let config = editor.config();
269+
270+
let sym = if breakpoint.verified {
271+
config.icons.dap.verified()
272+
} else {
273+
config.icons.dap.unverified()
274+
};
267275
write!(out, "{}", sym).unwrap();
268276
Some(style)
269277
},

0 commit comments

Comments
 (0)