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

feat: add basic support for icons #12369

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use helix_core::{
};
use helix_view::{
annotations::diagnostics::DiagnosticFilter,
document::{Mode, SavePoint, SCRATCH_BUFFER_NAME},
document::{Mode, SavePoint, DEFAULT_LANGUAGE_NAME, SCRATCH_BUFFER_NAME},
editor::{CompleteAction, CursorShapeConfig},
graphics::{Color, CursorKind, Modifier, Rect, Style},
input::{KeyEvent, MouseButton, MouseEvent, MouseEventKind},
Expand Down Expand Up @@ -646,7 +646,20 @@ impl EditorView {
bufferline_inactive
};

let text = format!(" {}{} ", fname, if doc.is_modified() { "[+]" } else { "" });
let lang = doc.language_name().unwrap_or(DEFAULT_LANGUAGE_NAME);
let config = editor.config();
let icon = config.icons.mime.get(lang);

let text = if lang == icon {
format!(" {} {}", fname, if doc.is_modified() { "[+] " } else { "" })
} else {
format!(
" {icon} {} {}",
fname,
if doc.is_modified() { "[+] " } else { "" }
)
};

let used_width = viewport.x.saturating_sub(x);
let rem_width = surface.area.width.saturating_sub(used_width);

Expand Down
45 changes: 33 additions & 12 deletions helix-term/src/ui/statusline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,13 @@ where
if warnings > 0 {
write(
context,
"●".to_string(),
context
.editor
.config()
.icons
.diagnostic
.warning()
.to_string(),
Some(context.editor.theme.get("warning")),
);
write(context, format!(" {} ", warnings), None);
Expand All @@ -252,7 +258,7 @@ where
if errors > 0 {
write(
context,
"●".to_string(),
context.editor.config().icons.diagnostic.error().to_string(),
Some(context.editor.theme.get("error")),
);
write(context, format!(" {} ", errors), None);
Expand Down Expand Up @@ -285,7 +291,13 @@ where
if warnings > 0 {
write(
context,
"●".to_string(),
context
.editor
.config()
.icons
.diagnostic
.warning()
.to_string(),
Some(context.editor.theme.get("warning")),
);
write(context, format!(" {} ", warnings), None);
Expand All @@ -294,7 +306,7 @@ where
if errors > 0 {
write(
context,
"●".to_string(),
context.editor.config().icons.diagnostic.error().to_string(),
Some(context.editor.theme.get("error")),
);
write(context, format!(" {} ", errors), None);
Expand Down Expand Up @@ -410,9 +422,13 @@ fn render_file_type<F>(context: &mut RenderContext, write: F)
where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
{
let file_type = context.doc.language_name().unwrap_or(DEFAULT_LANGUAGE_NAME);
let icons = &context.editor.config().icons;

write(context, format!(" {} ", file_type), None);
let icon = icons
.mime
.get(context.doc.language_name().unwrap_or(DEFAULT_LANGUAGE_NAME));

write(context, format!(" {} ", icon), None);
}

fn render_file_name<F>(context: &mut RenderContext, write: F)
Expand Down Expand Up @@ -514,13 +530,18 @@ fn render_version_control<F>(context: &mut RenderContext, write: F)
where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
{
let head = context
.doc
.version_control_head()
.unwrap_or_default()
.to_string();
let head = context.doc.version_control_head().unwrap_or_default();

let icons = &context.editor.config().icons;
let icon = icons.vcs.icon();

let vcs = if head.is_empty() {
format!("{head}")
} else {
format!("{icon} {head}")
};

write(context, head, None);
write(context, vcs, None);
}

fn render_register<F>(context: &mut RenderContext, write: F)
Expand Down
2 changes: 2 additions & 0 deletions helix-view/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ log = "~0.4"
parking_lot = "0.12.3"
thiserror.workspace = true

smartstring = { version = "1.0.1", features = ["serde"]}

[target.'cfg(windows)'.dependencies]
clipboard-win = { version = "5.4", features = ["std"] }

Expand Down
5 changes: 5 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
events::DocumentFocusLost,
graphics::{CursorKind, Rect},
handlers::Handlers,
icons,
info::Info,
input::KeyEvent,
register::Registers,
Expand All @@ -17,6 +18,7 @@ use crate::{
use dap::StackFrame;
use helix_event::dispatch;
use helix_vcs::DiffProviderRegistry;
use icons::Icons;

use futures_util::stream::select_all::SelectAll;
use futures_util::{future, StreamExt};
Expand Down Expand Up @@ -360,6 +362,8 @@ pub struct Config {
pub end_of_line_diagnostics: DiagnosticFilter,
// Set to override the default clipboard provider
pub clipboard_provider: ClipboardProvider,
/// Centralized location for icons that can be used throughout the UI
pub icons: Icons,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq, PartialOrd, Ord)]
Expand Down Expand Up @@ -1001,6 +1005,7 @@ impl Default for Config {
inline_diagnostics: InlineDiagnosticsConfig::default(),
end_of_line_diagnostics: DiagnosticFilter::Disable,
clipboard_provider: ClipboardProvider::default(),
icons: Icons::default(),
}
}
}
Expand Down
26 changes: 17 additions & 9 deletions helix-view/src/gutter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl GutterType {
}

pub fn diagnostic<'doc>(
_editor: &'doc Editor,
editor: &'doc Editor,
doc: &'doc Document,
_view: &View,
theme: &Theme,
Expand All @@ -57,6 +57,7 @@ pub fn diagnostic<'doc>(
let info = theme.get("info");
let hint = theme.get("hint");
let diagnostics = &doc.diagnostics;
let symbols = editor.config().icons.diagnostic.clone();

Box::new(
move |line: usize, _selected: bool, first_visual_line: bool, out: &mut String| {
Expand All @@ -74,13 +75,14 @@ pub fn diagnostic<'doc>(
.any(|ls| ls.id() == d.provider)
});
diagnostics_on_line.max_by_key(|d| d.severity).map(|d| {
write!(out, "●").ok();
match d.severity {
Some(Severity::Error) => error,
Some(Severity::Warning) | None => warning,
Some(Severity::Info) => info,
Some(Severity::Hint) => hint,
}
let (style, symbol) = match d.severity {
Some(Severity::Error) => (error, symbols.error()),
Some(Severity::Warning) | None => (warning, symbols.warning()),
Some(Severity::Info) => (info, symbols.info()),
Some(Severity::Hint) => (hint, symbols.hint()),
};
out.push_str(symbol);
style
})
},
)
Expand Down Expand Up @@ -272,7 +274,13 @@ pub fn breakpoints<'doc>(
breakpoint_style
};

let sym = if breakpoint.verified { "●" } else { "◯" };
let config = editor.config();

let sym = if breakpoint.verified {
config.icons.dap.verified()
} else {
config.icons.dap.unverified()
};
write!(out, "{}", sym).unwrap();
Some(style)
},
Expand Down
Loading
Loading