Skip to content

Update crossterm, use more terminal features #13223

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

Closed
wants to merge 4 commits into from
Closed
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
44 changes: 22 additions & 22 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ unicode-segmentation = "1.2"
ropey = { version = "1.6.1", default-features = false, features = ["simd"] }
foldhash = "0.1"
parking_lot = "0.12"
crossterm = { package = "helix-crossterm", version = "0.1.0-beta.1" }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before merging this we should publish 0.1.0


[workspace.package]
version = "25.1.1"
Expand Down
4 changes: 2 additions & 2 deletions helix-term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ once_cell = "1.21"

tokio = { version = "1", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot"] }
tui = { path = "../helix-tui", package = "helix-tui", default-features = false, features = ["crossterm"] }
crossterm = { version = "0.28", features = ["event-stream"] }
crossterm = { workspace = true, features = ["event-stream"] }
signal-hook = "0.3"
tokio-stream = "0.1"
futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false }
Expand Down Expand Up @@ -96,7 +96,7 @@ signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] }
libc = "0.2.171"

[target.'cfg(target_os = "macos")'.dependencies]
crossterm = { version = "0.28", features = ["event-stream", "use-dev-tty", "libc"] }
crossterm = { workspace = true, features = ["event-stream", "use-dev-tty", "libc"] }

[build-dependencies]
helix-loader = { path = "../helix-loader" }
Expand Down
19 changes: 14 additions & 5 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ pub struct Application {
signals: Signals,
jobs: Jobs,
lsp_progress: LspProgressMap,

/// The theme mode (light/dark) detected from the terminal, if available.
theme_mode: Option<theme::Mode>,
}

#[cfg(feature = "integration")]
Expand Down Expand Up @@ -109,6 +112,7 @@ impl Application {
#[cfg(feature = "integration")]
let backend = TestBackend::new(120, 150);

let theme_mode = backend.get_theme_mode();
let terminal = Terminal::new(backend)?;
let area = terminal.size().expect("couldn't get terminal size");
let mut compositor = Compositor::new(area);
Expand All @@ -123,12 +127,15 @@ impl Application {
})),
handlers,
);
Self::load_configured_theme(&mut editor, &config.load());
Self::load_configured_theme(&mut editor, &config.load(), theme_mode);

let keys = Box::new(Map::new(Arc::clone(&config), |config: &Config| {
&config.keys
}));
let editor_view = Box::new(ui::EditorView::new(Keymaps::new(keys)));
let editor_view = Box::new(ui::EditorView::new(
Keymaps::new(keys),
Map::new(Arc::clone(&config), |config: &Config| &config.theme),
));
compositor.push(editor_view);

if args.load_tutor {
Expand Down Expand Up @@ -242,6 +249,7 @@ impl Application {
signals,
jobs: Jobs::new(),
lsp_progress: LspProgressMap::new(),
theme_mode,
};

Ok(app)
Expand Down Expand Up @@ -408,7 +416,7 @@ impl Application {
.map_err(|err| anyhow::anyhow!("Failed to load config: {}", err))?;
self.refresh_language_config()?;
// Refresh theme after config change
Self::load_configured_theme(&mut self.editor, &default_config);
Self::load_configured_theme(&mut self.editor, &default_config, self.theme_mode);
self.terminal
.reconfigure(default_config.editor.clone().into())?;
// Store new config
Expand All @@ -427,12 +435,13 @@ impl Application {
}

/// Load the theme set in configuration
fn load_configured_theme(editor: &mut Editor, config: &Config) {
fn load_configured_theme(editor: &mut Editor, config: &Config, mode: Option<theme::Mode>) {
let true_color = config.editor.true_color || crate::true_color();
let theme = config
.theme
.as_ref()
.and_then(|theme| {
.and_then(|theme_config| {
let theme = theme_config.choose(mode);
editor
.theme_loader
.load(theme)
Expand Down
6 changes: 3 additions & 3 deletions helix-term/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::keymap;
use crate::keymap::{merge_keys, KeyTrie};
use helix_loader::merge_toml_values;
use helix_view::document::Mode;
use helix_view::{document::Mode, theme};
use serde::Deserialize;
use std::collections::HashMap;
use std::fmt::Display;
Expand All @@ -11,15 +11,15 @@ use toml::de::Error as TomlError;

#[derive(Debug, Clone, PartialEq)]
pub struct Config {
pub theme: Option<String>,
pub theme: Option<theme::Config>,
pub keys: HashMap<Mode, KeyTrie>,
pub editor: helix_view::editor::Config,
}

#[derive(Debug, Clone, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ConfigRaw {
pub theme: Option<String>,
pub theme: Option<theme::Config>,
pub keys: Option<HashMap<Mode, KeyTrie>>,
pub editor: Option<toml::Value>,
}
Expand Down
22 changes: 20 additions & 2 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{
},
};

use arc_swap::access::DynAccess;
Copy link
Contributor

@RoloEdits RoloEdits Mar 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think importing this as is can ruin some type inference for some instances of DynGuard (let bindings would then need a fully specified type which, can be long nested types for this kind of use case)? Sort of a precautionary measure, but I would just fully qualify the two instances of the use here.

edit: Yeah, just cherry-picked this and did see this when I am loading from my icons branch.

use helix_core::{
diagnostic::NumberOrString,
graphemes::{next_grapheme_boundary, prev_grapheme_boundary},
Expand All @@ -29,14 +30,15 @@ use helix_view::{
graphics::{Color, CursorKind, Modifier, Rect, Style},
input::{KeyEvent, MouseButton, MouseEvent, MouseEventKind},
keyboard::{KeyCode, KeyModifiers},
Document, Editor, Theme, View,
theme, Document, Editor, Theme, View,
};
use std::{mem::take, num::NonZeroUsize, path::PathBuf, rc::Rc};

use tui::{buffer::Buffer as Surface, text::Span};

pub struct EditorView {
pub keymaps: Keymaps,
theme_config: Box<dyn DynAccess<Option<theme::Config>>>,
on_next_key: Option<(OnKeyCallback, OnKeyCallbackKind)>,
pseudo_pending: Vec<KeyEvent>,
pub(crate) last_insert: (commands::MappableCommand, Vec<InsertEvent>),
Expand All @@ -58,9 +60,13 @@ pub enum InsertEvent {
}

impl EditorView {
pub fn new(keymaps: Keymaps) -> Self {
pub fn new(
keymaps: Keymaps,
theme_config: impl DynAccess<Option<theme::Config>> + 'static,
) -> Self {
Self {
keymaps,
theme_config: Box::new(theme_config),
on_next_key: None,
pseudo_pending: Vec::new(),
last_insert: (commands::MappableCommand::normal_mode, Vec::new()),
Expand Down Expand Up @@ -1535,6 +1541,18 @@ impl Component for EditorView {
self.terminal_focused = false;
EventResult::Consumed(None)
}
Event::ThemeModeChanged(theme_mode) => {
if let Some(theme_config) = self.theme_config.load().as_ref() {
let theme_name = theme_config.choose(Some(*theme_mode));
match context.editor.theme_loader.load(theme_name) {
Ok(theme) => context.editor.set_theme(theme),
Err(err) => {
log::warn!("failed to load theme `{}` - {}", theme_name, err);
}
}
}
EventResult::Consumed(None)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion helix-tui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ helix-core = { path = "../helix-core" }
bitflags.workspace = true
cassowary = "0.3"
unicode-segmentation.workspace = true
crossterm = { version = "0.28", optional = true }
crossterm = { workspace = true, optional = true }
termini = "1.0"
once_cell = "1.21"
log = "~0.4"
Loading
Loading