Compare commits
15
Commits
9debf46833
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b9fc8517d | ||
|
|
8d49a993e9 | ||
|
|
c21472b2f2 | ||
|
|
ca30e9a0ee | ||
|
|
c5e4e5fb85 | ||
|
|
d74b0acc83 | ||
|
|
567ffd76b2 | ||
|
|
2a4945b363 | ||
|
|
dd1622350d | ||
|
|
50e1319b92 | ||
|
|
fa8057989e | ||
|
|
51a497cb04 | ||
|
|
349f38b31c | ||
|
|
d8bfbf0294 | ||
|
|
3b04fe4f8b |
@@ -1,2 +1,3 @@
|
|||||||
/target/
|
/target/
|
||||||
/.tools/
|
/.tools/
|
||||||
|
/.worktrees
|
||||||
|
|||||||
Generated
+59
@@ -404,6 +404,15 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "core_maths"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "77745e017f5edba1a9c1d854f6f3a52dac8a12dd5af5d2f54aecf61e43d80d30"
|
||||||
|
dependencies = [
|
||||||
|
"libm",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crc32fast"
|
name = "crc32fast"
|
||||||
version = "1.5.1"
|
version = "1.5.1"
|
||||||
@@ -719,6 +728,29 @@ version = "0.2.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
|
checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fontconfig-parser"
|
||||||
|
version = "0.5.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bbc773e24e02d4ddd8395fd30dc147524273a83e54e0f312d986ea30de5f5646"
|
||||||
|
dependencies = [
|
||||||
|
"roxmltree",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fontdb"
|
||||||
|
version = "0.23.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "457e789b3d1202543297a350643cf459f836cade38934e7a4cf6a39e7cde2905"
|
||||||
|
dependencies = [
|
||||||
|
"fontconfig-parser",
|
||||||
|
"log",
|
||||||
|
"memmap2",
|
||||||
|
"slotmap",
|
||||||
|
"tinyvec",
|
||||||
|
"ttf-parser",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "foreign-types"
|
name = "foreign-types"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
@@ -2087,6 +2119,12 @@ version = "1.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832"
|
checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "roxmltree"
|
||||||
|
version = "0.20.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6c20b6793b5c2fa6553b250154b78d6d0db37e72700ae35fad9387a46f487c97"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc-hash"
|
name = "rustc-hash"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
@@ -2271,14 +2309,17 @@ checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
|
|||||||
name = "slerm"
|
name = "slerm"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"ab_glyph",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"base64",
|
"base64",
|
||||||
"eframe",
|
"eframe",
|
||||||
"egui",
|
"egui",
|
||||||
|
"fontdb",
|
||||||
"libghostty-vt",
|
"libghostty-vt",
|
||||||
"png",
|
"png",
|
||||||
"portable-pty",
|
"portable-pty",
|
||||||
"serde",
|
"serde",
|
||||||
|
"shell-words",
|
||||||
"toml",
|
"toml",
|
||||||
"wgpu",
|
"wgpu",
|
||||||
]
|
]
|
||||||
@@ -2488,6 +2529,21 @@ dependencies = [
|
|||||||
"zerovec",
|
"zerovec",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tinyvec"
|
||||||
|
version = "1.13.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4cf0ded5c4e56918d8f8a339e1bb67d038d3bc6d144ac407904015ba2e4cde9b"
|
||||||
|
dependencies = [
|
||||||
|
"tinyvec_macros",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tinyvec_macros"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml"
|
name = "toml"
|
||||||
version = "0.9.12+spec-1.1.0"
|
version = "0.9.12+spec-1.1.0"
|
||||||
@@ -2570,6 +2626,9 @@ name = "ttf-parser"
|
|||||||
version = "0.25.1"
|
version = "0.25.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d2df906b07856748fa3f6e0ad0cbaa047052d4a7dd609e231c4f72cee8c36f31"
|
checksum = "d2df906b07856748fa3f6e0ad0cbaa047052d4a7dd609e231c4f72cee8c36f31"
|
||||||
|
dependencies = [
|
||||||
|
"core_maths",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "type-map"
|
name = "type-map"
|
||||||
|
|||||||
@@ -8,12 +8,15 @@ license = "MIT"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
|
ab_glyph = "0.2"
|
||||||
|
fontdb = "0.23"
|
||||||
eframe = { version = "0.33", default-features = false, features = ["default_fonts", "wgpu", "wayland", "x11"] }
|
eframe = { version = "0.33", default-features = false, features = ["default_fonts", "wgpu", "wayland", "x11"] }
|
||||||
egui = "0.33"
|
egui = "0.33"
|
||||||
libghostty-vt = { version = "=0.2.1", features = ["png"] }
|
libghostty-vt = { version = "=0.2.1", features = ["png"] }
|
||||||
png = "0.18"
|
png = "0.18"
|
||||||
portable-pty = "0.9"
|
portable-pty = "0.9"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
shell-words = "1"
|
||||||
toml = "0.9"
|
toml = "0.9"
|
||||||
wgpu = { version = "27", default-features = false, features = ["std", "vulkan", "gles", "metal", "wgsl"] }
|
wgpu = { version = "27", default-features = false, features = ["std", "vulkan", "gles", "metal", "wgsl"] }
|
||||||
|
|
||||||
|
|||||||
+41
-4
@@ -2,14 +2,48 @@
|
|||||||
# Omit shell to use $SHELL. Arguments are separate array entries.
|
# Omit shell to use $SHELL. Arguments are separate array entries.
|
||||||
# shell = ["/bin/bash", "--login"]
|
# shell = ["/bin/bash", "--login"]
|
||||||
# working_directory = "/home/you"
|
# working_directory = "/home/you"
|
||||||
font_path = "/usr/local/share/fonts/MononokiNerdFontMono-Regular.ttf"
|
# Select an installed family; regular, bold, italic and bold italic are matched
|
||||||
|
# automatically. Install a patched Nerd Font to get its icons.
|
||||||
|
# font_family = "GeistMono Nerd Font Mono"
|
||||||
|
# Alternatively load a file; matching style faces are discovered beside it.
|
||||||
|
# font_path = "/usr/local/share/fonts/MononokiNerdFontMono-Regular.ttf"
|
||||||
|
# Optional overrides for individual faces:
|
||||||
|
# font_bold_path = "/path/to/Bold.ttf"
|
||||||
|
# font_italic_path = "/path/to/Italic.ttf"
|
||||||
|
# font_bold_italic_path = "/path/to/BoldItalic.ttf"
|
||||||
|
# Ordered installed fallback families, used for missing glyphs in every style.
|
||||||
|
# font_fallbacks = ["Symbols Nerd Font Mono"]
|
||||||
|
# Symbols Nerd Font Mono (or Symbols Nerd Font) is also used automatically when
|
||||||
|
# installed. Missing styles use the closest available face in the family;
|
||||||
|
# regular-only fonts retain synthetic bold/italic emphasis.
|
||||||
font_size = 16
|
font_size = 16
|
||||||
scrollback = 10000
|
scrollback = 10000
|
||||||
|
# Command for opening scrollback; omit to use $EDITOR, or vi if unset.
|
||||||
|
# Supports quoted arguments; the scrollback file path is appended automatically.
|
||||||
|
# Runs directly without shell expansion. The editor should stay in the foreground.
|
||||||
|
# scrollback_editor = "nvim -R"
|
||||||
window_width = 1100
|
window_width = 1100
|
||||||
window_height = 720
|
window_height = 720
|
||||||
background = "#17191c"
|
|
||||||
foreground = "#e2e4e8"
|
# Any theme from `slerm --list-themes`: "slerm" plus every theme Helix ships.
|
||||||
accent = "#58c4ad"
|
theme = "slerm"
|
||||||
|
|
||||||
|
# Shorthand for the [colors] entries of the same name.
|
||||||
|
# background = "#17191c"
|
||||||
|
# foreground = "#e2e4e8"
|
||||||
|
# accent = "#58c4ad"
|
||||||
|
|
||||||
|
# Colors overriding the theme, all optional. Alongside the three above:
|
||||||
|
# cursor, selection_background, selection_foreground, border,
|
||||||
|
# chrome_background, chrome_foreground, chrome_active_background,
|
||||||
|
# popup_background,
|
||||||
|
# and the sixteen ANSI colors:
|
||||||
|
# black, red, green, yellow, blue, magenta, cyan, white,
|
||||||
|
# and each of those again as bright_black ... bright_white.
|
||||||
|
# [colors]
|
||||||
|
# cursor = "#58c4ad"
|
||||||
|
# red = "#cc6666"
|
||||||
|
# bright_red = "#d54e53"
|
||||||
|
|
||||||
[kitty]
|
[kitty]
|
||||||
image_storage_mb = 64
|
image_storage_mb = 64
|
||||||
@@ -30,6 +64,7 @@ floating_max_height = 640
|
|||||||
"Alt+F" = "toggle_floats"
|
"Alt+F" = "toggle_floats"
|
||||||
"Alt+M" = "new_pane"
|
"Alt+M" = "new_pane"
|
||||||
"Alt+H" = "focus_left"
|
"Alt+H" = "focus_left"
|
||||||
|
# With floating panes shown, J/K cycle forward/backward through them.
|
||||||
"Alt+J" = "focus_down"
|
"Alt+J" = "focus_down"
|
||||||
"Alt+K" = "focus_up"
|
"Alt+K" = "focus_up"
|
||||||
"Alt+L" = "focus_right"
|
"Alt+L" = "focus_right"
|
||||||
@@ -37,6 +72,8 @@ floating_max_height = 640
|
|||||||
"Alt+Shift+H" = "previous_tab"
|
"Alt+Shift+H" = "previous_tab"
|
||||||
"Alt+Shift+L" = "next_tab"
|
"Alt+Shift+L" = "next_tab"
|
||||||
"Alt+X" = "close_pane"
|
"Alt+X" = "close_pane"
|
||||||
|
# Open scrollback in scrollback_editor (or $EDITOR/vi), returning on exit.
|
||||||
|
"Alt+S" = "open_scrollback"
|
||||||
"Ctrl+Shift+Z" = "zoom_pane"
|
"Ctrl+Shift+Z" = "zoom_pane"
|
||||||
"Ctrl+Shift+R" = "reload_config"
|
"Ctrl+Shift+R" = "reload_config"
|
||||||
"Ctrl+Shift+C" = "copy"
|
"Ctrl+Shift+C" = "copy"
|
||||||
|
|||||||
@@ -0,0 +1,699 @@
|
|||||||
|
//! Converts the themes Helix ships in `runtime/themes` into `src/themes.rs`.
|
||||||
|
//!
|
||||||
|
//! Helix themes describe an editor: they name syntax scopes, not the sixteen
|
||||||
|
//! ANSI colors a terminal needs. The conversion therefore reads the UI scopes
|
||||||
|
//! directly (`ui.background`, `ui.statusline`, ...) and *infers* the ANSI
|
||||||
|
//! palette by scoring every color the theme uses against the hue each slot is
|
||||||
|
//! expected to hold, preferring the scopes that conventionally carry it.
|
||||||
|
//!
|
||||||
|
//! cargo run --example gen_themes -- <helix>/runtime/themes src/themes.rs
|
||||||
|
|
||||||
|
use std::{collections::BTreeMap, fmt::Write as _, path::Path};
|
||||||
|
use toml::Value;
|
||||||
|
|
||||||
|
type Rgb = [u8; 3];
|
||||||
|
|
||||||
|
/// A color as written in a theme: its RGB value, plus the ANSI slot it named if
|
||||||
|
/// it was written as one of Helix's terminal color names rather than as hex.
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
|
struct Color {
|
||||||
|
rgb: Rgb,
|
||||||
|
ansi: Option<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Helix's terminal color names and the palette slots they select. `gray` is
|
||||||
|
/// the dim one and `light-gray` the bright one, matching how Helix hands them
|
||||||
|
/// to crossterm (`Gray` -> dark grey, `LightGray` -> grey).
|
||||||
|
const NAMED: &[(&str, u8)] = &[
|
||||||
|
("black", 0),
|
||||||
|
("red", 1),
|
||||||
|
("green", 2),
|
||||||
|
("yellow", 3),
|
||||||
|
("blue", 4),
|
||||||
|
("magenta", 5),
|
||||||
|
("cyan", 6),
|
||||||
|
("light-gray", 7),
|
||||||
|
("gray", 8),
|
||||||
|
("light-red", 9),
|
||||||
|
("light-green", 10),
|
||||||
|
("light-yellow", 11),
|
||||||
|
("light-blue", 12),
|
||||||
|
("light-magenta", 13),
|
||||||
|
("light-cyan", 14),
|
||||||
|
("white", 15),
|
||||||
|
];
|
||||||
|
|
||||||
|
/// The xterm defaults, used both for themes that name terminal colors outright
|
||||||
|
/// and as the last resort for a slot nothing in a theme fits.
|
||||||
|
const XTERM: [Rgb; 16] = [
|
||||||
|
[0x00, 0x00, 0x00],
|
||||||
|
[0xcd, 0x00, 0x00],
|
||||||
|
[0x00, 0xcd, 0x00],
|
||||||
|
[0xcd, 0xcd, 0x00],
|
||||||
|
[0x00, 0x00, 0xee],
|
||||||
|
[0xcd, 0x00, 0xcd],
|
||||||
|
[0x00, 0xcd, 0xcd],
|
||||||
|
[0xe5, 0xe5, 0xe5],
|
||||||
|
[0x7f, 0x7f, 0x7f],
|
||||||
|
[0xff, 0x00, 0x00],
|
||||||
|
[0x00, 0xff, 0x00],
|
||||||
|
[0xff, 0xff, 0x00],
|
||||||
|
[0x5c, 0x5c, 0xff],
|
||||||
|
[0xff, 0x00, 0xff],
|
||||||
|
[0x00, 0xff, 0xff],
|
||||||
|
[0xff, 0xff, 0xff],
|
||||||
|
];
|
||||||
|
|
||||||
|
/// The hue each chromatic slot aims for, and the scopes that conventionally
|
||||||
|
/// carry it. Earlier scopes are preferred, but only as a tie-break: a theme
|
||||||
|
/// whose `function` is teal still gets a teal blue rather than a stray hue.
|
||||||
|
const SLOTS: [(u8, f32, &[&str]); 6] = [
|
||||||
|
(
|
||||||
|
1,
|
||||||
|
0.0,
|
||||||
|
&[
|
||||||
|
"error",
|
||||||
|
"diagnostic.error",
|
||||||
|
"diff.minus",
|
||||||
|
"keyword.control.exception",
|
||||||
|
"markup.list.unchecked",
|
||||||
|
"variable.builtin",
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
2,
|
||||||
|
120.0,
|
||||||
|
&[
|
||||||
|
"string",
|
||||||
|
"diff.plus",
|
||||||
|
"markup.raw",
|
||||||
|
"hint",
|
||||||
|
"diagnostic.hint",
|
||||||
|
"variable.other.member",
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
3,
|
||||||
|
48.0,
|
||||||
|
&[
|
||||||
|
"warning",
|
||||||
|
"diagnostic.warning",
|
||||||
|
"constant.numeric",
|
||||||
|
"attribute",
|
||||||
|
"type",
|
||||||
|
"markup.heading",
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
4,
|
||||||
|
230.0,
|
||||||
|
&[
|
||||||
|
"function",
|
||||||
|
"info",
|
||||||
|
"diagnostic.info",
|
||||||
|
"constructor",
|
||||||
|
"markup.link.url",
|
||||||
|
"diff.delta",
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
5,
|
||||||
|
300.0,
|
||||||
|
&[
|
||||||
|
"keyword",
|
||||||
|
"constant",
|
||||||
|
"special",
|
||||||
|
"namespace",
|
||||||
|
"markup.link.text",
|
||||||
|
"type.enum.variant",
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
6,
|
||||||
|
185.0,
|
||||||
|
&[
|
||||||
|
"operator",
|
||||||
|
"constant.character.escape",
|
||||||
|
"markup.quote",
|
||||||
|
"string.special",
|
||||||
|
"punctuation.special",
|
||||||
|
"label",
|
||||||
|
],
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
/// One theme file, before inheritance is resolved.
|
||||||
|
#[derive(Default)]
|
||||||
|
struct Raw {
|
||||||
|
inherits: Option<String>,
|
||||||
|
palette: BTreeMap<String, String>,
|
||||||
|
/// Scope -> (fg, bg), each already flattened out of Helix's several
|
||||||
|
/// spellings (bare string, `{ fg, bg }`, `{ underline = { color } }`).
|
||||||
|
scopes: BTreeMap<String, (Option<String>, Option<String>)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read(path: &Path) -> Raw {
|
||||||
|
let text = std::fs::read_to_string(path).expect("cannot read theme file");
|
||||||
|
let table: toml::Table = toml::from_str(&text).expect("theme is not valid TOML");
|
||||||
|
let mut raw = Raw::default();
|
||||||
|
for (key, value) in table {
|
||||||
|
match (key.as_str(), value) {
|
||||||
|
("inherits", Value::String(name)) => raw.inherits = Some(name),
|
||||||
|
("palette", Value::Table(entries)) => {
|
||||||
|
for (name, value) in entries {
|
||||||
|
if let Value::String(color) = value {
|
||||||
|
raw.palette.insert(name, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(_, Value::String(fg)) => {
|
||||||
|
raw.scopes.insert(key, (Some(fg), None));
|
||||||
|
}
|
||||||
|
(_, Value::Table(style)) => {
|
||||||
|
let text = |v: Option<&Value>| v.and_then(Value::as_str).map(str::to_owned);
|
||||||
|
let fg = text(style.get("fg")).or_else(|| {
|
||||||
|
style
|
||||||
|
.get("underline")
|
||||||
|
.and_then(Value::as_table)
|
||||||
|
.and_then(|u| text(u.get("color")))
|
||||||
|
});
|
||||||
|
raw.scopes.insert(key, (fg, text(style.get("bg"))));
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
raw
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A theme with its `inherits` chain folded in: the child's palette entries and
|
||||||
|
/// whole scope entries win over the parent's, exactly as Helix merges them.
|
||||||
|
struct Theme {
|
||||||
|
palette: BTreeMap<String, String>,
|
||||||
|
scopes: BTreeMap<String, (Option<String>, Option<String>)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn flatten(name: &str, raws: &BTreeMap<String, Raw>) -> Theme {
|
||||||
|
let mut chain = vec![];
|
||||||
|
let mut current = Some(name.to_owned());
|
||||||
|
while let Some(name) = current {
|
||||||
|
if chain.contains(&name) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
current = raws.get(&name).and_then(|r| r.inherits.clone());
|
||||||
|
chain.push(name);
|
||||||
|
}
|
||||||
|
let mut theme = Theme {
|
||||||
|
palette: BTreeMap::new(),
|
||||||
|
scopes: BTreeMap::new(),
|
||||||
|
};
|
||||||
|
// Ancestors first so that descendants overwrite them.
|
||||||
|
for name in chain.iter().rev() {
|
||||||
|
let Some(raw) = raws.get(name) else { continue };
|
||||||
|
theme.palette.extend(raw.palette.clone());
|
||||||
|
theme.scopes.extend(raw.scopes.clone());
|
||||||
|
}
|
||||||
|
theme
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Theme {
|
||||||
|
fn color(&self, text: &str) -> Option<Color> {
|
||||||
|
let text = self.palette.get(text).map(String::as_str).unwrap_or(text);
|
||||||
|
if let Some((_, index)) = NAMED.iter().find(|(name, _)| *name == text) {
|
||||||
|
return Some(Color {
|
||||||
|
rgb: XTERM[*index as usize],
|
||||||
|
ansi: Some(*index),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let digits = text.strip_prefix('#')?;
|
||||||
|
let expand = |c: u8| (c << 4) | c;
|
||||||
|
let nibble = |i: usize| u8::from_str_radix(&digits[i..i + 1], 16).ok();
|
||||||
|
let byte = |i: usize| u8::from_str_radix(&digits[i..i + 2], 16).ok();
|
||||||
|
let rgb = match digits.len() {
|
||||||
|
3 => [expand(nibble(0)?), expand(nibble(1)?), expand(nibble(2)?)],
|
||||||
|
6 | 8 => [byte(0)?, byte(2)?, byte(4)?],
|
||||||
|
_ => return None,
|
||||||
|
};
|
||||||
|
Some(Color { rgb, ansi: None })
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fg(&self, scope: &str) -> Option<Color> {
|
||||||
|
self.color(self.scopes.get(scope)?.0.as_deref()?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bg(&self, scope: &str) -> Option<Color> {
|
||||||
|
self.color(self.scopes.get(scope)?.1.as_deref()?)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Every color the theme mentions anywhere, with the number of scopes that
|
||||||
|
/// use it. This is the pool the ANSI slots are chosen from; the count
|
||||||
|
/// separates a theme's working colors from one-off accents such as the
|
||||||
|
/// color of a jump label.
|
||||||
|
fn all(&self) -> Vec<(Color, usize)> {
|
||||||
|
let mut counts: BTreeMap<Rgb, (Color, usize)> = BTreeMap::new();
|
||||||
|
let named = self.palette.values().map(String::as_str);
|
||||||
|
// `ui.*` carries backgrounds, greys and one-off markers such as the
|
||||||
|
// color of a jump label, none of which belong in a terminal palette.
|
||||||
|
let scoped = self
|
||||||
|
.scopes
|
||||||
|
.iter()
|
||||||
|
.filter(|(scope, _)| !scope.starts_with("ui."))
|
||||||
|
.flat_map(|(_, (fg, bg))| [fg, bg])
|
||||||
|
.filter_map(|c| c.as_deref());
|
||||||
|
for color in named.chain(scoped).filter_map(|c| self.color(c)) {
|
||||||
|
counts.entry(color.rgb).or_insert((color, 0)).1 += 1;
|
||||||
|
}
|
||||||
|
counts.into_values().collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn luma(c: Rgb) -> f32 {
|
||||||
|
let channel = |v: u8| {
|
||||||
|
let v = v as f32 / 255.0;
|
||||||
|
if v <= 0.04045 {
|
||||||
|
v / 12.92
|
||||||
|
} else {
|
||||||
|
((v + 0.055) / 1.055).powf(2.4)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
0.2126 * channel(c[0]) + 0.7152 * channel(c[1]) + 0.0722 * channel(c[2])
|
||||||
|
}
|
||||||
|
|
||||||
|
fn contrast(a: Rgb, b: Rgb) -> f32 {
|
||||||
|
let (a, b) = (luma(a) + 0.05, luma(b) + 0.05);
|
||||||
|
if a > b { a / b } else { b / a }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Hue in degrees, saturation and lightness in 0..1.
|
||||||
|
fn hsl(c: Rgb) -> (f32, f32, f32) {
|
||||||
|
let [r, g, b] = [
|
||||||
|
c[0] as f32 / 255.0,
|
||||||
|
c[1] as f32 / 255.0,
|
||||||
|
c[2] as f32 / 255.0,
|
||||||
|
];
|
||||||
|
let max = r.max(g).max(b);
|
||||||
|
let min = r.min(g).min(b);
|
||||||
|
let (span, sum) = (max - min, max + min);
|
||||||
|
let lightness = sum / 2.0;
|
||||||
|
if span < f32::EPSILON {
|
||||||
|
return (0.0, 0.0, lightness);
|
||||||
|
}
|
||||||
|
let saturation = span / (1.0 - (sum - 1.0).abs());
|
||||||
|
let hue = if max == r {
|
||||||
|
60.0 * (((g - b) / span) % 6.0)
|
||||||
|
} else if max == g {
|
||||||
|
60.0 * ((b - r) / span + 2.0)
|
||||||
|
} else {
|
||||||
|
60.0 * ((r - g) / span + 4.0)
|
||||||
|
};
|
||||||
|
(hue.rem_euclid(360.0), saturation, lightness)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hue_distance(a: f32, b: f32) -> f32 {
|
||||||
|
let d = (a - b).abs() % 360.0;
|
||||||
|
d.min(360.0 - d)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn mix(a: Rgb, b: Rgb, t: f32) -> Rgb {
|
||||||
|
let channel = |i: usize| (a[i] as f32 + (b[i] as f32 - a[i] as f32) * t).round() as u8;
|
||||||
|
[channel(0), channel(1), channel(2)]
|
||||||
|
}
|
||||||
|
|
||||||
|
const BLACK: Rgb = [0, 0, 0];
|
||||||
|
const WHITE: Rgb = [255, 255, 255];
|
||||||
|
|
||||||
|
/// The converted theme, mirroring the struct in `src/theme.rs`.
|
||||||
|
struct Out {
|
||||||
|
dark: bool,
|
||||||
|
background: Rgb,
|
||||||
|
foreground: Rgb,
|
||||||
|
cursor: Rgb,
|
||||||
|
selection_bg: Rgb,
|
||||||
|
selection_fg: Rgb,
|
||||||
|
accent: Rgb,
|
||||||
|
chrome_bg: Rgb,
|
||||||
|
chrome_fg: Rgb,
|
||||||
|
chrome_active_bg: Rgb,
|
||||||
|
border: Rgb,
|
||||||
|
popup_bg: Rgb,
|
||||||
|
ansi: [Rgb; 16],
|
||||||
|
}
|
||||||
|
|
||||||
|
fn convert(theme: &Theme) -> Out {
|
||||||
|
let text = theme
|
||||||
|
.fg("ui.text")
|
||||||
|
.or_else(|| theme.fg("ui.background"))
|
||||||
|
.or_else(|| theme.fg("ui.statusline"));
|
||||||
|
let background = theme
|
||||||
|
.bg("ui.background")
|
||||||
|
.or_else(|| theme.bg("ui.popup"))
|
||||||
|
.or_else(|| theme.bg("ui.statusline"));
|
||||||
|
// A theme that never states a background (the `term16` family leaves it to
|
||||||
|
// the terminal) is placed by the brightness of its text instead.
|
||||||
|
let dark = match (background, text) {
|
||||||
|
(Some(bg), _) => luma(bg.rgb) < 0.22,
|
||||||
|
(None, Some(fg)) => luma(fg.rgb) > 0.22,
|
||||||
|
(None, None) => true,
|
||||||
|
};
|
||||||
|
let background = background.map_or(if dark { BLACK } else { WHITE }, |c| c.rgb);
|
||||||
|
let mut foreground = text.map_or(if dark { WHITE } else { BLACK }, |c| c.rgb);
|
||||||
|
// A theme that states neither (peachpuff leaves both to the terminal) can
|
||||||
|
// resolve to text the same shade as its background, which renders nothing.
|
||||||
|
if contrast(foreground, background) < 2.0 {
|
||||||
|
foreground = if dark { WHITE } else { BLACK };
|
||||||
|
}
|
||||||
|
let far = if dark { WHITE } else { BLACK };
|
||||||
|
|
||||||
|
let ansi = palette(theme, background, foreground, dark);
|
||||||
|
let cursor = theme
|
||||||
|
.bg("ui.cursor.primary")
|
||||||
|
.or_else(|| theme.bg("ui.cursor"))
|
||||||
|
.or_else(|| theme.fg("ui.cursor.primary"))
|
||||||
|
.or_else(|| theme.fg("ui.cursor"))
|
||||||
|
.map_or(foreground, |c| c.rgb);
|
||||||
|
let selection_bg = theme
|
||||||
|
.bg("ui.selection.primary")
|
||||||
|
.or_else(|| theme.bg("ui.selection"))
|
||||||
|
.map_or(mix(background, far, 0.22), |c| c.rgb);
|
||||||
|
let selection_fg = theme
|
||||||
|
.fg("ui.selection.primary")
|
||||||
|
.or_else(|| theme.fg("ui.selection"))
|
||||||
|
.map(|c| c.rgb)
|
||||||
|
.filter(|c| contrast(*c, selection_bg) >= 2.5)
|
||||||
|
.unwrap_or_else(|| {
|
||||||
|
if contrast(foreground, selection_bg) >= 2.5 {
|
||||||
|
foreground
|
||||||
|
} else {
|
||||||
|
mix(
|
||||||
|
selection_bg,
|
||||||
|
if luma(selection_bg) > 0.3 {
|
||||||
|
BLACK
|
||||||
|
} else {
|
||||||
|
WHITE
|
||||||
|
},
|
||||||
|
0.85,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let chrome_bg = theme
|
||||||
|
.bg("ui.statusline")
|
||||||
|
.or_else(|| theme.bg("ui.popup"))
|
||||||
|
.map(|c| c.rgb)
|
||||||
|
.filter(|c| *c != background)
|
||||||
|
.unwrap_or_else(|| mix(background, far, 0.09));
|
||||||
|
let chrome_fg = theme
|
||||||
|
.fg("ui.statusline")
|
||||||
|
.map(|c| c.rgb)
|
||||||
|
.filter(|c| contrast(*c, chrome_bg) >= 2.0)
|
||||||
|
.unwrap_or_else(|| mix(chrome_bg, far, 0.7));
|
||||||
|
// The accent marks the focused pane: it is drawn both on the title bar and
|
||||||
|
// as a border on the terminal background, so it has to read on both.
|
||||||
|
let readable = |c: Rgb| contrast(c, chrome_bg) >= 2.5 && contrast(c, background) >= 2.5;
|
||||||
|
let vivid = [theme.fg("ui.cursor.match").map(|c| c.rgb), Some(cursor)]
|
||||||
|
.into_iter()
|
||||||
|
.flatten()
|
||||||
|
.find(|c| readable(*c) && hsl(*c).1 > 0.30);
|
||||||
|
let accent = vivid
|
||||||
|
// A theme whose cursor is a plain grey still deserves a colored focus
|
||||||
|
// ring, so fall back to its own blue, cyan or magenta.
|
||||||
|
.or_else(|| {
|
||||||
|
[4, 6, 5, 3]
|
||||||
|
.into_iter()
|
||||||
|
.map(|i| ansi[i])
|
||||||
|
.find(|c| readable(*c))
|
||||||
|
})
|
||||||
|
.or(Some(cursor).filter(|c| readable(*c)))
|
||||||
|
.unwrap_or(foreground);
|
||||||
|
Out {
|
||||||
|
dark,
|
||||||
|
background,
|
||||||
|
foreground,
|
||||||
|
cursor,
|
||||||
|
selection_bg,
|
||||||
|
selection_fg,
|
||||||
|
accent,
|
||||||
|
chrome_bg,
|
||||||
|
chrome_fg,
|
||||||
|
// The focused pane's title bar steps away from the unfocused ones,
|
||||||
|
// whichever direction that is for this theme's chrome.
|
||||||
|
chrome_active_bg: mix(
|
||||||
|
chrome_bg,
|
||||||
|
if luma(chrome_bg) > 0.18 { BLACK } else { WHITE },
|
||||||
|
0.14,
|
||||||
|
),
|
||||||
|
// Unfocused borders are a hint, not a frame, so a theme with a loud
|
||||||
|
// window color is pulled back towards its background.
|
||||||
|
border: theme
|
||||||
|
.fg("ui.window")
|
||||||
|
.or_else(|| theme.fg("ui.virtual.indent-guide"))
|
||||||
|
.map_or(mix(background, far, 0.28), |c| mix(background, c.rgb, 0.65)),
|
||||||
|
popup_bg: theme.bg("ui.popup").map_or(chrome_bg, |c| c.rgb),
|
||||||
|
ansi,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Picks the sixteen ANSI colors. The six chromatic slots score every color the
|
||||||
|
/// theme uses against the slot's hue; the greys are derived from the background
|
||||||
|
/// and foreground so that they always stay legible against the theme's own
|
||||||
|
/// background.
|
||||||
|
fn palette(theme: &Theme, background: Rgb, foreground: Rgb, dark: bool) -> [Rgb; 16] {
|
||||||
|
let pool = theme.all();
|
||||||
|
let mut ansi = XTERM;
|
||||||
|
// A theme whose palette names terminal colors outright is already
|
||||||
|
// describing a palette; those entries are taken as written.
|
||||||
|
let named: BTreeMap<u8, Rgb> = theme
|
||||||
|
.palette
|
||||||
|
.keys()
|
||||||
|
.filter_map(|name| Some((slot_named(name)?, theme.color(name)?.rgb)))
|
||||||
|
.collect();
|
||||||
|
let mut taken: Vec<Rgb> = vec![];
|
||||||
|
let mut assigned = [false; 7];
|
||||||
|
for (index, rgb) in &named {
|
||||||
|
ansi[*index as usize] = *rgb;
|
||||||
|
if let Some(slot) = assigned.get_mut(*index as usize) {
|
||||||
|
*slot = true;
|
||||||
|
taken.push(*rgb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Score every slot against every color the theme uses, then hand each color
|
||||||
|
// to the slot that wants it most. Assigning greedily one slot at a time
|
||||||
|
// would let an early slot take a color a later slot needed far more, which
|
||||||
|
// is how palettes with no true blue end up with two cyans.
|
||||||
|
let mut pairs: Vec<(f32, usize, Rgb)> = vec![];
|
||||||
|
for (index, hue, scopes) in SLOTS {
|
||||||
|
if assigned[index as usize] {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let preferred: Vec<Rgb> = scopes
|
||||||
|
.iter()
|
||||||
|
.filter_map(|s| Some(theme.fg(s)?.rgb))
|
||||||
|
.collect();
|
||||||
|
for (candidate, uses) in &pool {
|
||||||
|
let (h, s, l) = hsl(candidate.rgb);
|
||||||
|
// A grey, an unreadable color, the plain text color and a color the
|
||||||
|
// theme only spelled as a terminal name (which says nothing about
|
||||||
|
// what that terminal color should be) are never palette entries.
|
||||||
|
if s < 0.10
|
||||||
|
|| contrast(candidate.rgb, background) < 1.8
|
||||||
|
|| candidate.ansi.is_some()
|
||||||
|
|| candidate.rgb == foreground
|
||||||
|
|| candidate.rgb == background
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let rank = preferred
|
||||||
|
.iter()
|
||||||
|
.position(|p| *p == candidate.rgb)
|
||||||
|
.map_or(20.0, |r| r as f32 * 2.5);
|
||||||
|
// Whichever slot's hue this color sits closest to has the better
|
||||||
|
// claim on it, so that a theme's red is not spent on magenta just
|
||||||
|
// because it happens to be the color of `keyword`.
|
||||||
|
let closest = SLOTS
|
||||||
|
.iter()
|
||||||
|
.map(|(_, target, _)| *target)
|
||||||
|
.min_by(|a, b| hue_distance(h, *a).total_cmp(&hue_distance(h, *b)));
|
||||||
|
let score = hue_distance(h, hue) * 1.5
|
||||||
|
+ rank
|
||||||
|
+ (1.0 - s) * 38.0
|
||||||
|
+ if closest == Some(hue) { 0.0 } else { 45.0 }
|
||||||
|
// A color used once is a one-off accent, not a working color.
|
||||||
|
+ match uses {
|
||||||
|
0 | 1 => 22.0,
|
||||||
|
2 => 10.0,
|
||||||
|
_ => 0.0,
|
||||||
|
}
|
||||||
|
+ if l > 0.85 { 40.0 } else { 0.0 };
|
||||||
|
pairs.push((score, index as usize, candidate.rgb));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pairs.sort_by(|a, b| a.0.total_cmp(&b.0).then(a.1.cmp(&b.1)));
|
||||||
|
for (_, index, rgb) in &pairs {
|
||||||
|
if !assigned[*index] && !taken.contains(rgb) {
|
||||||
|
assigned[*index] = true;
|
||||||
|
ansi[*index] = *rgb;
|
||||||
|
taken.push(*rgb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// A theme with fewer than six usable colors leaves slots over; those share
|
||||||
|
// whichever color came closest rather than falling back to a stock xterm
|
||||||
|
// primary that belongs to no theme at all.
|
||||||
|
for (_, index, rgb) in &pairs {
|
||||||
|
if !assigned[*index] {
|
||||||
|
assigned[*index] = true;
|
||||||
|
ansi[*index] = *rgb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (index, _, _) in SLOTS {
|
||||||
|
if !assigned[index as usize] {
|
||||||
|
ansi[index as usize] = mix(XTERM[index as usize], foreground, 0.4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The bright variant is the theme's own lighter shade of the same color
|
||||||
|
// where it has one, and a lightened copy otherwise. Matching the hue is not
|
||||||
|
// enough: a pale grey-blue is a poor bright blue, so the candidate has to
|
||||||
|
// keep most of the base color's chroma, and it cannot be a color another
|
||||||
|
// slot already owns.
|
||||||
|
let chroma = |c: Rgb| (*c.iter().max().unwrap() - *c.iter().min().unwrap()) as f32;
|
||||||
|
for (index, _, _) in SLOTS {
|
||||||
|
if named.contains_key(&(index + 8)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let base = ansi[index as usize];
|
||||||
|
let (base_hue, _, lightness) = hsl(base);
|
||||||
|
let brighter = pool
|
||||||
|
.iter()
|
||||||
|
.map(|(c, _)| c)
|
||||||
|
.filter(|c| {
|
||||||
|
let (h, _, l) = hsl(c.rgb);
|
||||||
|
hue_distance(h, base_hue) <= 30.0
|
||||||
|
&& chroma(c.rgb) >= chroma(base) * 0.7
|
||||||
|
&& (0.05..=0.40).contains(&(l - lightness))
|
||||||
|
&& contrast(c.rgb, background) >= 2.0
|
||||||
|
&& !taken.contains(&c.rgb)
|
||||||
|
})
|
||||||
|
.min_by(|a, b| hsl(a.rgb).2.total_cmp(&hsl(b.rgb).2));
|
||||||
|
ansi[index as usize + 8] = brighter.map_or_else(
|
||||||
|
|| mix(base, WHITE, if lightness > 0.7 { 0.12 } else { 0.26 }),
|
||||||
|
|c| c.rgb,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Greys: black through bright white always span from the theme's darker end
|
||||||
|
// to its lighter end, so ANSI text stays readable in light themes too.
|
||||||
|
let comment = theme
|
||||||
|
.fg("comment")
|
||||||
|
.map(|c| c.rgb)
|
||||||
|
.filter(|c| contrast(*c, background) >= 2.0);
|
||||||
|
let greys = if dark {
|
||||||
|
[
|
||||||
|
mix(background, WHITE, 0.13),
|
||||||
|
foreground,
|
||||||
|
comment.unwrap_or_else(|| mix(background, WHITE, 0.42)),
|
||||||
|
mix(foreground, WHITE, 0.35),
|
||||||
|
]
|
||||||
|
} else {
|
||||||
|
[
|
||||||
|
mix(foreground, BLACK, 0.25),
|
||||||
|
mix(background, BLACK, 0.13),
|
||||||
|
comment.unwrap_or_else(|| mix(foreground, background, 0.45)),
|
||||||
|
background,
|
||||||
|
]
|
||||||
|
};
|
||||||
|
for (slot, grey) in [0, 7, 8, 15].into_iter().zip(greys) {
|
||||||
|
ansi[slot as usize] = *named.get(&slot).unwrap_or(&grey);
|
||||||
|
}
|
||||||
|
ansi
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The palette slot a `[palette]` key names outright, so that a theme defining
|
||||||
|
/// `red`/`bright-blue` and friends keeps its own values.
|
||||||
|
fn slot_named(name: &str) -> Option<u8> {
|
||||||
|
let name = name.to_ascii_lowercase().replace('_', "-");
|
||||||
|
let (bright, base) = match name
|
||||||
|
.strip_prefix("bright-")
|
||||||
|
.or_else(|| name.strip_prefix("light-"))
|
||||||
|
{
|
||||||
|
Some(base) => (8, base.to_owned()),
|
||||||
|
None => (0, name),
|
||||||
|
};
|
||||||
|
let index = match base.as_str() {
|
||||||
|
"black" => 0,
|
||||||
|
"red" => 1,
|
||||||
|
"green" => 2,
|
||||||
|
"yellow" => 3,
|
||||||
|
"blue" => 4,
|
||||||
|
"magenta" => 5,
|
||||||
|
"cyan" => 6,
|
||||||
|
"white" => 7,
|
||||||
|
_ => return None,
|
||||||
|
};
|
||||||
|
Some(index + bright)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut args = std::env::args().skip(1);
|
||||||
|
let dir = args
|
||||||
|
.next()
|
||||||
|
.expect("usage: gen_themes <themes dir> <out.rs>");
|
||||||
|
let out = args
|
||||||
|
.next()
|
||||||
|
.expect("usage: gen_themes <themes dir> <out.rs>");
|
||||||
|
|
||||||
|
let mut raws = BTreeMap::new();
|
||||||
|
for entry in std::fs::read_dir(&dir).expect("cannot read themes directory") {
|
||||||
|
let path = entry.expect("cannot read theme").path();
|
||||||
|
if path.extension().is_some_and(|e| e == "toml") {
|
||||||
|
let name = path.file_stem().unwrap().to_string_lossy().into_owned();
|
||||||
|
raws.insert(name, read(&path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut text = String::from(
|
||||||
|
"//! The themes Helix ships with, converted by `cargo run --example gen_themes`.\n\
|
||||||
|
//! Generated file: edit the generator, not this.\n\
|
||||||
|
//!\n\
|
||||||
|
//! Upstream: <https://github.com/helix-editor/helix/tree/master/runtime/themes>.\n\
|
||||||
|
//! The individual themes keep their own authors and licenses; see `themes/LICENSES`.\n\n\
|
||||||
|
use crate::theme::Theme;\n\n\
|
||||||
|
/// Every built-in theme, sorted by name so that lookup can binary search.\n\
|
||||||
|
pub static THEMES: &[(&str, Theme)] = &[\n",
|
||||||
|
);
|
||||||
|
for name in raws.keys() {
|
||||||
|
let out = convert(&flatten(name, &raws));
|
||||||
|
let hex = |c: Rgb| format!("0x{:02x}{:02x}{:02x}", c[0], c[1], c[2]);
|
||||||
|
let ansi = out
|
||||||
|
.ansi
|
||||||
|
.iter()
|
||||||
|
.map(|c| hex(*c))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", ");
|
||||||
|
writeln!(
|
||||||
|
text,
|
||||||
|
" (\n {name:?},\n Theme {{\n \
|
||||||
|
dark: {dark},\n background: {bg},\n foreground: {fg},\n \
|
||||||
|
cursor: {cursor},\n \
|
||||||
|
selection_bg: {sel_bg},\n selection_fg: {sel_fg},\n \
|
||||||
|
accent: {accent},\n chrome_bg: {chrome_bg},\n \
|
||||||
|
chrome_fg: {chrome_fg},\n chrome_active_bg: {chrome_active},\n \
|
||||||
|
border: {border},\n popup_bg: {popup},\n \
|
||||||
|
ansi: [\n {ansi},\n ],\n }},\n ),",
|
||||||
|
dark = out.dark,
|
||||||
|
bg = hex(out.background),
|
||||||
|
fg = hex(out.foreground),
|
||||||
|
cursor = hex(out.cursor),
|
||||||
|
sel_bg = hex(out.selection_bg),
|
||||||
|
sel_fg = hex(out.selection_fg),
|
||||||
|
accent = hex(out.accent),
|
||||||
|
chrome_bg = hex(out.chrome_bg),
|
||||||
|
chrome_fg = hex(out.chrome_fg),
|
||||||
|
chrome_active = hex(out.chrome_active_bg),
|
||||||
|
border = hex(out.border),
|
||||||
|
popup = hex(out.popup_bg),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
text.push_str("];\n");
|
||||||
|
std::fs::write(&out, text).expect("cannot write output");
|
||||||
|
eprintln!("wrote {} themes to {out}", raws.len());
|
||||||
|
}
|
||||||
@@ -132,6 +132,35 @@
|
|||||||
unset slermCache slermStale slermTmp slermDir slermGlob slermLib
|
unset slermCache slermStale slermTmp slermDir slermGlob slermLib
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
# macOS only gives a process a dock icon, a menu bar and a real
|
||||||
|
# application name when it runs from a bundle, so ship one and keep
|
||||||
|
# bin/slerm as a symlink into it for terminal use.
|
||||||
|
appBundle = version: ''
|
||||||
|
app="$out/Applications/slerm.app"
|
||||||
|
mkdir -p "$app/Contents/MacOS" "$app/Contents/Resources"
|
||||||
|
cat > "$app/Contents/Info.plist" <<EOF
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleName</key><string>slerm</string>
|
||||||
|
<key>CFBundleDisplayName</key><string>slerm</string>
|
||||||
|
<key>CFBundleExecutable</key><string>slerm</string>
|
||||||
|
<key>CFBundleIdentifier</key><string>org.slerm.slerm</string>
|
||||||
|
<key>CFBundleInfoDictionaryVersion</key><string>6.0</string>
|
||||||
|
<key>CFBundlePackageType</key><string>APPL</string>
|
||||||
|
<key>CFBundleShortVersionString</key><string>${version}</string>
|
||||||
|
<key>CFBundleVersion</key><string>${version}</string>
|
||||||
|
<key>LSApplicationCategoryType</key><string>public.app-category.developer-tools</string>
|
||||||
|
<key>LSMinimumSystemVersion</key><string>11.0</string>
|
||||||
|
<key>NSHighResolutionCapable</key><true/>
|
||||||
|
<key>NSSupportsAutomaticGraphicsSwitching</key><true/>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
|
EOF
|
||||||
|
mv "$out/bin/slerm" "$app/Contents/MacOS/slerm"
|
||||||
|
ln -s "$app/Contents/MacOS/slerm" "$out/bin/slerm"
|
||||||
|
'';
|
||||||
ghosttyEnv = {
|
ghosttyEnv = {
|
||||||
GHOSTTY_SOURCE_DIR = "${ghostty-src}";
|
GHOSTTY_SOURCE_DIR = "${ghostty-src}";
|
||||||
GHOSTTY_ZIG_SYSTEM_DIR = "${ghosttyDeps}";
|
GHOSTTY_ZIG_SYSTEM_DIR = "${ghosttyDeps}";
|
||||||
@@ -178,11 +207,16 @@
|
|||||||
checkFlags = [
|
checkFlags = [
|
||||||
"--test-threads=1"
|
"--test-threads=1"
|
||||||
"--skip=app::tests::"
|
"--skip=app::tests::"
|
||||||
|
"--skip=pane::scrollback_tests::"
|
||||||
"--skip=tests::pty_executes_input_and_bracketed_paste_is_sanitized"
|
"--skip=tests::pty_executes_input_and_bracketed_paste_is_sanitized"
|
||||||
"--skip=tests::new_panes_start_in_the_directory_of_the_pane_they_came_from"
|
"--skip=tests::new_panes_start_in_the_directory_of_the_pane_they_came_from"
|
||||||
"--skip=tests::osc7_wins_over_the_process_directory_but_only_for_this_machine"
|
"--skip=tests::osc7_wins_over_the_process_directory_but_only_for_this_machine"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
postInstall = lib.optionalString pkgs.stdenv.hostPlatform.isDarwin (
|
||||||
|
appBundle manifest.package.version
|
||||||
|
);
|
||||||
|
|
||||||
postFixup = lib.optionalString pkgs.stdenv.hostPlatform.isLinux ''
|
postFixup = lib.optionalString pkgs.stdenv.hostPlatform.isLinux ''
|
||||||
wrapProgram "$out/bin/slerm" \
|
wrapProgram "$out/bin/slerm" \
|
||||||
--suffix LD_LIBRARY_PATH : ${lib.makeLibraryPath runtimeLibraries} \
|
--suffix LD_LIBRARY_PATH : ${lib.makeLibraryPath runtimeLibraries} \
|
||||||
|
|||||||
+273
-49
@@ -3,10 +3,10 @@ use crate::{
|
|||||||
input,
|
input,
|
||||||
layout::{Axis, Direction, Layout, PaneId, Tab},
|
layout::{Axis, Direction, Layout, PaneId, Tab},
|
||||||
pane::{self, Pane},
|
pane::{self, Pane},
|
||||||
render::color,
|
theme::{self, Theme},
|
||||||
};
|
};
|
||||||
use anyhow::{Result, ensure};
|
use anyhow::{Result, ensure};
|
||||||
use egui::{Color32, Rect, Stroke, vec2};
|
use egui::{CornerRadius, Rect, Stroke, vec2};
|
||||||
use std::{
|
use std::{
|
||||||
collections::{BTreeMap, HashSet},
|
collections::{BTreeMap, HashSet},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
@@ -14,6 +14,7 @@ use std::{
|
|||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
config: Config,
|
config: Config,
|
||||||
|
theme: Theme,
|
||||||
config_path: PathBuf,
|
config_path: PathBuf,
|
||||||
panes: BTreeMap<PaneId, Pane>,
|
panes: BTreeMap<PaneId, Pane>,
|
||||||
tabs: Vec<Tab>,
|
tabs: Vec<Tab>,
|
||||||
@@ -23,20 +24,39 @@ pub struct App {
|
|||||||
suppressed: HashSet<egui::Key>,
|
suppressed: HashSet<egui::Key>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fonts(config: &Config) -> Result<egui::FontDefinitions> {
|
/// Width kept free at the left of the tab bar for the macOS traffic lights,
|
||||||
let mut fonts = egui::FontDefinitions::default();
|
/// which float over the content once the titlebar is hidden.
|
||||||
if let Some(path) = &config.font_path {
|
const TITLEBAR_INSET: f32 = 70.0;
|
||||||
let data = std::fs::read(path)?;
|
/// Height the tab bar needs so the traffic lights fit inside it.
|
||||||
fonts
|
const TITLEBAR_HEIGHT: f32 = 28.0;
|
||||||
.font_data
|
|
||||||
.insert("terminal".into(), egui::FontData::from_owned(data).into());
|
/// With the titlebar hidden the tab bar takes its place, so let the empty space
|
||||||
fonts
|
/// beside the tabs drag the window and double-click to zoom, like a titlebar.
|
||||||
.families
|
fn drag_window(ui: &mut egui::Ui) {
|
||||||
.get_mut(&egui::FontFamily::Monospace)
|
let used = ui.min_rect();
|
||||||
.unwrap()
|
let free = Rect::from_min_max(
|
||||||
.insert(0, "terminal".into());
|
egui::pos2(used.right(), used.top()),
|
||||||
|
egui::pos2(ui.max_rect().right(), used.bottom()),
|
||||||
|
);
|
||||||
|
if free.width() <= 0.0 {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
Ok(fonts)
|
let response = ui.interact(
|
||||||
|
free,
|
||||||
|
ui.id().with("titlebar drag"),
|
||||||
|
egui::Sense::click_and_drag(),
|
||||||
|
);
|
||||||
|
if response.double_clicked() {
|
||||||
|
let maximized = ui.input(|i| i.viewport().maximized.unwrap_or(false));
|
||||||
|
ui.ctx()
|
||||||
|
.send_viewport_cmd(egui::ViewportCommand::Maximized(!maximized));
|
||||||
|
} else if response.drag_started_by(egui::PointerButton::Primary) {
|
||||||
|
ui.ctx().send_viewport_cmd(egui::ViewportCommand::StartDrag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn fonts(config: &Config) -> Result<egui::FontDefinitions> {
|
||||||
|
crate::fonts::load(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
@@ -45,11 +65,13 @@ impl App {
|
|||||||
config: Config,
|
config: Config,
|
||||||
config_path: PathBuf,
|
config_path: PathBuf,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
cc.egui_ctx.set_visuals(egui::Visuals::dark());
|
let theme = config.theme()?;
|
||||||
|
cc.egui_ctx.set_visuals(theme.visuals());
|
||||||
cc.egui_ctx.set_fonts(fonts(&config)?);
|
cc.egui_ctx.set_fonts(fonts(&config)?);
|
||||||
let pane = Pane::new(&config, &cc.egui_ctx, None)?;
|
let pane = Pane::new(&config, &theme, &cc.egui_ctx, None)?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
config,
|
config,
|
||||||
|
theme,
|
||||||
config_path,
|
config_path,
|
||||||
panes: BTreeMap::from([(1, pane)]),
|
panes: BTreeMap::from([(1, pane)]),
|
||||||
tabs: vec![Tab::new(1, 1)],
|
tabs: vec![Tab::new(1, 1)],
|
||||||
@@ -71,13 +93,27 @@ impl App {
|
|||||||
.get(self.current)
|
.get(self.current)
|
||||||
.and_then(|tab| self.panes.get(&tab.active))
|
.and_then(|tab| self.panes.get(&tab.active))
|
||||||
.and_then(Pane::cwd);
|
.and_then(Pane::cwd);
|
||||||
let pane = Pane::new(&self.config, ctx, cwd.as_deref())?;
|
let pane = Pane::new(&self.config, &self.theme, ctx, cwd.as_deref())?;
|
||||||
let id = self.next_id;
|
let id = self.next_id;
|
||||||
self.next_id += 1;
|
self.next_id += 1;
|
||||||
self.panes.insert(id, pane);
|
self.panes.insert(id, pane);
|
||||||
Ok(id)
|
Ok(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Switches theme for this session. Every open pane is retinted, since a
|
||||||
|
/// terminal keeps its palette rather than asking for it each frame.
|
||||||
|
fn set_theme(&mut self, name: &str, ctx: &egui::Context) -> Result<()> {
|
||||||
|
let previous = std::mem::replace(&mut self.config.theme, name.to_owned());
|
||||||
|
self.theme = self.config.theme().inspect_err(|_| {
|
||||||
|
self.config.theme = previous;
|
||||||
|
})?;
|
||||||
|
for pane in self.panes.values_mut() {
|
||||||
|
pane::apply_config(&mut pane.terminal, &self.config, &self.theme)?;
|
||||||
|
}
|
||||||
|
ctx.set_visuals(self.theme.visuals());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn action(&mut self, action: Action, ctx: &egui::Context) -> Result<()> {
|
fn action(&mut self, action: Action, ctx: &egui::Context) -> Result<()> {
|
||||||
let active = self.tabs[self.current].active;
|
let active = self.tabs[self.current].active;
|
||||||
match action {
|
match action {
|
||||||
@@ -185,10 +221,12 @@ impl App {
|
|||||||
Action::ReloadConfig => {
|
Action::ReloadConfig => {
|
||||||
let config = Config::load(&self.config_path)?;
|
let config = Config::load(&self.config_path)?;
|
||||||
let fonts = fonts(&config)?;
|
let fonts = fonts(&config)?;
|
||||||
|
self.theme = config.theme()?;
|
||||||
for pane in self.panes.values_mut() {
|
for pane in self.panes.values_mut() {
|
||||||
pane::apply_config(&mut pane.terminal, &config)?;
|
pane::apply_config(&mut pane.terminal, &config, &self.theme)?;
|
||||||
}
|
}
|
||||||
ctx.set_fonts(fonts);
|
ctx.set_fonts(fonts);
|
||||||
|
ctx.set_visuals(self.theme.visuals());
|
||||||
self.config = config;
|
self.config = config;
|
||||||
}
|
}
|
||||||
Action::Copy => {
|
Action::Copy => {
|
||||||
@@ -197,6 +235,13 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Action::Paste => ctx.send_viewport_cmd(egui::ViewportCommand::RequestPaste),
|
Action::Paste => ctx.send_viewport_cmd(egui::ViewportCommand::RequestPaste),
|
||||||
|
Action::OpenScrollback => {
|
||||||
|
self.panes.get_mut(&active).unwrap().open_scrollback(
|
||||||
|
&self.config,
|
||||||
|
&self.theme,
|
||||||
|
ctx,
|
||||||
|
)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -351,8 +396,13 @@ impl eframe::App for App {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let mut action = None;
|
let mut action = None;
|
||||||
|
let mut picked = None;
|
||||||
egui::TopBottomPanel::top("tabs").show(ctx, |ui| {
|
egui::TopBottomPanel::top("tabs").show(ctx, |ui| {
|
||||||
ui.horizontal_wrapped(|ui| {
|
ui.horizontal_wrapped(|ui| {
|
||||||
|
if cfg!(target_os = "macos") {
|
||||||
|
ui.add_space(TITLEBAR_INSET);
|
||||||
|
ui.set_min_height(TITLEBAR_HEIGHT);
|
||||||
|
}
|
||||||
for (index, tab) in self.tabs.iter().enumerate() {
|
for (index, tab) in self.tabs.iter().enumerate() {
|
||||||
let title = self.panes[&tab.active].terminal.title().unwrap_or("");
|
let title = self.panes[&tab.active].terminal.title().unwrap_or("");
|
||||||
let label = if title.is_empty() {
|
let label = if title.is_empty() {
|
||||||
@@ -382,6 +432,7 @@ impl eframe::App for App {
|
|||||||
("Zoom / restore", Action::ZoomPane),
|
("Zoom / restore", Action::ZoomPane),
|
||||||
("Next pane", Action::NextPane),
|
("Next pane", Action::NextPane),
|
||||||
("Close pane", Action::ClosePane),
|
("Close pane", Action::ClosePane),
|
||||||
|
("Open scrollback in editor", Action::OpenScrollback),
|
||||||
] {
|
] {
|
||||||
if ui.button(label).clicked() {
|
if ui.button(label).clicked() {
|
||||||
action = Some(a);
|
action = Some(a);
|
||||||
@@ -394,20 +445,37 @@ impl eframe::App for App {
|
|||||||
action = Some(Action::ReloadConfig);
|
action = Some(Action::ReloadConfig);
|
||||||
ui.close();
|
ui.close();
|
||||||
}
|
}
|
||||||
|
ui.menu_button("Theme", |ui| {
|
||||||
|
ui.label("Applies now; set `theme` in the config to keep it.");
|
||||||
|
egui::ScrollArea::vertical()
|
||||||
|
.max_height(420.0)
|
||||||
|
.show(ui, |ui| {
|
||||||
|
for name in theme::names() {
|
||||||
|
let current = self.config.theme == name;
|
||||||
|
if ui.selectable_label(current, name).clicked() && !current {
|
||||||
|
picked = Some(name);
|
||||||
|
ui.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
if cfg!(target_os = "macos") {
|
||||||
|
drag_window(ui);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
if let Some(error) = self.error.clone() {
|
if let Some(error) = self.error.clone() {
|
||||||
egui::TopBottomPanel::bottom("error").show(ctx, |ui| {
|
egui::TopBottomPanel::bottom("error").show(ctx, |ui| {
|
||||||
ui.horizontal_wrapped(|ui| {
|
ui.horizontal_wrapped(|ui| {
|
||||||
ui.colored_label(Color32::LIGHT_RED, error);
|
ui.colored_label(theme::color(self.theme.ansi[9]), error);
|
||||||
if ui.button("Dismiss").clicked() {
|
if ui.button("Dismiss").clicked() {
|
||||||
self.error = None;
|
self.error = None;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
let bg = color(config::rgb(&self.config.background).unwrap());
|
let bg = theme::color(self.theme.background);
|
||||||
let tab = &mut self.tabs[self.current];
|
let tab = &mut self.tabs[self.current];
|
||||||
let mut tiled = vec![];
|
let mut tiled = vec![];
|
||||||
let mut workspace = Rect::NOTHING;
|
let mut workspace = Rect::NOTHING;
|
||||||
@@ -426,7 +494,7 @@ impl eframe::App for App {
|
|||||||
if !tab.zoomed {
|
if !tab.zoomed {
|
||||||
pane.last_rect = *rect;
|
pane.last_rect = *rect;
|
||||||
}
|
}
|
||||||
if show_pane(ui, *id, pane, *rect, &self.config, active) {
|
if show_pane(ui, *id, pane, *rect, &self.config, &self.theme, active) {
|
||||||
tab.active = *id;
|
tab.active = *id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -436,23 +504,28 @@ impl eframe::App for App {
|
|||||||
let pane = self.panes.get_mut(&id).unwrap();
|
let pane = self.panes.get_mut(&id).unwrap();
|
||||||
let window_id = egui::Id::new(("float", tab.id, id));
|
let window_id = egui::Id::new(("float", tab.id, id));
|
||||||
let active = tab.active == id;
|
let active = tab.active == id;
|
||||||
let (pos, size) = float_placement(workspace, index, &self.config.multiplexer);
|
let window = egui::Window::new(pane_title(id, pane))
|
||||||
let result = egui::Window::new(pane_title(id, pane))
|
|
||||||
.id(window_id)
|
.id(window_id)
|
||||||
.title_bar(false)
|
.title_bar(false)
|
||||||
.constrain_to(workspace)
|
.constrain_to(workspace)
|
||||||
.default_pos(pos)
|
|
||||||
.default_size(size)
|
|
||||||
.min_size(vec2(160.0, 100.0))
|
.min_size(vec2(160.0, 100.0))
|
||||||
.frame(egui::Frame::NONE.fill(bg))
|
.frame(egui::Frame::NONE.fill(bg));
|
||||||
.show(ctx, |ui| {
|
let result = position_float(
|
||||||
let rect = ui.available_rect_before_wrap();
|
ctx,
|
||||||
ui.allocate_rect(rect, egui::Sense::hover());
|
window,
|
||||||
pane.last_rect = rect;
|
window_id,
|
||||||
if show_pane(ui, id, pane, rect, &self.config, active) {
|
index,
|
||||||
tab.active = id;
|
workspace,
|
||||||
}
|
&self.config.multiplexer,
|
||||||
});
|
)
|
||||||
|
.show(ctx, |ui| {
|
||||||
|
let rect = ui.available_rect_before_wrap();
|
||||||
|
ui.allocate_rect(rect, egui::Sense::hover());
|
||||||
|
pane.last_rect = rect;
|
||||||
|
if show_pane(ui, id, pane, rect, &self.config, &self.theme, active) {
|
||||||
|
tab.active = id;
|
||||||
|
}
|
||||||
|
});
|
||||||
if let Some(result) = result
|
if let Some(result) = result
|
||||||
&& result.response.contains_pointer()
|
&& result.response.contains_pointer()
|
||||||
&& ctx.input(|i| i.pointer.any_pressed())
|
&& ctx.input(|i| i.pointer.any_pressed())
|
||||||
@@ -472,6 +545,11 @@ impl eframe::App for App {
|
|||||||
pane.error = Some(e.to_string());
|
pane.error = Some(e.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let Some(name) = picked
|
||||||
|
&& let Err(e) = self.set_theme(name, ctx)
|
||||||
|
{
|
||||||
|
self.error = Some(e.to_string());
|
||||||
|
}
|
||||||
if !self.tabs.is_empty()
|
if !self.tabs.is_empty()
|
||||||
&& let Some(action) = action
|
&& let Some(action) = action
|
||||||
&& let Err(e) = self.action(action, ctx)
|
&& let Err(e) = self.action(action, ctx)
|
||||||
@@ -505,20 +583,40 @@ fn grab_keys(ctx: &egui::Context) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Corner rounding shared by a pane's border and its title bar.
|
||||||
|
const CORNER: u8 = theme::CORNER_RADIUS;
|
||||||
|
|
||||||
fn show_pane(
|
fn show_pane(
|
||||||
ui: &mut egui::Ui,
|
ui: &mut egui::Ui,
|
||||||
id: PaneId,
|
id: PaneId,
|
||||||
pane: &mut Pane,
|
pane: &mut Pane,
|
||||||
rect: Rect,
|
rect: Rect,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
|
theme: &Theme,
|
||||||
active: bool,
|
active: bool,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let accent = color(config::rgb(&config.accent).unwrap());
|
let accent = theme::color(theme.accent);
|
||||||
let title_rect = Rect::from_min_size(rect.min, vec2(rect.width(), 25.0_f32.min(rect.height())));
|
let title_rect = Rect::from_min_size(rect.min, vec2(rect.width(), 25.0_f32.min(rect.height())));
|
||||||
|
// The title bar only rounds off the top of the pane, unless the pane is so
|
||||||
|
// short that the bar is all there is of it.
|
||||||
|
let bottom = if title_rect.height() < rect.height() {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
CORNER
|
||||||
|
};
|
||||||
ui.painter().rect_filled(
|
ui.painter().rect_filled(
|
||||||
title_rect,
|
title_rect,
|
||||||
0,
|
CornerRadius {
|
||||||
Color32::from_gray(if active { 43 } else { 31 }),
|
nw: CORNER,
|
||||||
|
ne: CORNER,
|
||||||
|
sw: bottom,
|
||||||
|
se: bottom,
|
||||||
|
},
|
||||||
|
theme::color(if active {
|
||||||
|
theme.chrome_active_bg
|
||||||
|
} else {
|
||||||
|
theme.chrome_bg
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
ui.painter()
|
ui.painter()
|
||||||
.with_clip_rect(title_rect.shrink(3.0).intersect(ui.clip_rect()))
|
.with_clip_rect(title_rect.shrink(3.0).intersect(ui.clip_rect()))
|
||||||
@@ -527,7 +625,11 @@ fn show_pane(
|
|||||||
egui::Align2::LEFT_TOP,
|
egui::Align2::LEFT_TOP,
|
||||||
pane_title(id, pane),
|
pane_title(id, pane),
|
||||||
egui::FontId::proportional(13.0),
|
egui::FontId::proportional(13.0),
|
||||||
if active { accent } else { Color32::GRAY },
|
if active {
|
||||||
|
accent
|
||||||
|
} else {
|
||||||
|
theme::color(theme.chrome_fg)
|
||||||
|
},
|
||||||
);
|
);
|
||||||
// Click-only leaves dragging to the floating window's existing move handler.
|
// Click-only leaves dragging to the floating window's existing move handler.
|
||||||
let header = ui.interact(
|
let header = ui.interact(
|
||||||
@@ -541,19 +643,19 @@ fn show_pane(
|
|||||||
// The pane rectangle is already allocated; a layout scope would grow its parent.
|
// The pane rectangle is already allocated; a layout scope would grow its parent.
|
||||||
let mut content_ui = ui.new_child(egui::UiBuilder::new().id_salt(id).max_rect(content));
|
let mut content_ui = ui.new_child(egui::UiBuilder::new().id_salt(id).max_rect(content));
|
||||||
content_ui.set_clip_rect(content.intersect(ui.clip_rect()));
|
content_ui.set_clip_rect(content.intersect(ui.clip_rect()));
|
||||||
match pane.show(&mut content_ui, content, config, active) {
|
match pane.show(&mut content_ui, content, config, theme, active) {
|
||||||
Ok(clicked) => focused |= clicked,
|
Ok(clicked) => focused |= clicked,
|
||||||
Err(e) => pane.error = Some(e.to_string()),
|
Err(e) => pane.error = Some(e.to_string()),
|
||||||
}
|
}
|
||||||
ui.painter().rect_stroke(
|
ui.painter().rect_stroke(
|
||||||
rect,
|
rect,
|
||||||
0,
|
CORNER,
|
||||||
Stroke::new(
|
Stroke::new(
|
||||||
1.0_f32,
|
theme::BORDER_WIDTH,
|
||||||
if active {
|
if active {
|
||||||
accent
|
accent
|
||||||
} else {
|
} else {
|
||||||
Color32::from_gray(54)
|
theme::color(theme.border)
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
egui::StrokeKind::Inside,
|
egui::StrokeKind::Inside,
|
||||||
@@ -564,7 +666,7 @@ fn show_pane(
|
|||||||
/// Where a floating pane opens, from its place in the tab's float list rather than
|
/// Where a floating pane opens, from its place in the tab's float list rather than
|
||||||
/// its pane id: the first one is centred and every later one steps down and right
|
/// its pane id: the first one is centred and every later one steps down and right
|
||||||
/// from it, so the same slot always lands in the same spot. The cascade wraps
|
/// from it, so the same slot always lands in the same spot. The cascade wraps
|
||||||
/// before it can walk a float off the far edge.
|
/// every six panes, with each new stack shifted slightly to the right.
|
||||||
fn float_placement(
|
fn float_placement(
|
||||||
workspace: Rect,
|
workspace: Rect,
|
||||||
index: usize,
|
index: usize,
|
||||||
@@ -574,8 +676,43 @@ fn float_placement(
|
|||||||
// terminal far more room than it needs; the maximums keep it in hand.
|
// terminal far more room than it needs; the maximums keep it in hand.
|
||||||
let size = (workspace.size() * vec2(config.floating_width, config.floating_height))
|
let size = (workspace.size() * vec2(config.floating_width, config.floating_height))
|
||||||
.min(vec2(config.floating_max_width, config.floating_max_height));
|
.min(vec2(config.floating_max_width, config.floating_max_height));
|
||||||
|
(workspace.center() - size / 2.0 + float_offset(index), size)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn float_offset(index: usize) -> egui::Vec2 {
|
||||||
let step = (index % 6) as f32 * 28.0;
|
let step = (index % 6) as f32 * 28.0;
|
||||||
(workspace.center() - size / 2.0 + vec2(step, step), size)
|
let stack = (index / 6) as f32 * 12.0;
|
||||||
|
vec2(step + stack, step)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Reapply the cascade when a pane changes slots or the workspace resizes.
|
||||||
|
/// Otherwise leave egui's remembered position alone so panes can still be dragged.
|
||||||
|
fn position_float<'a>(
|
||||||
|
ctx: &egui::Context,
|
||||||
|
window: egui::Window<'a>,
|
||||||
|
window_id: egui::Id,
|
||||||
|
index: usize,
|
||||||
|
workspace: Rect,
|
||||||
|
config: &config::Multiplexer,
|
||||||
|
) -> egui::Window<'a> {
|
||||||
|
let (pos, size) = float_placement(workspace, index, config);
|
||||||
|
let window = window.default_pos(pos).default_size(size);
|
||||||
|
let changed = ctx.data_mut(|data| {
|
||||||
|
let key = window_id.with("cascade placement");
|
||||||
|
let placement = (index, workspace);
|
||||||
|
let previous = data.get_temp::<(usize, Rect)>(key);
|
||||||
|
data.insert_temp(key, placement);
|
||||||
|
previous.is_some_and(|previous| previous != placement)
|
||||||
|
});
|
||||||
|
if changed {
|
||||||
|
// Center using the remembered size, including user resizing.
|
||||||
|
let size = egui::AreaState::load(ctx, window_id)
|
||||||
|
.and_then(|state| state.size)
|
||||||
|
.unwrap_or(size);
|
||||||
|
window.current_pos(workspace.center() - size / 2.0 + float_offset(index))
|
||||||
|
} else {
|
||||||
|
window
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pane_title(id: PaneId, pane: &Pane) -> String {
|
fn pane_title(id: PaneId, pane: &Pane) -> String {
|
||||||
@@ -596,9 +733,11 @@ mod tests {
|
|||||||
shell: vec!["/bin/sh".into()],
|
shell: vec!["/bin/sh".into()],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let pane = Pane::new(&config, ctx, None).unwrap();
|
let theme = config.theme().unwrap();
|
||||||
|
let pane = Pane::new(&config, &theme, ctx, None).unwrap();
|
||||||
App {
|
App {
|
||||||
config,
|
config,
|
||||||
|
theme,
|
||||||
config_path: PathBuf::new(),
|
config_path: PathBuf::new(),
|
||||||
panes: BTreeMap::from([(1, pane)]),
|
panes: BTreeMap::from([(1, pane)]),
|
||||||
tabs: vec![Tab::new(1, 1)],
|
tabs: vec![Tab::new(1, 1)],
|
||||||
@@ -634,6 +773,7 @@ mod tests {
|
|||||||
app.panes.get_mut(&1).unwrap(),
|
app.panes.get_mut(&1).unwrap(),
|
||||||
rect,
|
rect,
|
||||||
&app.config,
|
&app.config,
|
||||||
|
&app.theme,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
@@ -649,6 +789,80 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn removing_floats_repositions_survivors_in_cycle_order() {
|
||||||
|
let ctx = egui::Context::default();
|
||||||
|
let config = config::Multiplexer::default();
|
||||||
|
let workspace = Rect::from_min_size(egui::Pos2::ZERO, vec2(1600.0, 1200.0));
|
||||||
|
let mut tab = Tab::new(1, 1);
|
||||||
|
tab.floats = vec![2, 3, 4, 5];
|
||||||
|
tab.floats_visible = true;
|
||||||
|
let render = |tab: &Tab, moved: Option<PaneId>, workspace: Rect| {
|
||||||
|
let mut positions = BTreeMap::new();
|
||||||
|
// Allow egui's initial sizing pass to settle.
|
||||||
|
for _ in 0..3 {
|
||||||
|
let _ = ctx.run(
|
||||||
|
egui::RawInput {
|
||||||
|
screen_rect: Some(workspace),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
|ctx| {
|
||||||
|
for (index, &id) in tab.floats.iter().enumerate() {
|
||||||
|
let window_id = egui::Id::new(("float", tab.id, id));
|
||||||
|
let mut window = egui::Window::new(id.to_string())
|
||||||
|
.id(window_id)
|
||||||
|
.title_bar(false)
|
||||||
|
.frame(egui::Frame::NONE);
|
||||||
|
if moved == Some(id) {
|
||||||
|
window = window.current_pos(egui::pos2(100.0, 100.0));
|
||||||
|
}
|
||||||
|
let response =
|
||||||
|
position_float(ctx, window, window_id, index, workspace, &config)
|
||||||
|
.show(ctx, |ui| {
|
||||||
|
ui.allocate_rect(
|
||||||
|
ui.available_rect_before_wrap(),
|
||||||
|
egui::Sense::hover(),
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
positions.insert(id, response.response.rect.min);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
positions
|
||||||
|
};
|
||||||
|
render(&tab, Some(2), workspace);
|
||||||
|
assert_eq!(render(&tab, None, workspace)[&2], egui::pos2(100.0, 100.0));
|
||||||
|
// Resizing recenters even a dragged pane, using its existing size.
|
||||||
|
let resized = Rect::from_min_size(egui::Pos2::ZERO, vec2(1800.0, 1400.0));
|
||||||
|
let positions = render(&tab, None, resized);
|
||||||
|
for (index, &id) in tab.floats.iter().enumerate() {
|
||||||
|
assert_eq!(positions[&id], float_placement(resized, index, &config).0);
|
||||||
|
}
|
||||||
|
render(&tab, None, workspace);
|
||||||
|
render(&tab, Some(2), workspace);
|
||||||
|
// Remove the middle pane, then the first, then append a new float.
|
||||||
|
for (removed, added) in [(3, None), (2, None), (4, Some(6))] {
|
||||||
|
tab.detach(removed);
|
||||||
|
if let Some(id) = added {
|
||||||
|
tab.floats.push(id);
|
||||||
|
}
|
||||||
|
let positions = render(&tab, None, workspace);
|
||||||
|
tab.active = tab.floats[0];
|
||||||
|
for index in 0..tab.floats.len() {
|
||||||
|
let expected = if tab.active == 2 {
|
||||||
|
egui::pos2(100.0, 100.0)
|
||||||
|
} else {
|
||||||
|
float_placement(workspace, index, &config).0
|
||||||
|
};
|
||||||
|
assert_eq!(positions[&tab.active], expected);
|
||||||
|
tab.cycle(false);
|
||||||
|
}
|
||||||
|
assert_eq!(tab.active, tab.floats[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn floats_open_centered_then_cascade_and_stay_within_the_maximums() {
|
fn floats_open_centered_then_cascade_and_stay_within_the_maximums() {
|
||||||
let config = config::Multiplexer::default();
|
let config = config::Multiplexer::default();
|
||||||
@@ -670,9 +884,19 @@ mod tests {
|
|||||||
second.x > first.x && second.y > first.y,
|
second.x > first.x && second.y > first.y,
|
||||||
"later floats step off it"
|
"later floats step off it"
|
||||||
);
|
);
|
||||||
// Six slots later the cascade is back where it started, so it cannot walk away.
|
// Each group of six restarts the cascade slightly to the right.
|
||||||
assert_eq!(float_placement(workspace, 6, &config).0, first);
|
assert_eq!(
|
||||||
assert_eq!(float_placement(workspace, 7, &config).0, second);
|
float_placement(workspace, 6, &config).0,
|
||||||
|
first + vec2(12.0, 0.0)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
float_placement(workspace, 7, &config).0,
|
||||||
|
second + vec2(12.0, 0.0)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
float_placement(workspace, 12, &config).0,
|
||||||
|
first + vec2(24.0, 0.0)
|
||||||
|
);
|
||||||
|
|
||||||
// A small workspace keeps the fractions instead of the maximums.
|
// A small workspace keeps the fractions instead of the maximums.
|
||||||
let small = Rect::from_min_size(egui::Pos2::ZERO, vec2(800.0, 600.0));
|
let small = Rect::from_min_size(egui::Pos2::ZERO, vec2(800.0, 600.0));
|
||||||
|
|||||||
+82
-9
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::theme::{self, Theme};
|
||||||
use anyhow::{Context, Result, bail, ensure};
|
use anyhow::{Context, Result, bail, ensure};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::{
|
use std::{
|
||||||
@@ -14,12 +15,22 @@ pub struct Config {
|
|||||||
pub working_directory: Option<PathBuf>,
|
pub working_directory: Option<PathBuf>,
|
||||||
pub font_size: f32,
|
pub font_size: f32,
|
||||||
pub font_path: Option<PathBuf>,
|
pub font_path: Option<PathBuf>,
|
||||||
|
pub font_family: Option<String>,
|
||||||
|
pub font_bold_path: Option<PathBuf>,
|
||||||
|
pub font_italic_path: Option<PathBuf>,
|
||||||
|
pub font_bold_italic_path: Option<PathBuf>,
|
||||||
|
pub font_fallbacks: Vec<String>,
|
||||||
pub scrollback: usize,
|
pub scrollback: usize,
|
||||||
|
pub scrollback_editor: Option<String>,
|
||||||
pub window_width: f32,
|
pub window_width: f32,
|
||||||
pub window_height: f32,
|
pub window_height: f32,
|
||||||
pub background: String,
|
pub theme: String,
|
||||||
pub foreground: String,
|
/// Shorthand for the `[colors]` entries of the same name.
|
||||||
pub accent: String,
|
pub background: Option<String>,
|
||||||
|
pub foreground: Option<String>,
|
||||||
|
pub accent: Option<String>,
|
||||||
|
/// Colors overriding the theme, keyed by the names in `theme::FIELDS`.
|
||||||
|
pub colors: BTreeMap<String, String>,
|
||||||
pub kitty: Kitty,
|
pub kitty: Kitty,
|
||||||
pub multiplexer: Multiplexer,
|
pub multiplexer: Multiplexer,
|
||||||
pub keys: BTreeMap<String, Action>,
|
pub keys: BTreeMap<String, Action>,
|
||||||
@@ -67,6 +78,7 @@ pub enum Action {
|
|||||||
ReloadConfig,
|
ReloadConfig,
|
||||||
Copy,
|
Copy,
|
||||||
Paste,
|
Paste,
|
||||||
|
OpenScrollback,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Kitty {
|
impl Default for Kitty {
|
||||||
@@ -99,12 +111,20 @@ impl Default for Config {
|
|||||||
working_directory: None,
|
working_directory: None,
|
||||||
font_size: 16.0,
|
font_size: 16.0,
|
||||||
font_path: None,
|
font_path: None,
|
||||||
|
font_family: None,
|
||||||
|
font_bold_path: None,
|
||||||
|
font_italic_path: None,
|
||||||
|
font_bold_italic_path: None,
|
||||||
|
font_fallbacks: Vec::new(),
|
||||||
scrollback: 10000,
|
scrollback: 10000,
|
||||||
|
scrollback_editor: None,
|
||||||
window_width: 1100.0,
|
window_width: 1100.0,
|
||||||
window_height: 720.0,
|
window_height: 720.0,
|
||||||
background: "#17191c".into(),
|
theme: theme::DEFAULT_NAME.into(),
|
||||||
foreground: "#e2e4e8".into(),
|
background: None,
|
||||||
accent: "#58c4ad".into(),
|
foreground: None,
|
||||||
|
accent: None,
|
||||||
|
colors: BTreeMap::new(),
|
||||||
kitty: Kitty::default(),
|
kitty: Kitty::default(),
|
||||||
multiplexer: Multiplexer::default(),
|
multiplexer: Multiplexer::default(),
|
||||||
keys: [
|
keys: [
|
||||||
@@ -118,6 +138,7 @@ impl Default for Config {
|
|||||||
("Alt+Shift+H", Action::PreviousTab),
|
("Alt+Shift+H", Action::PreviousTab),
|
||||||
("Alt+Shift+L", Action::NextTab),
|
("Alt+Shift+L", Action::NextTab),
|
||||||
("Alt+X", Action::ClosePane),
|
("Alt+X", Action::ClosePane),
|
||||||
|
("Alt+S", Action::OpenScrollback),
|
||||||
("Ctrl+Shift+Z", Action::ZoomPane),
|
("Ctrl+Shift+Z", Action::ZoomPane),
|
||||||
("Ctrl+Shift+R", Action::ReloadConfig),
|
("Ctrl+Shift+R", Action::ReloadConfig),
|
||||||
("Ctrl+Shift+C", Action::Copy),
|
("Ctrl+Shift+C", Action::Copy),
|
||||||
@@ -153,10 +174,30 @@ impl Config {
|
|||||||
|
|
||||||
pub fn parse(text: &str) -> Result<Self> {
|
pub fn parse(text: &str) -> Result<Self> {
|
||||||
let config: Self = toml::from_str(text)?;
|
let config: Self = toml::from_str(text)?;
|
||||||
|
ensure!(
|
||||||
|
config.font_path.is_none() || config.font_family.is_none(),
|
||||||
|
"set either font_family or font_path, not both"
|
||||||
|
);
|
||||||
|
ensure!(
|
||||||
|
config
|
||||||
|
.font_family
|
||||||
|
.iter()
|
||||||
|
.chain(&config.font_fallbacks)
|
||||||
|
.all(|name| !name.trim().is_empty()),
|
||||||
|
"font family names must not be empty"
|
||||||
|
);
|
||||||
ensure!(
|
ensure!(
|
||||||
!config.shell.is_empty() && !config.shell[0].is_empty(),
|
!config.shell.is_empty() && !config.shell[0].is_empty(),
|
||||||
"shell must contain an executable"
|
"shell must contain an executable"
|
||||||
);
|
);
|
||||||
|
if let Some(editor) = &config.scrollback_editor {
|
||||||
|
let command =
|
||||||
|
shell_words::split(editor).context("Invalid scrollback_editor command")?;
|
||||||
|
ensure!(
|
||||||
|
!command.is_empty() && !command[0].is_empty(),
|
||||||
|
"scrollback_editor must contain an executable"
|
||||||
|
);
|
||||||
|
}
|
||||||
ensure!(
|
ensure!(
|
||||||
(8.0..=48.0).contains(&config.font_size),
|
(8.0..=48.0).contains(&config.font_size),
|
||||||
"font_size must be 8..48"
|
"font_size must be 8..48"
|
||||||
@@ -196,14 +237,38 @@ impl Config {
|
|||||||
"floating maximums must be 160..16384 points"
|
"floating maximums must be 160..16384 points"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
for color in [&config.background, &config.foreground, &config.accent] {
|
config.theme()?;
|
||||||
rgb(color)?;
|
|
||||||
}
|
|
||||||
for key in config.keys.keys() {
|
for key in config.keys.keys() {
|
||||||
shortcut(key)?;
|
shortcut(key)?;
|
||||||
}
|
}
|
||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The configured theme with the `[colors]` overrides applied. Validated by
|
||||||
|
/// `parse`, so a config that loaded is a config whose theme resolves.
|
||||||
|
pub fn theme(&self) -> Result<Theme> {
|
||||||
|
let mut theme = theme::find(&self.theme)
|
||||||
|
.with_context(|| format!("unknown theme: {} (try --list-themes)", self.theme))?;
|
||||||
|
let shorthand = [
|
||||||
|
("background", &self.background),
|
||||||
|
("foreground", &self.foreground),
|
||||||
|
("accent", &self.accent),
|
||||||
|
];
|
||||||
|
let named = shorthand
|
||||||
|
.iter()
|
||||||
|
.filter_map(|(name, value)| Some((*name, value.as_ref()?)))
|
||||||
|
.chain(self.colors.iter().map(|(k, v)| (k.as_str(), v)));
|
||||||
|
for (name, value) in named {
|
||||||
|
theme.set(name, packed(value)?)?;
|
||||||
|
}
|
||||||
|
Ok(theme)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A `#RRGGBB` string as the packed integer a theme stores.
|
||||||
|
pub fn packed(text: &str) -> Result<theme::Rgb> {
|
||||||
|
let color = rgb(text)?;
|
||||||
|
Ok((color.r as u32) << 16 | (color.g as u32) << 8 | color.b as u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rgb(text: &str) -> Result<libghostty_vt::style::RgbColor> {
|
pub fn rgb(text: &str) -> Result<libghostty_vt::style::RgbColor> {
|
||||||
@@ -250,7 +315,14 @@ mod tests {
|
|||||||
assert_eq!(example.keys, Config::default().keys);
|
assert_eq!(example.keys, Config::default().keys);
|
||||||
for text in [
|
for text in [
|
||||||
"font_size = nan",
|
"font_size = nan",
|
||||||
|
"font_family = ''",
|
||||||
|
"font_fallbacks = [' ']",
|
||||||
|
"font_family = 'Test'\nfont_path = '/font.ttf'",
|
||||||
"shell = []",
|
"shell = []",
|
||||||
|
"scrollback_editor = ''",
|
||||||
|
"scrollback_editor = ' '",
|
||||||
|
"scrollback_editor = \"''\"",
|
||||||
|
"scrollback_editor = \"'\"",
|
||||||
"background = '#xx0000'",
|
"background = '#xx0000'",
|
||||||
"font_sze = 16",
|
"font_sze = 16",
|
||||||
"[keys]\n'Hyper+Q' = 'close_pane'",
|
"[keys]\n'Hyper+Q' = 'close_pane'",
|
||||||
@@ -274,6 +346,7 @@ mod tests {
|
|||||||
("Alt+Shift+H", Action::PreviousTab),
|
("Alt+Shift+H", Action::PreviousTab),
|
||||||
("Alt+Shift+L", Action::NextTab),
|
("Alt+Shift+L", Action::NextTab),
|
||||||
("Alt+X", Action::ClosePane),
|
("Alt+X", Action::ClosePane),
|
||||||
|
("Alt+S", Action::OpenScrollback),
|
||||||
] {
|
] {
|
||||||
assert_eq!(config.keys.get(binding), Some(&action));
|
assert_eq!(config.keys.get(binding), Some(&action));
|
||||||
assert!(shortcut(binding).unwrap().modifiers.alt);
|
assert!(shortcut(binding).unwrap().modifiers.alt);
|
||||||
|
|||||||
+268
@@ -0,0 +1,268 @@
|
|||||||
|
use crate::config::Config;
|
||||||
|
use anyhow::{Context, Result, ensure};
|
||||||
|
use egui::{FontData, FontDefinitions, FontFamily};
|
||||||
|
use fontdb::{Database, Family, ID, Query, Style, Weight};
|
||||||
|
use std::{collections::HashMap, path::Path};
|
||||||
|
|
||||||
|
pub fn family(bold: bool, italic: bool) -> FontFamily {
|
||||||
|
match (bold, italic) {
|
||||||
|
(false, false) => FontFamily::Monospace,
|
||||||
|
(true, false) => FontFamily::Name("terminal-bold".into()),
|
||||||
|
(false, true) => FontFamily::Name("terminal-italic".into()),
|
||||||
|
(true, true) => FontFamily::Name("terminal-bold-italic".into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn query(db: &Database, name: &str, bold: bool, italic: bool) -> Option<ID> {
|
||||||
|
db.query(&Query {
|
||||||
|
families: &[Family::Name(name)],
|
||||||
|
weight: if bold { Weight::BOLD } else { Weight::NORMAL },
|
||||||
|
style: if italic { Style::Italic } else { Style::Normal },
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_file(db: &mut Database, path: &Path) -> Result<ID> {
|
||||||
|
let bytes =
|
||||||
|
std::fs::read(path).with_context(|| format!("Cannot read font {}", path.display()))?;
|
||||||
|
db.load_font_source(fontdb::Source::Binary(std::sync::Arc::new(bytes)))
|
||||||
|
.first()
|
||||||
|
.copied()
|
||||||
|
.with_context(|| format!("No font faces in {}", path.display()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn register(
|
||||||
|
db: &Database,
|
||||||
|
fonts: &mut FontDefinitions,
|
||||||
|
loaded: &mut HashMap<ID, String>,
|
||||||
|
id: ID,
|
||||||
|
) -> Result<String> {
|
||||||
|
if let Some(name) = loaded.get(&id) {
|
||||||
|
return Ok(name.clone());
|
||||||
|
}
|
||||||
|
let face = db.face(id).context("Font face disappeared")?;
|
||||||
|
let data = db
|
||||||
|
.with_face_data(id, |bytes, index| {
|
||||||
|
// Validate with the renderer's parser too, so a bad font becomes a
|
||||||
|
// reload error rather than a panic inside egui on the next frame.
|
||||||
|
ab_glyph::FontRef::try_from_slice_and_index(bytes, index)
|
||||||
|
.with_context(|| format!("Unsupported font: {}", face.post_script_name))?;
|
||||||
|
let mut data = FontData::from_owned(bytes.to_vec());
|
||||||
|
data.index = index;
|
||||||
|
Ok::<_, anyhow::Error>(data)
|
||||||
|
})
|
||||||
|
.context("Cannot read font face data")??;
|
||||||
|
let name = format!("terminal-face-{}", loaded.len());
|
||||||
|
fonts.font_data.insert(name.clone(), data.into());
|
||||||
|
loaded.insert(id, name.clone());
|
||||||
|
Ok(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load(config: &Config) -> Result<FontDefinitions> {
|
||||||
|
let mut db = Database::new();
|
||||||
|
// Preserve the built-in default when no family is configured. System
|
||||||
|
// fonts also supply optional Nerd Font symbols and named fallbacks.
|
||||||
|
db.load_system_fonts();
|
||||||
|
load_from_database(config, db)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_from_database(config: &Config, mut db: Database) -> Result<FontDefinitions> {
|
||||||
|
let mut primary = config.font_family.clone();
|
||||||
|
let regular = if let Some(path) = &config.font_path {
|
||||||
|
let id = load_file(&mut db, path)?;
|
||||||
|
primary = db
|
||||||
|
.face(id)
|
||||||
|
.and_then(|face| face.families.first())
|
||||||
|
.map(|f| f.0.clone());
|
||||||
|
// Inspect sibling metadata, not filename suffixes: foundries use
|
||||||
|
// different style names, and collections contain multiple faces.
|
||||||
|
let parent = path
|
||||||
|
.parent()
|
||||||
|
.filter(|p| !p.as_os_str().is_empty())
|
||||||
|
.unwrap_or(Path::new("."));
|
||||||
|
for entry in std::fs::read_dir(parent)?.flatten() {
|
||||||
|
let path = entry.path();
|
||||||
|
if path.extension().and_then(|e| e.to_str()).is_some_and(|e| {
|
||||||
|
["ttf", "otf", "ttc", "otc"]
|
||||||
|
.iter()
|
||||||
|
.any(|ext| e.eq_ignore_ascii_case(ext))
|
||||||
|
}) {
|
||||||
|
let _ = db.load_font_file(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(id)
|
||||||
|
} else if let Some(name) = &primary {
|
||||||
|
Some(
|
||||||
|
query(&db, name, false, false)
|
||||||
|
.with_context(|| format!("Font family not found: {name}"))?,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
for name in &config.font_fallbacks {
|
||||||
|
ensure!(
|
||||||
|
query(&db, name, false, false).is_some(),
|
||||||
|
"Fallback font family not found: {name}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let mut fallbacks = config.font_fallbacks.clone();
|
||||||
|
for name in ["Symbols Nerd Font Mono", "Symbols Nerd Font"] {
|
||||||
|
if query(&db, name, false, false).is_some() && !fallbacks.iter().any(|f| f == name) {
|
||||||
|
fallbacks.push(name.into());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut fonts = FontDefinitions::default();
|
||||||
|
let builtin = fonts.families[&FontFamily::Monospace].clone();
|
||||||
|
let mut loaded = HashMap::new();
|
||||||
|
for (bold, italic, path) in [
|
||||||
|
(false, false, None),
|
||||||
|
(true, false, config.font_bold_path.as_deref()),
|
||||||
|
(false, true, config.font_italic_path.as_deref()),
|
||||||
|
(true, true, config.font_bold_italic_path.as_deref()),
|
||||||
|
] {
|
||||||
|
let id = if let Some(path) = path {
|
||||||
|
Some(load_file(&mut db, path)?)
|
||||||
|
} else if !bold && !italic {
|
||||||
|
regular
|
||||||
|
} else {
|
||||||
|
primary
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|name| query(&db, name, bold, italic))
|
||||||
|
.or(regular)
|
||||||
|
};
|
||||||
|
let mut chain = Vec::new();
|
||||||
|
if let Some(id) = id {
|
||||||
|
chain.push(register(&db, &mut fonts, &mut loaded, id)?);
|
||||||
|
} else {
|
||||||
|
// A symbols-only fallback must not set the terminal's line metrics.
|
||||||
|
chain.push(builtin[0].clone());
|
||||||
|
}
|
||||||
|
// A style face may lack symbols present in its regular face.
|
||||||
|
if let Some(id) = regular {
|
||||||
|
let name = register(&db, &mut fonts, &mut loaded, id)?;
|
||||||
|
if !chain.contains(&name) {
|
||||||
|
chain.push(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for name in &fallbacks {
|
||||||
|
for id in [
|
||||||
|
query(&db, name, bold, italic),
|
||||||
|
query(&db, name, false, false),
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.flatten()
|
||||||
|
{
|
||||||
|
let name = register(&db, &mut fonts, &mut loaded, id)?;
|
||||||
|
if !chain.contains(&name) {
|
||||||
|
chain.push(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
chain.extend(builtin.iter().cloned());
|
||||||
|
fonts.families.insert(family(bold, italic), chain);
|
||||||
|
}
|
||||||
|
Ok(fonts)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn database() -> Database {
|
||||||
|
let mut db = Database::new();
|
||||||
|
let fonts = FontDefinitions::default();
|
||||||
|
let data = &fonts.font_data[&fonts.families[&FontFamily::Monospace][0]];
|
||||||
|
db.load_font_data(data.font.to_vec());
|
||||||
|
let template = db.faces().next().unwrap().clone();
|
||||||
|
for (bold, italic) in [(false, false), (true, false), (false, true), (true, true)] {
|
||||||
|
let mut face = template.clone();
|
||||||
|
face.families[0].0 = "Test Family".into();
|
||||||
|
face.weight = if bold { Weight::BOLD } else { Weight::NORMAL };
|
||||||
|
face.style = if italic { Style::Italic } else { Style::Normal };
|
||||||
|
db.push_face_info(face);
|
||||||
|
}
|
||||||
|
db
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn matches_styles_and_keeps_regular_as_fallback() {
|
||||||
|
let config = Config {
|
||||||
|
font_family: Some("Test Family".into()),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let db = database();
|
||||||
|
let mut ids = std::collections::HashSet::new();
|
||||||
|
for (bold, italic) in [(false, false), (true, false), (false, true), (true, true)] {
|
||||||
|
let id = query(&db, "Test Family", bold, italic).unwrap();
|
||||||
|
assert!(ids.insert(id), "styles must select distinct faces");
|
||||||
|
let face = db.face(id).unwrap();
|
||||||
|
assert_eq!(face.weight == Weight::BOLD, bold);
|
||||||
|
assert_eq!(face.style == Style::Italic, italic);
|
||||||
|
}
|
||||||
|
let fonts = load_from_database(&config, db).unwrap();
|
||||||
|
let regular = &fonts.families[&family(false, false)][0];
|
||||||
|
for (bold, italic) in [(true, false), (false, true), (true, true)] {
|
||||||
|
let chain = &fonts.families[&family(bold, italic)];
|
||||||
|
assert_ne!(&chain[0], regular);
|
||||||
|
assert_eq!(&chain[1], regular);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rejects_missing_families_and_accepts_regular_only_fallback() {
|
||||||
|
let mut config = Config {
|
||||||
|
font_family: Some("Not Installed".into()),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
assert!(load_from_database(&config, database()).is_err());
|
||||||
|
config.font_family = None;
|
||||||
|
config.font_fallbacks = vec!["Not Installed".into()];
|
||||||
|
assert!(load_from_database(&config, database()).is_err());
|
||||||
|
let db = database();
|
||||||
|
let name = db.faces().next().unwrap().families[0].0.clone();
|
||||||
|
config.font_fallbacks = vec![name];
|
||||||
|
let fonts = load_from_database(&config, db).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
fonts.families[&family(false, false)],
|
||||||
|
fonts.families[&family(true, true)]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore = "requires SLERM_TEST_FONT pointing to a Nerd Font regular face with sibling styles"]
|
||||||
|
fn installed_nerd_font_family_and_sibling_styles() {
|
||||||
|
use ab_glyph::Font;
|
||||||
|
let path = std::env::var_os("SLERM_TEST_FONT").expect("set SLERM_TEST_FONT");
|
||||||
|
let config = Config {
|
||||||
|
font_path: Some(path.into()),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let fonts = load(&config).unwrap();
|
||||||
|
let mut faces = std::collections::HashSet::new();
|
||||||
|
for (bold, italic) in [(false, false), (true, false), (false, true), (true, true)] {
|
||||||
|
let name = &fonts.families[&family(bold, italic)][0];
|
||||||
|
assert!(faces.insert(name.clone()));
|
||||||
|
let data = &fonts.font_data[name];
|
||||||
|
let face = ab_glyph::FontRef::try_from_slice_and_index(&data.font, data.index).unwrap();
|
||||||
|
for c in ['M', '\u{f121}', '\u{e0a0}', '\u{f0001}'] {
|
||||||
|
assert_ne!(face.glyph_id(c).0, 0, "missing {c:?} in {name}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut db = Database::new();
|
||||||
|
let id = load_file(&mut db, config.font_path.as_ref().unwrap()).unwrap();
|
||||||
|
let name = db.face(id).unwrap().families[0].0.clone();
|
||||||
|
eprintln!("Verified installed family: {name}");
|
||||||
|
let named = load(&Config {
|
||||||
|
font_family: Some(name),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
for (bold, italic) in [(false, false), (true, false), (false, true), (true, true)] {
|
||||||
|
let a = &fonts.font_data[&fonts.families[&family(bold, italic)][0]];
|
||||||
|
let b = &named.font_data[&named.families[&family(bold, italic)][0]];
|
||||||
|
assert_eq!(a.font, b.font);
|
||||||
|
assert_eq!(a.index, b.index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+21
-2
@@ -1,6 +1,25 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use libghostty_vt::{Terminal, key};
|
use libghostty_vt::{Terminal, key};
|
||||||
|
|
||||||
|
/// Avoid libghostty-vt 0.2.1's encode_to_vec capacity calculation, which can
|
||||||
|
/// reserve too little when the destination already has some spare capacity.
|
||||||
|
pub fn append_encoded(
|
||||||
|
out: &mut Vec<u8>,
|
||||||
|
mut encode: impl FnMut(&mut [u8]) -> libghostty_vt::error::Result<usize>,
|
||||||
|
) -> Result<()> {
|
||||||
|
let mut buffer = [0; 128];
|
||||||
|
match encode(&mut buffer) {
|
||||||
|
Ok(written) => out.extend_from_slice(&buffer[..written]),
|
||||||
|
Err(libghostty_vt::Error::OutOfSpace { required }) => {
|
||||||
|
let mut buffer = vec![0; required];
|
||||||
|
let written = encode(&mut buffer)?;
|
||||||
|
out.extend_from_slice(&buffer[..written]);
|
||||||
|
}
|
||||||
|
Err(error) => return Err(error.into()),
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn mods(m: egui::Modifiers) -> key::Mods {
|
pub fn mods(m: egui::Modifiers) -> key::Mods {
|
||||||
let mut out = key::Mods::empty();
|
let mut out = key::Mods::empty();
|
||||||
if m.ctrl {
|
if m.ctrl {
|
||||||
@@ -71,7 +90,7 @@ pub fn encode(terminal: &Terminal<'_, '_>, events: &[egui::Event]) -> Result<Vec
|
|||||||
})
|
})
|
||||||
.set_unshifted_codepoint(ucp)
|
.set_unshifted_codepoint(ucp)
|
||||||
.set_utf8(text);
|
.set_utf8(text);
|
||||||
encoder.encode_to_vec(&event, &mut out)?;
|
append_encoded(&mut out, |buffer| encoder.encode(&event, buffer))?;
|
||||||
}
|
}
|
||||||
egui::Event::Text(text) if !used_text.contains(&index) => {
|
egui::Event::Text(text) if !used_text.contains(&index) => {
|
||||||
event
|
event
|
||||||
@@ -81,7 +100,7 @@ pub fn encode(terminal: &Terminal<'_, '_>, events: &[egui::Event]) -> Result<Vec
|
|||||||
.set_consumed_mods(key::Mods::empty())
|
.set_consumed_mods(key::Mods::empty())
|
||||||
.set_unshifted_codepoint('\0')
|
.set_unshifted_codepoint('\0')
|
||||||
.set_utf8(Some(text.as_str()));
|
.set_utf8(Some(text.as_str()));
|
||||||
encoder.encode_to_vec(&event, &mut out)?;
|
append_encoded(&mut out, |buffer| encoder.encode(&event, buffer))?;
|
||||||
}
|
}
|
||||||
egui::Event::Ime(egui::ImeEvent::Commit(text)) => {
|
egui::Event::Ime(egui::ImeEvent::Commit(text)) => {
|
||||||
out.extend_from_slice(text.as_bytes())
|
out.extend_from_slice(text.as_bytes())
|
||||||
|
|||||||
+146
-7
@@ -152,6 +152,8 @@ pub struct Tab {
|
|||||||
pub floats: Vec<PaneId>,
|
pub floats: Vec<PaneId>,
|
||||||
pub active: PaneId,
|
pub active: PaneId,
|
||||||
pub floats_visible: bool,
|
pub floats_visible: bool,
|
||||||
|
// Remember both focus and zoom while floating panes are hidden.
|
||||||
|
last_active_float: Option<(PaneId, bool)>,
|
||||||
pub zoomed: bool,
|
pub zoomed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,6 +165,7 @@ impl Tab {
|
|||||||
floats: vec![],
|
floats: vec![],
|
||||||
active: pane,
|
active: pane,
|
||||||
floats_visible: false,
|
floats_visible: false,
|
||||||
|
last_active_float: None,
|
||||||
zoomed: false,
|
zoomed: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,6 +180,9 @@ impl Tab {
|
|||||||
pub fn detach(&mut self, id: PaneId) {
|
pub fn detach(&mut self, id: PaneId) {
|
||||||
self.root = self.root.take().and_then(|r| r.remove(id));
|
self.root = self.root.take().and_then(|r| r.remove(id));
|
||||||
self.floats.retain(|p| *p != id);
|
self.floats.retain(|p| *p != id);
|
||||||
|
if self.last_active_float.is_some_and(|(pane, _)| pane == id) {
|
||||||
|
self.last_active_float = None;
|
||||||
|
}
|
||||||
if self.floats.is_empty() {
|
if self.floats.is_empty() {
|
||||||
self.floats_visible = false;
|
self.floats_visible = false;
|
||||||
}
|
}
|
||||||
@@ -199,19 +205,32 @@ impl Tab {
|
|||||||
|
|
||||||
pub fn toggle_floats(&mut self) {
|
pub fn toggle_floats(&mut self) {
|
||||||
self.floats_visible = !self.floats_visible;
|
self.floats_visible = !self.floats_visible;
|
||||||
self.zoomed = false;
|
let was_zoomed = std::mem::take(&mut self.zoomed);
|
||||||
if self.floats_visible {
|
if self.floats_visible {
|
||||||
if let Some(id) = self.floats.last() {
|
if let Some((id, zoomed)) = self
|
||||||
self.active = *id;
|
.last_active_float
|
||||||
|
.filter(|(id, _)| self.floats.contains(id))
|
||||||
|
.or_else(|| self.floats.last().map(|id| (*id, false)))
|
||||||
|
{
|
||||||
|
self.active = id;
|
||||||
|
self.zoomed = zoomed;
|
||||||
|
}
|
||||||
|
} else if self.floats.contains(&self.active) {
|
||||||
|
self.last_active_float = Some((self.active, was_zoomed));
|
||||||
|
if let Some(root) = &self.root {
|
||||||
|
self.active = root.first();
|
||||||
}
|
}
|
||||||
} else if self.floats.contains(&self.active)
|
|
||||||
&& let Some(root) = &self.root
|
|
||||||
{
|
|
||||||
self.active = root.first();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn focus_direction(&mut self, direction: Direction, rects: &[(PaneId, Rect)]) {
|
pub fn focus_direction(&mut self, direction: Direction, rects: &[(PaneId, Rect)]) {
|
||||||
|
if self.floats_visible
|
||||||
|
&& !self.floats.is_empty()
|
||||||
|
&& matches!(direction, Direction::Down | Direction::Up)
|
||||||
|
{
|
||||||
|
self.cycle(matches!(direction, Direction::Up));
|
||||||
|
return;
|
||||||
|
}
|
||||||
let Some((_, source)) = rects
|
let Some((_, source)) = rects
|
||||||
.iter()
|
.iter()
|
||||||
.find(|(id, _)| *id == self.active && self.is_visible(*id))
|
.find(|(id, _)| *id == self.active && self.is_visible(*id))
|
||||||
@@ -322,6 +341,100 @@ mod tests {
|
|||||||
assert!(tab.is_visible(2));
|
assert!(tab.is_visible(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn showing_floats_restores_the_pane_active_when_hidden() {
|
||||||
|
let mut tab = Tab::new(1, 1);
|
||||||
|
tab.root.as_mut().unwrap().split(1, 2, Axis::Horizontal);
|
||||||
|
tab.floats = vec![3, 4, 5];
|
||||||
|
tab.toggle_floats();
|
||||||
|
assert_eq!(tab.active, 5);
|
||||||
|
tab.cycle(true);
|
||||||
|
assert_eq!(tab.active, 4);
|
||||||
|
|
||||||
|
tab.toggle_floats();
|
||||||
|
assert_eq!(tab.active, 1);
|
||||||
|
tab.cycle(false);
|
||||||
|
assert_eq!(tab.active, 2);
|
||||||
|
tab.toggle_floats();
|
||||||
|
assert_eq!(tab.active, 4);
|
||||||
|
|
||||||
|
tab.cycle(true);
|
||||||
|
tab.toggle_floats();
|
||||||
|
tab.toggle_floats();
|
||||||
|
assert_eq!(tab.active, 3);
|
||||||
|
|
||||||
|
tab.root = None;
|
||||||
|
tab.toggle_floats();
|
||||||
|
tab.toggle_floats();
|
||||||
|
assert_eq!(tab.active, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn showing_floats_falls_back_when_remembered_pane_is_detached() {
|
||||||
|
for dock in [false, true] {
|
||||||
|
let mut tab = Tab::new(1, 1);
|
||||||
|
tab.floats = vec![2, 3];
|
||||||
|
tab.floats_visible = true;
|
||||||
|
tab.active = 2;
|
||||||
|
tab.zoomed = true;
|
||||||
|
tab.toggle_floats();
|
||||||
|
tab.detach(2);
|
||||||
|
if dock {
|
||||||
|
tab.root.as_mut().unwrap().split(1, 2, Axis::Horizontal);
|
||||||
|
}
|
||||||
|
tab.toggle_floats();
|
||||||
|
assert_eq!(tab.active, 3);
|
||||||
|
assert!(!tab.zoomed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn showing_floats_restores_zoom_without_zooming_tiles() {
|
||||||
|
let mut tab = Tab::new(1, 1);
|
||||||
|
tab.root.as_mut().unwrap().split(1, 2, Axis::Horizontal);
|
||||||
|
tab.floats = vec![3, 4];
|
||||||
|
tab.floats_visible = true;
|
||||||
|
tab.active = 3;
|
||||||
|
tab.zoomed = true;
|
||||||
|
|
||||||
|
for _ in 0..2 {
|
||||||
|
tab.toggle_floats();
|
||||||
|
assert_eq!(tab.active, 1);
|
||||||
|
assert!(!tab.zoomed);
|
||||||
|
assert!(!tab.is_visible(3));
|
||||||
|
tab.cycle(false);
|
||||||
|
assert_eq!(tab.active, 2);
|
||||||
|
tab.toggle_floats();
|
||||||
|
assert_eq!(tab.active, 3);
|
||||||
|
assert!(tab.zoomed);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unzooming the float replaces its remembered zoom, even if tiles zoom.
|
||||||
|
tab.zoomed = false;
|
||||||
|
tab.toggle_floats();
|
||||||
|
tab.zoomed = true;
|
||||||
|
tab.toggle_floats();
|
||||||
|
assert_eq!(tab.active, 3);
|
||||||
|
assert!(!tab.zoomed);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn floating_zoom_survives_hiding_without_tiles() {
|
||||||
|
let mut tab = Tab::new(1, 1);
|
||||||
|
tab.root = None;
|
||||||
|
tab.floats = vec![1];
|
||||||
|
tab.floats_visible = true;
|
||||||
|
tab.zoomed = true;
|
||||||
|
|
||||||
|
tab.toggle_floats();
|
||||||
|
assert!(!tab.is_visible(1));
|
||||||
|
assert!(!tab.zoomed);
|
||||||
|
tab.toggle_floats();
|
||||||
|
assert_eq!(tab.active, 1);
|
||||||
|
assert!(tab.is_visible(1));
|
||||||
|
assert!(tab.zoomed);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn directional_focus_uses_geometry_and_ignores_hidden_or_foreign_panes() {
|
fn directional_focus_uses_geometry_and_ignores_hidden_or_foreign_panes() {
|
||||||
let mut tab = Tab::new(1, 1);
|
let mut tab = Tab::new(1, 1);
|
||||||
@@ -375,6 +488,30 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn up_and_down_cycle_visible_floats_without_geometry() {
|
||||||
|
let mut tab = Tab::new(1, 1);
|
||||||
|
tab.floats = vec![2, 3, 4];
|
||||||
|
tab.floats_visible = true;
|
||||||
|
for (direction, expected) in [
|
||||||
|
(Direction::Down, 2),
|
||||||
|
(Direction::Down, 3),
|
||||||
|
(Direction::Down, 4),
|
||||||
|
(Direction::Down, 2),
|
||||||
|
(Direction::Up, 4),
|
||||||
|
(Direction::Up, 3),
|
||||||
|
(Direction::Up, 2),
|
||||||
|
] {
|
||||||
|
tab.focus_direction(direction, &[]);
|
||||||
|
assert_eq!(tab.active, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
tab.toggle_floats();
|
||||||
|
assert_eq!(tab.active, 1);
|
||||||
|
tab.toggle_floats();
|
||||||
|
assert_eq!(tab.active, 2);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn visible_floats_constrain_directional_and_cyclic_navigation() {
|
fn visible_floats_constrain_directional_and_cyclic_navigation() {
|
||||||
let mut tab = Tab::new(1, 1);
|
let mut tab = Tab::new(1, 1);
|
||||||
@@ -395,6 +532,8 @@ mod tests {
|
|||||||
(Direction::Right, 4),
|
(Direction::Right, 4),
|
||||||
(Direction::Down, 5),
|
(Direction::Down, 5),
|
||||||
(Direction::Left, 6),
|
(Direction::Left, 6),
|
||||||
|
(Direction::Up, 5),
|
||||||
|
(Direction::Up, 4),
|
||||||
(Direction::Up, 3),
|
(Direction::Up, 3),
|
||||||
] {
|
] {
|
||||||
tab.focus_direction(direction, &rects);
|
tab.focus_direction(direction, &rects);
|
||||||
|
|||||||
+24
-6
@@ -1,5 +1,6 @@
|
|||||||
mod app;
|
mod app;
|
||||||
mod config;
|
mod config;
|
||||||
|
mod fonts;
|
||||||
mod input;
|
mod input;
|
||||||
mod layout;
|
mod layout;
|
||||||
mod pane;
|
mod pane;
|
||||||
@@ -7,6 +8,8 @@ mod pty;
|
|||||||
mod render;
|
mod render;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
mod theme;
|
||||||
|
mod themes;
|
||||||
|
|
||||||
use anyhow::{Context, Result, bail};
|
use anyhow::{Context, Result, bail};
|
||||||
|
|
||||||
@@ -20,13 +23,19 @@ fn main() -> Result<()> {
|
|||||||
"--config" => path = args.next().context("--config needs a path")?.into(),
|
"--config" => path = args.next().context("--config needs a path")?.into(),
|
||||||
"--check-config" => check = true,
|
"--check-config" => check = true,
|
||||||
"--init-config" => init = true,
|
"--init-config" => init = true,
|
||||||
|
"--list-themes" => {
|
||||||
|
for name in theme::names() {
|
||||||
|
println!("{name}");
|
||||||
|
}
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
"--version" => {
|
"--version" => {
|
||||||
println!("slerm {}", env!("CARGO_PKG_VERSION"));
|
println!("slerm {}", env!("CARGO_PKG_VERSION"));
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
"--help" | "-h" => {
|
"--help" | "-h" => {
|
||||||
println!(
|
println!(
|
||||||
"slerm [--config PATH] [--check-config | --init-config]\n\nDefault config: {}",
|
"slerm [--config PATH] [--check-config | --init-config | --list-themes]\n\nDefault config: {}",
|
||||||
path.display()
|
path.display()
|
||||||
);
|
);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@@ -67,12 +76,21 @@ fn main() -> Result<()> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
libghostty_vt::kitty::graphics::set_png_decoder(Some(Box::new(render::PngDecoder)))?;
|
libghostty_vt::kitty::graphics::set_png_decoder(Some(Box::new(render::PngDecoder)))?;
|
||||||
|
let mut viewport = egui::ViewportBuilder::default()
|
||||||
|
.with_title("slerm")
|
||||||
|
.with_inner_size([config.window_width, config.window_height])
|
||||||
|
.with_min_inner_size([320.0, 200.0])
|
||||||
|
.with_app_id("slerm");
|
||||||
|
if cfg!(target_os = "macos") {
|
||||||
|
// Hide the titlebar and draw under it; the traffic lights stay on top of
|
||||||
|
// the tab bar, which reserves room for them (see app::TITLEBAR_INSET).
|
||||||
|
viewport = viewport
|
||||||
|
.with_fullsize_content_view(true)
|
||||||
|
.with_titlebar_shown(false)
|
||||||
|
.with_title_shown(false);
|
||||||
|
}
|
||||||
let options = eframe::NativeOptions {
|
let options = eframe::NativeOptions {
|
||||||
viewport: egui::ViewportBuilder::default()
|
viewport,
|
||||||
.with_title("slerm")
|
|
||||||
.with_inner_size([config.window_width, config.window_height])
|
|
||||||
.with_min_inner_size([320.0, 200.0])
|
|
||||||
.with_app_id("slerm"),
|
|
||||||
renderer: eframe::Renderer::Wgpu,
|
renderer: eframe::Renderer::Wgpu,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|||||||
+332
-30
@@ -1,10 +1,11 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
config::{Config, rgb},
|
config::Config,
|
||||||
input,
|
input,
|
||||||
pty::Pty,
|
pty::Pty,
|
||||||
render::{Renderer, cell_size},
|
render::{Grid, Renderer, cell_size},
|
||||||
|
theme::{self, Theme},
|
||||||
};
|
};
|
||||||
use anyhow::{Result, ensure};
|
use anyhow::{Context, Result, ensure};
|
||||||
use egui::{FontId, Rect, Sense, vec2};
|
use egui::{FontId, Rect, Sense, vec2};
|
||||||
use libghostty_vt::{
|
use libghostty_vt::{
|
||||||
Terminal, TerminalOptions, mouse,
|
Terminal, TerminalOptions, mouse,
|
||||||
@@ -30,8 +31,193 @@ pub struct Pane {
|
|||||||
callback_error: Rc<RefCell<Option<String>>>,
|
callback_error: Rc<RefCell<Option<String>>>,
|
||||||
mouse_encoder: mouse::Encoder<'static>,
|
mouse_encoder: mouse::Encoder<'static>,
|
||||||
mouse_event: mouse::Event<'static>,
|
mouse_event: mouse::Event<'static>,
|
||||||
|
scrollback_scroll: ScrollAccumulator,
|
||||||
|
mouse_scroll: ScrollAccumulator,
|
||||||
selection_start: Option<PointCoordinate>,
|
selection_start: Option<PointCoordinate>,
|
||||||
focused: bool,
|
focused: bool,
|
||||||
|
saved_session: Option<(Box<Pane>, ScrollbackFile)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ScrollbackFile(PathBuf);
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
struct ScrollAccumulator(f32);
|
||||||
|
|
||||||
|
impl ScrollAccumulator {
|
||||||
|
fn rows(&mut self, delta: f32) -> isize {
|
||||||
|
self.0 += delta;
|
||||||
|
let rows = self.0.trunc();
|
||||||
|
self.0 -= rows;
|
||||||
|
rows as isize
|
||||||
|
}
|
||||||
|
|
||||||
|
fn wheel(&mut self, unit: egui::MouseWheelUnit, delta: f32, cell: f32, page: u16) -> isize {
|
||||||
|
self.rows(match unit {
|
||||||
|
egui::MouseWheelUnit::Point => delta / cell,
|
||||||
|
egui::MouseWheelUnit::Line => delta * 3.0,
|
||||||
|
egui::MouseWheelUnit::Page => delta * f32::from(page),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ScrollbackFile {
|
||||||
|
fn new(bytes: &[u8]) -> Result<Self> {
|
||||||
|
use std::{
|
||||||
|
fs::OpenOptions,
|
||||||
|
io::Write,
|
||||||
|
os::unix::fs::OpenOptionsExt,
|
||||||
|
sync::atomic::{AtomicU64, Ordering},
|
||||||
|
};
|
||||||
|
static NEXT: AtomicU64 = AtomicU64::new(0);
|
||||||
|
loop {
|
||||||
|
let path = std::env::temp_dir().join(format!(
|
||||||
|
"slerm-scrollback-{}-{}.txt",
|
||||||
|
std::process::id(),
|
||||||
|
NEXT.fetch_add(1, Ordering::Relaxed)
|
||||||
|
));
|
||||||
|
match OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.create_new(true)
|
||||||
|
.mode(0o600)
|
||||||
|
.open(&path)
|
||||||
|
{
|
||||||
|
Ok(mut file) => {
|
||||||
|
let temporary = Self(path);
|
||||||
|
file.write_all(bytes)?;
|
||||||
|
return Ok(temporary);
|
||||||
|
}
|
||||||
|
Err(error) if error.kind() == std::io::ErrorKind::AlreadyExists => continue,
|
||||||
|
Err(error) => return Err(error.into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod scroll_tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn precise_scrolling_preserves_distance_across_frames() {
|
||||||
|
let mut scroll = ScrollAccumulator::default();
|
||||||
|
// Sub-pixel events from a slow gesture must eventually move a row.
|
||||||
|
let rows: isize = (0..128).map(|_| scroll.rows(0.25 / 16.0)).sum();
|
||||||
|
assert_eq!(rows, 2);
|
||||||
|
assert_eq!(scroll.0, 0.0);
|
||||||
|
|
||||||
|
let mut batched = ScrollAccumulator::default();
|
||||||
|
assert_eq!(batched.rows(32.0 / 16.0), rows);
|
||||||
|
assert_eq!(scroll.rows(1.75), 1);
|
||||||
|
assert_eq!(scroll.rows(0.25), 1);
|
||||||
|
assert_eq!(scroll.rows(-0.75), 0);
|
||||||
|
assert_eq!(scroll.rows(-0.25), -1);
|
||||||
|
assert_eq!(scroll.rows(0.75), 0);
|
||||||
|
assert_eq!(scroll.rows(-0.75), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn mouse_tracking_respects_precise_distance_and_wheel_units() {
|
||||||
|
use egui::MouseWheelUnit::{Line, Page, Point};
|
||||||
|
let mut scroll = ScrollAccumulator::default();
|
||||||
|
assert_eq!(scroll.wheel(Point, 0.0, 16.0, 24), 0);
|
||||||
|
assert_eq!(scroll.wheel(Point, 4.0, 16.0, 24), 0);
|
||||||
|
assert_eq!(scroll.wheel(Point, 12.0, 16.0, 24), 1);
|
||||||
|
assert_eq!(scroll.wheel(Point, -32.0, 16.0, 24), -2);
|
||||||
|
assert_eq!(scroll.wheel(Line, 1.0, 16.0, 24), 3);
|
||||||
|
assert_eq!(scroll.wheel(Page, -1.0, 16.0, 24), -24);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod scrollback_tests {
|
||||||
|
use super::*;
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn editor_receives_history_and_restores_original_session_on_exit() {
|
||||||
|
let ctx = egui::Context::default();
|
||||||
|
let config = Config {
|
||||||
|
shell: vec![
|
||||||
|
"/bin/sh".into(),
|
||||||
|
"-c".into(),
|
||||||
|
"read answer; printf ORIGINAL_ALIVE; read answer".into(),
|
||||||
|
],
|
||||||
|
scrollback_editor: Config::parse(
|
||||||
|
"scrollback_editor = \"/bin/sh -c 'printf EDITOR_READY; read answer' editor\"",
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
.scrollback_editor,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let mut pane = Pane::new(&config, &theme::DEFAULT, &ctx, None).unwrap();
|
||||||
|
pane.terminal.resize(12, 2, 8, 16).unwrap();
|
||||||
|
pane.terminal
|
||||||
|
.vt_write(b"history\r\n\x1b[31mred\x1b[0m\r\nlong line that wraps\r\nlast");
|
||||||
|
pane.open_scrollback(&config, &theme::DEFAULT, &ctx)
|
||||||
|
.unwrap();
|
||||||
|
let (original, file) = pane.saved_session.as_ref().unwrap();
|
||||||
|
assert!(!original.dead);
|
||||||
|
let path = file.0.clone();
|
||||||
|
let contents = std::fs::read_to_string(&path).unwrap();
|
||||||
|
assert!(
|
||||||
|
contents.contains("history\nred\nlong line that wraps\nlast"),
|
||||||
|
"{contents:?}"
|
||||||
|
);
|
||||||
|
assert!(!contents.contains('\x1b'));
|
||||||
|
pane.send(b"done\n".to_vec()).unwrap();
|
||||||
|
let deadline = Instant::now() + Duration::from_secs(5);
|
||||||
|
while pane.saved_session.is_some() && Instant::now() < deadline {
|
||||||
|
pane.drain(&ctx);
|
||||||
|
std::thread::sleep(Duration::from_millis(10));
|
||||||
|
}
|
||||||
|
assert!(pane.saved_session.is_none());
|
||||||
|
assert!(!pane.dead);
|
||||||
|
assert!(!path.exists());
|
||||||
|
pane.send(b"continue\n".to_vec()).unwrap();
|
||||||
|
let deadline = Instant::now() + Duration::from_secs(5);
|
||||||
|
loop {
|
||||||
|
pane.drain(&ctx);
|
||||||
|
let text = libghostty_vt::fmt::Formatter::new(
|
||||||
|
&pane.terminal,
|
||||||
|
libghostty_vt::fmt::FormatterOptions::new().with_unwrap(true),
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
.format_alloc(None)
|
||||||
|
.unwrap();
|
||||||
|
if String::from_utf8_lossy(&text).contains("ORIGINAL_ALIVE") {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
assert!(
|
||||||
|
Instant::now() < deadline,
|
||||||
|
"original process did not resume input"
|
||||||
|
);
|
||||||
|
std::thread::sleep(Duration::from_millis(10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn invalid_editor_leaves_the_original_pane_intact() {
|
||||||
|
let ctx = egui::Context::default();
|
||||||
|
let config = Config {
|
||||||
|
shell: vec!["/bin/sh".into()],
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let mut pane = Pane::new(&config, &theme::DEFAULT, &ctx, None).unwrap();
|
||||||
|
for editor in ["", "'", "/no/such/slerm-editor"] {
|
||||||
|
assert!(
|
||||||
|
pane.open_scrollback_with_editor(&config, &theme::DEFAULT, &ctx, editor)
|
||||||
|
.is_err()
|
||||||
|
);
|
||||||
|
assert!(pane.saved_session.is_none());
|
||||||
|
assert!(!pane.dead);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for ScrollbackFile {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
let _ = std::fs::remove_file(&self.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// OSC 7 carries a `file://host/path` URL. Only a directory on this machine can be
|
/// OSC 7 carries a `file://host/path` URL. Only a directory on this machine can be
|
||||||
@@ -46,13 +232,29 @@ fn local_pwd(pwd: &str) -> Option<PathBuf> {
|
|||||||
return pwd.starts_with('/').then(|| PathBuf::from(pwd));
|
return pwd.starts_with('/').then(|| PathBuf::from(pwd));
|
||||||
};
|
};
|
||||||
let (host, path) = rest.split_once('/')?;
|
let (host, path) = rest.split_once('/')?;
|
||||||
|
// A shell may report either the short name or the FQDN, so compare the leading
|
||||||
|
// label of each.
|
||||||
|
let short = |name: &str| name.split('.').next().unwrap_or(name).to_ascii_lowercase();
|
||||||
let local = host.is_empty()
|
let local = host.is_empty()
|
||||||
|| host.eq_ignore_ascii_case("localhost")
|
|| host.eq_ignore_ascii_case("localhost")
|
||||||
|| std::fs::read_to_string("/proc/sys/kernel/hostname")
|
|| hostname().is_some_and(|name| short(&name) == short(host));
|
||||||
.is_ok_and(|name| name.trim().eq_ignore_ascii_case(host));
|
|
||||||
local.then(|| PathBuf::from(percent_decode(&format!("/{path}"))))
|
local.then(|| PathBuf::from(percent_decode(&format!("/{path}"))))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn hostname() -> Option<String> {
|
||||||
|
unsafe extern "C" {
|
||||||
|
fn gethostname(name: *mut std::ffi::c_char, len: usize) -> std::ffi::c_int;
|
||||||
|
}
|
||||||
|
let mut buf = [0u8; 256];
|
||||||
|
// SAFETY: at most `len` bytes are written, leaving the final byte of `buf` as
|
||||||
|
// the terminator even when the name is truncated.
|
||||||
|
if unsafe { gethostname(buf.as_mut_ptr().cast(), buf.len() - 1) } != 0 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let end = buf.iter().position(|&b| b == 0)?;
|
||||||
|
String::from_utf8(buf[..end].to_vec()).ok()
|
||||||
|
}
|
||||||
|
|
||||||
fn percent_decode(path: &str) -> String {
|
fn percent_decode(path: &str) -> String {
|
||||||
let mut out = Vec::with_capacity(path.len());
|
let mut out = Vec::with_capacity(path.len());
|
||||||
let mut bytes = path.bytes();
|
let mut bytes = path.bytes();
|
||||||
@@ -75,14 +277,16 @@ fn percent_decode(path: &str) -> String {
|
|||||||
String::from_utf8_lossy(&out).into_owned()
|
String::from_utf8_lossy(&out).into_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn terminal(config: &Config) -> Result<Terminal<'static, 'static>> {
|
pub fn terminal(config: &Config, theme: &Theme) -> Result<Terminal<'static, 'static>> {
|
||||||
let mut term = Terminal::new(TerminalOptions {
|
let mut term = Terminal::new(TerminalOptions {
|
||||||
cols: 80,
|
cols: 80,
|
||||||
rows: 24,
|
rows: 24,
|
||||||
max_scrollback: config.scrollback,
|
max_scrollback: config.scrollback,
|
||||||
})?;
|
})?;
|
||||||
term.resize(80, 24, 8, 16)?;
|
term.resize(80, 24, 8, 16)?;
|
||||||
apply_config(&mut term, config)?;
|
apply_config(&mut term, config, theme)?;
|
||||||
|
term.set_default_cursor_style(Some(terminal::CursorStyle::BlockHollow))?;
|
||||||
|
term.vt_write(b"\x1b[0 q");
|
||||||
term.on_xtversion(|_| Some(concat!("slerm ", env!("CARGO_PKG_VERSION"))))?;
|
term.on_xtversion(|_| Some(concat!("slerm ", env!("CARGO_PKG_VERSION"))))?;
|
||||||
term.on_device_attributes(|_| {
|
term.on_device_attributes(|_| {
|
||||||
Some(terminal::DeviceAttributes {
|
Some(terminal::DeviceAttributes {
|
||||||
@@ -98,14 +302,21 @@ pub fn terminal(config: &Config) -> Result<Terminal<'static, 'static>> {
|
|||||||
tertiary: Default::default(),
|
tertiary: Default::default(),
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
term.on_color_scheme(|_| Some(terminal::ColorScheme::Dark))?;
|
let scheme = if theme.dark {
|
||||||
|
terminal::ColorScheme::Dark
|
||||||
|
} else {
|
||||||
|
terminal::ColorScheme::Light
|
||||||
|
};
|
||||||
|
term.on_color_scheme(move |_| Some(scheme))?;
|
||||||
Ok(term)
|
Ok(term)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_config(term: &mut Terminal<'_, '_>, config: &Config) -> Result<()> {
|
pub fn apply_config(term: &mut Terminal<'_, '_>, config: &Config, theme: &Theme) -> Result<()> {
|
||||||
term.set_default_fg_color(Some(rgb(&config.foreground)?))?
|
let palette = theme.palette(term.default_color_palette()?);
|
||||||
.set_default_bg_color(Some(rgb(&config.background)?))?
|
term.set_default_fg_color(Some(theme::rgb_color(theme.foreground)))?
|
||||||
.set_default_cursor_color(Some(rgb(&config.accent)?))?
|
.set_default_bg_color(Some(theme::rgb_color(theme.background)))?
|
||||||
|
.set_default_cursor_color(Some(theme::rgb_color(theme.cursor)))?
|
||||||
|
.set_default_color_palette(Some(palette))?
|
||||||
.set_kitty_image_storage_limit(config.kitty.image_storage_mb * 1024 * 1024)?
|
.set_kitty_image_storage_limit(config.kitty.image_storage_mb * 1024 * 1024)?
|
||||||
.set_kitty_image_from_file_allowed(config.kitty.allow_file)?
|
.set_kitty_image_from_file_allowed(config.kitty.allow_file)?
|
||||||
.set_kitty_image_from_temp_file_allowed(config.kitty.allow_temp_file)?
|
.set_kitty_image_from_temp_file_allowed(config.kitty.allow_temp_file)?
|
||||||
@@ -114,8 +325,13 @@ pub fn apply_config(term: &mut Terminal<'_, '_>, config: &Config) -> Result<()>
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Pane {
|
impl Pane {
|
||||||
pub fn new(config: &Config, ctx: &egui::Context, cwd: Option<&Path>) -> Result<Self> {
|
pub fn new(
|
||||||
let mut terminal = terminal(config)?;
|
config: &Config,
|
||||||
|
theme: &Theme,
|
||||||
|
ctx: &egui::Context,
|
||||||
|
cwd: Option<&Path>,
|
||||||
|
) -> Result<Self> {
|
||||||
|
let mut terminal = terminal(config, theme)?;
|
||||||
let renderer = Renderer::new()?;
|
let renderer = Renderer::new()?;
|
||||||
let mouse_encoder = mouse::Encoder::new()?;
|
let mouse_encoder = mouse::Encoder::new()?;
|
||||||
let mouse_event = mouse::Event::new()?;
|
let mouse_event = mouse::Event::new()?;
|
||||||
@@ -148,12 +364,18 @@ impl Pane {
|
|||||||
callback_error,
|
callback_error,
|
||||||
mouse_encoder,
|
mouse_encoder,
|
||||||
mouse_event,
|
mouse_event,
|
||||||
|
scrollback_scroll: ScrollAccumulator::default(),
|
||||||
|
mouse_scroll: ScrollAccumulator::default(),
|
||||||
selection_start: None,
|
selection_start: None,
|
||||||
focused: false,
|
focused: false,
|
||||||
|
saved_session: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn drain(&mut self, ctx: &egui::Context) {
|
pub fn drain(&mut self, ctx: &egui::Context) {
|
||||||
|
if let Some((session, _)) = &mut self.saved_session {
|
||||||
|
session.drain(ctx);
|
||||||
|
}
|
||||||
// Bound work per frame as well as queued bytes, so one busy PTY cannot starve others.
|
// Bound work per frame as well as queued bytes, so one busy PTY cannot starve others.
|
||||||
let mut drained = 0;
|
let mut drained = 0;
|
||||||
for _ in 0..64 {
|
for _ in 0..64 {
|
||||||
@@ -179,6 +401,66 @@ impl Pane {
|
|||||||
if drained == 64 {
|
if drained == 64 {
|
||||||
ctx.request_repaint();
|
ctx.request_repaint();
|
||||||
}
|
}
|
||||||
|
if self.dead
|
||||||
|
&& let Some((session, _file)) = self.saved_session.take()
|
||||||
|
{
|
||||||
|
*self = *session;
|
||||||
|
ctx.request_repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn open_scrollback(
|
||||||
|
&mut self,
|
||||||
|
config: &Config,
|
||||||
|
theme: &Theme,
|
||||||
|
ctx: &egui::Context,
|
||||||
|
) -> Result<()> {
|
||||||
|
if self.saved_session.is_some() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
let editor = config
|
||||||
|
.scrollback_editor
|
||||||
|
.clone()
|
||||||
|
.unwrap_or_else(|| std::env::var("EDITOR").unwrap_or_else(|_| "vi".into()));
|
||||||
|
self.open_scrollback_with_editor(config, theme, ctx, &editor)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn open_scrollback_with_editor(
|
||||||
|
&mut self,
|
||||||
|
config: &Config,
|
||||||
|
theme: &Theme,
|
||||||
|
ctx: &egui::Context,
|
||||||
|
editor: &str,
|
||||||
|
) -> Result<()> {
|
||||||
|
use libghostty_vt::fmt::{Formatter, FormatterOptions};
|
||||||
|
let mut command =
|
||||||
|
shell_words::split(editor).context("Invalid scrollback editor command")?;
|
||||||
|
ensure!(
|
||||||
|
!command.is_empty() && !command[0].is_empty(),
|
||||||
|
"Scrollback editor command is empty"
|
||||||
|
);
|
||||||
|
self.drain(ctx);
|
||||||
|
let bytes = Formatter::new(
|
||||||
|
&self.terminal,
|
||||||
|
FormatterOptions::new().with_trim(true).with_unwrap(true),
|
||||||
|
)?
|
||||||
|
.format_alloc(None)?;
|
||||||
|
let file = ScrollbackFile::new(&bytes).context("Cannot save scrollback")?;
|
||||||
|
command.push(
|
||||||
|
file.0
|
||||||
|
.to_str()
|
||||||
|
.context("Scrollback path is not valid UTF-8")?
|
||||||
|
.into(),
|
||||||
|
);
|
||||||
|
let mut editor_config = config.clone();
|
||||||
|
editor_config.shell = command;
|
||||||
|
let mut editor_pane = Self::new(&editor_config, theme, ctx, self.cwd().as_deref())
|
||||||
|
.context("Cannot open scrollback editor")?;
|
||||||
|
editor_pane.last_rect = self.last_rect;
|
||||||
|
let session = std::mem::replace(self, editor_pane);
|
||||||
|
self.saved_session = Some((Box::new(session), file));
|
||||||
|
ctx.request_repaint();
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send(&mut self, bytes: Vec<u8>) -> Result<()> {
|
pub fn send(&mut self, bytes: Vec<u8>) -> Result<()> {
|
||||||
@@ -191,6 +473,7 @@ impl Pane {
|
|||||||
.try_send(bytes)
|
.try_send(bytes)
|
||||||
.map_err(|e| anyhow::anyhow!("PTY input queue: {e}"))?;
|
.map_err(|e| anyhow::anyhow!("PTY input queue: {e}"))?;
|
||||||
self.terminal.scroll_viewport(ScrollViewport::Bottom);
|
self.terminal.scroll_viewport(ScrollViewport::Bottom);
|
||||||
|
self.scrollback_scroll = ScrollAccumulator::default();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,6 +528,7 @@ impl Pane {
|
|||||||
ui: &mut egui::Ui,
|
ui: &mut egui::Ui,
|
||||||
rect: Rect,
|
rect: Rect,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
|
theme: &Theme,
|
||||||
active: bool,
|
active: bool,
|
||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
let font = FontId::monospace(config.font_size);
|
let font = FontId::monospace(config.font_size);
|
||||||
@@ -273,15 +557,24 @@ impl Pane {
|
|||||||
}
|
}
|
||||||
let response = ui.interact(grid, ui.id().with("terminal"), Sense::click_and_drag());
|
let response = ui.interact(grid, ui.id().with("terminal"), Sense::click_and_drag());
|
||||||
self.pointer(ui, &response, grid, cell)?;
|
self.pointer(ui, &response, grid, cell)?;
|
||||||
self.renderer
|
self.renderer.paint(
|
||||||
.paint(&self.terminal, ui.painter(), grid, cell, &font, active)?;
|
&self.terminal,
|
||||||
|
ui.painter(),
|
||||||
|
&Grid {
|
||||||
|
rect: grid,
|
||||||
|
cell,
|
||||||
|
font: &font,
|
||||||
|
theme,
|
||||||
|
active,
|
||||||
|
},
|
||||||
|
)?;
|
||||||
if let Some(error) = &self.error {
|
if let Some(error) = &self.error {
|
||||||
ui.painter().text(
|
ui.painter().text(
|
||||||
grid.left_bottom() - vec2(0.0, ch),
|
grid.left_bottom() - vec2(0.0, ch),
|
||||||
egui::Align2::LEFT_TOP,
|
egui::Align2::LEFT_TOP,
|
||||||
error,
|
error,
|
||||||
FontId::proportional(12.0),
|
FontId::proportional(12.0),
|
||||||
egui::Color32::LIGHT_RED,
|
theme::color(theme.ansi[9]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Ok(response.clicked()
|
Ok(response.clicked()
|
||||||
@@ -298,6 +591,12 @@ impl Pane {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let modifiers = ui.input(|i| i.modifiers);
|
let modifiers = ui.input(|i| i.modifiers);
|
||||||
let tracking = self.terminal.is_mouse_tracking()? && !modifiers.shift;
|
let tracking = self.terminal.is_mouse_tracking()? && !modifiers.shift;
|
||||||
|
if !response.hovered() || tracking {
|
||||||
|
self.scrollback_scroll = ScrollAccumulator::default();
|
||||||
|
}
|
||||||
|
if !response.hovered() || !tracking {
|
||||||
|
self.mouse_scroll = ScrollAccumulator::default();
|
||||||
|
}
|
||||||
let pos = response
|
let pos = response
|
||||||
.interact_pointer_pos()
|
.interact_pointer_pos()
|
||||||
.or_else(|| ui.input(|i| i.pointer.hover_pos()));
|
.or_else(|| ui.input(|i| i.pointer.hover_pos()));
|
||||||
@@ -346,8 +645,9 @@ impl Pane {
|
|||||||
mouse::Action::Release
|
mouse::Action::Release
|
||||||
})
|
})
|
||||||
.set_button(Some(button));
|
.set_button(Some(button));
|
||||||
self.mouse_encoder
|
input::append_encoded(&mut data, |buffer| {
|
||||||
.encode_to_vec(&self.mouse_event, &mut data)?;
|
self.mouse_encoder.encode(&self.mouse_event, buffer)
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
egui::Event::PointerMoved(_) => {
|
egui::Event::PointerMoved(_) => {
|
||||||
let button = ui.input(|i| {
|
let button = ui.input(|i| {
|
||||||
@@ -362,20 +662,23 @@ impl Pane {
|
|||||||
self.mouse_event
|
self.mouse_event
|
||||||
.set_action(mouse::Action::Motion)
|
.set_action(mouse::Action::Motion)
|
||||||
.set_button(button);
|
.set_button(button);
|
||||||
self.mouse_encoder
|
input::append_encoded(&mut data, |buffer| {
|
||||||
.encode_to_vec(&self.mouse_event, &mut data)?;
|
self.mouse_encoder.encode(&self.mouse_event, buffer)
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
egui::Event::MouseWheel { delta, .. } => {
|
egui::Event::MouseWheel { unit, delta, .. } => {
|
||||||
|
let rows = self.mouse_scroll.wheel(unit, delta.y, cell.y, self.size.1);
|
||||||
self.mouse_event
|
self.mouse_event
|
||||||
.set_action(mouse::Action::Press)
|
.set_action(mouse::Action::Press)
|
||||||
.set_button(Some(if delta.y > 0.0 {
|
.set_button(Some(if rows > 0 {
|
||||||
mouse::Button::Four
|
mouse::Button::Four
|
||||||
} else {
|
} else {
|
||||||
mouse::Button::Five
|
mouse::Button::Five
|
||||||
}));
|
}));
|
||||||
for _ in 0..3 {
|
for _ in 0..rows.unsigned_abs() {
|
||||||
self.mouse_encoder
|
input::append_encoded(&mut data, |buffer| {
|
||||||
.encode_to_vec(&self.mouse_event, &mut data)?;
|
self.mouse_encoder.encode(&self.mouse_event, buffer)
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@@ -408,10 +711,9 @@ impl Pane {
|
|||||||
}
|
}
|
||||||
if response.hovered() {
|
if response.hovered() {
|
||||||
let scroll = ui.input(|i| i.raw_scroll_delta.y);
|
let scroll = ui.input(|i| i.raw_scroll_delta.y);
|
||||||
if scroll.abs() >= 1.0 {
|
let rows = self.scrollback_scroll.rows(scroll / cell.y);
|
||||||
self.terminal.scroll_viewport(ScrollViewport::Delta(
|
if rows != 0 {
|
||||||
-(scroll / cell.y).round() as isize,
|
self.terminal.scroll_viewport(ScrollViewport::Delta(-rows));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+69
-4
@@ -111,11 +111,10 @@ impl Pty {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The working directory of the foreground process group, via /proc. Shells
|
/// The working directory of the foreground process group. Shells that emit
|
||||||
/// that emit OSC 7 are reported by the terminal instead; this covers the rest.
|
/// OSC 7 are reported by the terminal instead; this covers the rest.
|
||||||
pub fn cwd(&self) -> Option<PathBuf> {
|
pub fn cwd(&self) -> Option<PathBuf> {
|
||||||
let pid = self.master.process_group_leader()?;
|
process_cwd(self.master.process_group_leader()?)
|
||||||
std::fs::read_link(format!("/proc/{pid}/cwd")).ok()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resize(&self, cols: u16, rows: u16, cw: u32, ch: u32) -> Result<()> {
|
pub fn resize(&self, cols: u16, rows: u16, cw: u32, ch: u32) -> Result<()> {
|
||||||
@@ -129,6 +128,72 @@ impl Pty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
fn process_cwd(pid: i32) -> Option<PathBuf> {
|
||||||
|
std::fs::read_link(format!("/proc/{pid}/cwd")).ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// macOS has no /proc, so the current directory comes from `proc_pidinfo`.
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
fn process_cwd(pid: i32) -> Option<PathBuf> {
|
||||||
|
use std::{ffi::CStr, os::unix::ffi::OsStrExt};
|
||||||
|
|
||||||
|
// <sys/proc_info.h>. `vinfo_stat` is spelled as its 136 bytes of padding
|
||||||
|
// because only the path that follows it is of interest here.
|
||||||
|
#[repr(C)]
|
||||||
|
struct VnodeInfo {
|
||||||
|
stat: [u64; 17],
|
||||||
|
vtype: i32,
|
||||||
|
pad: i32,
|
||||||
|
fsid: [i32; 2],
|
||||||
|
}
|
||||||
|
#[repr(C)]
|
||||||
|
struct VnodeInfoPath {
|
||||||
|
info: VnodeInfo,
|
||||||
|
path: [std::ffi::c_char; 1024],
|
||||||
|
}
|
||||||
|
#[repr(C)]
|
||||||
|
struct VnodePathInfo {
|
||||||
|
cdir: VnodeInfoPath,
|
||||||
|
rdir: VnodeInfoPath,
|
||||||
|
}
|
||||||
|
const PROC_PIDVNODEPATHINFO: i32 = 9;
|
||||||
|
|
||||||
|
unsafe extern "C" {
|
||||||
|
fn proc_pidinfo(
|
||||||
|
pid: i32,
|
||||||
|
flavor: i32,
|
||||||
|
arg: u64,
|
||||||
|
buffer: *mut std::ffi::c_void,
|
||||||
|
buffersize: i32,
|
||||||
|
) -> i32;
|
||||||
|
}
|
||||||
|
|
||||||
|
let size = size_of::<VnodePathInfo>();
|
||||||
|
// SAFETY: the call writes at most `size` bytes into `info`, and reports how
|
||||||
|
// many it wrote. A short write leaves the path unset, so it is rejected.
|
||||||
|
unsafe {
|
||||||
|
let mut info = std::mem::zeroed::<VnodePathInfo>();
|
||||||
|
let written = proc_pidinfo(
|
||||||
|
pid,
|
||||||
|
PROC_PIDVNODEPATHINFO,
|
||||||
|
0,
|
||||||
|
(&raw mut info).cast(),
|
||||||
|
size as i32,
|
||||||
|
);
|
||||||
|
if written < size as i32 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let path = CStr::from_ptr(info.cdir.path.as_ptr());
|
||||||
|
(!path.is_empty()).then(|| PathBuf::from(std::ffi::OsStr::from_bytes(path.to_bytes())))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
|
||||||
|
fn process_cwd(_pid: i32) -> Option<PathBuf> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
impl Drop for Pty {
|
impl Drop for Pty {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
let _ = self.shutdown.send(());
|
let _ = self.shutdown.send(());
|
||||||
|
|||||||
+504
-70
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::theme::{self, Theme};
|
||||||
use anyhow::{Result, ensure};
|
use anyhow::{Result, ensure};
|
||||||
use egui::{
|
use egui::{
|
||||||
Color32, ColorImage, FontId, Painter, Rect, Stroke, TextureHandle, TextureOptions, pos2, vec2,
|
Color32, ColorImage, FontId, Painter, Rect, Stroke, TextureHandle, TextureOptions, pos2, vec2,
|
||||||
@@ -7,24 +8,43 @@ use libghostty_vt::{
|
|||||||
alloc::{Allocator, Bytes},
|
alloc::{Allocator, Bytes},
|
||||||
kitty::graphics::{DecodePng, DecodedImage, ImageFormat, Layer, PlacementIterator},
|
kitty::graphics::{DecodePng, DecodedImage, ImageFormat, Layer, PlacementIterator},
|
||||||
render::{CellIterator, Colors, CursorVisualStyle, Dirty, RowIterator},
|
render::{CellIterator, Colors, CursorVisualStyle, Dirty, RowIterator},
|
||||||
style::{RgbColor, Underline},
|
screen::CellWide,
|
||||||
|
style::{RgbColor, Style, Underline},
|
||||||
|
terminal::Mode,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
io::Cursor,
|
io::Cursor,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Where a pane's terminal is drawn this frame, and the colors that are slerm's
|
||||||
|
/// own rather than the terminal's.
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
pub struct Grid<'a> {
|
||||||
|
pub rect: Rect,
|
||||||
|
pub cell: egui::Vec2,
|
||||||
|
pub font: &'a FontId,
|
||||||
|
pub theme: &'a Theme,
|
||||||
|
pub active: bool,
|
||||||
|
}
|
||||||
|
|
||||||
pub fn color(c: RgbColor) -> Color32 {
|
pub fn color(c: RgbColor) -> Color32 {
|
||||||
Color32::from_rgb(c.r, c.g, c.b)
|
Color32::from_rgb(c.r, c.g, c.b)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cell_size(painter: &Painter, font: &FontId) -> egui::Vec2 {
|
pub fn cell_size(painter: &Painter, font: &FontId) -> egui::Vec2 {
|
||||||
|
let pixels_per_point = painter.ctx().pixels_per_point();
|
||||||
painter.ctx().fonts_mut(|fonts| {
|
painter.ctx().fonts_mut(|fonts| {
|
||||||
vec2(
|
// Cached glyphs are rasterized at x=0 and egui snaps their positions to
|
||||||
fonts.glyph_width(font, 'M').ceil().max(1.0),
|
// physical pixels. Use a whole-pixel column pitch so that snapping
|
||||||
fonts.row_height(font).ceil().max(1.0),
|
// cannot periodically insert an extra pixel between columns. Round
|
||||||
)
|
// down to avoid spacing wider than the font's advance.
|
||||||
|
let width_px = (fonts.glyph_width(font, 'M') * pixels_per_point)
|
||||||
|
.floor()
|
||||||
|
.max(1.0);
|
||||||
|
vec2(width_px / pixels_per_point, fonts.row_height(font).max(1.0))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,16 +145,71 @@ struct CachedRow {
|
|||||||
backgrounds: Vec<egui::Shape>,
|
backgrounds: Vec<egui::Shape>,
|
||||||
foregrounds: Vec<egui::Shape>,
|
foregrounds: Vec<egui::Shape>,
|
||||||
selection: Option<(u16, u16)>,
|
selection: Option<(u16, u16)>,
|
||||||
|
cells: Vec<CachedCell>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
|
struct CellAppearance {
|
||||||
|
text: String,
|
||||||
|
style: Style,
|
||||||
|
fg: Color32,
|
||||||
|
bg: Color32,
|
||||||
|
background: bool,
|
||||||
|
wide: CellWide,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct CachedCell {
|
||||||
|
appearance: CellAppearance,
|
||||||
|
backgrounds: std::ops::Range<usize>,
|
||||||
|
foregrounds: std::ops::Range<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn layout_glyph(painter: &Painter, text: String, font: &FontId, height: f32) -> Arc<egui::Galley> {
|
fn layout_glyph(painter: &Painter, text: String, font: &FontId, height: f32) -> Arc<egui::Galley> {
|
||||||
|
layout_styled_glyph(painter, text, font, height, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn layout_styled_glyph(
|
||||||
|
painter: &Painter,
|
||||||
|
text: String,
|
||||||
|
font: &FontId,
|
||||||
|
height: f32,
|
||||||
|
italics: bool,
|
||||||
|
) -> Arc<egui::Galley> {
|
||||||
let mut job =
|
let mut job =
|
||||||
egui::text::LayoutJob::simple(text, font.clone(), Color32::PLACEHOLDER, f32::INFINITY);
|
egui::text::LayoutJob::simple(text, font.clone(), Color32::PLACEHOLDER, f32::INFINITY);
|
||||||
job.sections[0].format.line_height = Some(height);
|
job.sections[0].format.line_height = Some(height);
|
||||||
job.sections[0].format.valign = egui::Align::Center;
|
job.sections[0].format.valign = egui::Align::Center;
|
||||||
|
job.sections[0].format.italics = italics;
|
||||||
painter.layout_job(job)
|
painter.layout_job(job)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn nerd_icon(text: &str) -> bool {
|
||||||
|
// Includes the supplementary private-use plane used by Material Design.
|
||||||
|
text.chars()
|
||||||
|
.next()
|
||||||
|
.is_some_and(|c| matches!(c as u32, 0xe000..=0xf8ff | 0xf0000..=0xffffd))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn icon_shape(galley: Arc<egui::Galley>, rect: Rect, color: Color32) -> egui::Shape {
|
||||||
|
// Use ink bounds: patched fonts can have bearings or outlines that extend
|
||||||
|
// well beyond their nominal advance. Fit uniformly and center in the cell
|
||||||
|
// allocation so icons cannot cover neighboring text or rows.
|
||||||
|
let bounds = galley.mesh_bounds;
|
||||||
|
let mut shape = egui::epaint::TextShape::new(egui::Pos2::ZERO, galley, color);
|
||||||
|
if bounds.is_positive() {
|
||||||
|
let scale = (rect.width() / bounds.width())
|
||||||
|
.min(rect.height() / bounds.height())
|
||||||
|
.min(1.0);
|
||||||
|
shape.transform(egui::emath::TSTransform {
|
||||||
|
scaling: scale,
|
||||||
|
translation: rect.center().to_vec2() - bounds.center().to_vec2() * scale,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
shape.pos = rect.min;
|
||||||
|
}
|
||||||
|
shape.into()
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Renderer {
|
pub struct Renderer {
|
||||||
state: RenderState<'static>,
|
state: RenderState<'static>,
|
||||||
rows: RowIterator<'static>,
|
rows: RowIterator<'static>,
|
||||||
@@ -142,13 +217,19 @@ pub struct Renderer {
|
|||||||
placements: PlacementIterator<'static>,
|
placements: PlacementIterator<'static>,
|
||||||
textures: HashMap<u32, (u64, TextureHandle)>,
|
textures: HashMap<u32, (u64, TextureHandle)>,
|
||||||
row_cache: Vec<CachedRow>,
|
row_cache: Vec<CachedRow>,
|
||||||
glyphs: HashMap<String, Arc<egui::Galley>>,
|
glyphs: HashMap<(String, bool, bool), Arc<egui::Galley>>,
|
||||||
font_marker: Option<Arc<egui::Galley>>,
|
font_marker: Option<Arc<egui::Galley>>,
|
||||||
|
synthetic_styles: [(bool, bool); 4],
|
||||||
cached_colors: Option<Colors>,
|
cached_colors: Option<Colors>,
|
||||||
|
cached_selection: (Color32, Color32),
|
||||||
cached_cell: egui::Vec2,
|
cached_cell: egui::Vec2,
|
||||||
cached_cols: u16,
|
cached_cols: u16,
|
||||||
|
frame: Vec<egui::epaint::ClippedShape>,
|
||||||
|
sync_started: Option<Instant>,
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
rebuilt_rows: usize,
|
rebuilt_rows: usize,
|
||||||
|
#[cfg(test)]
|
||||||
|
rebuilt_cells: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Renderer {
|
impl Renderer {
|
||||||
@@ -162,11 +243,17 @@ impl Renderer {
|
|||||||
row_cache: Vec::new(),
|
row_cache: Vec::new(),
|
||||||
glyphs: HashMap::new(),
|
glyphs: HashMap::new(),
|
||||||
font_marker: None,
|
font_marker: None,
|
||||||
|
synthetic_styles: [(false, false); 4],
|
||||||
cached_colors: None,
|
cached_colors: None,
|
||||||
|
cached_selection: (Color32::PLACEHOLDER, Color32::PLACEHOLDER),
|
||||||
cached_cell: egui::Vec2::ZERO,
|
cached_cell: egui::Vec2::ZERO,
|
||||||
cached_cols: 0,
|
cached_cols: 0,
|
||||||
|
frame: Vec::new(),
|
||||||
|
sync_started: None,
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
rebuilt_rows: 0,
|
rebuilt_rows: 0,
|
||||||
|
#[cfg(test)]
|
||||||
|
rebuilt_cells: 0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,39 +261,95 @@ impl Renderer {
|
|||||||
&mut self,
|
&mut self,
|
||||||
term: &Terminal<'static, '_>,
|
term: &Terminal<'static, '_>,
|
||||||
painter: &Painter,
|
painter: &Painter,
|
||||||
rect: Rect,
|
grid: &Grid<'_>,
|
||||||
cell: egui::Vec2,
|
|
||||||
font: &FontId,
|
|
||||||
active: bool,
|
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let &Grid {
|
||||||
|
rect,
|
||||||
|
cell,
|
||||||
|
font,
|
||||||
|
theme,
|
||||||
|
active,
|
||||||
|
} = grid;
|
||||||
let painter = painter.with_clip_rect(rect.intersect(painter.clip_rect()));
|
let painter = painter.with_clip_rect(rect.intersect(painter.clip_rect()));
|
||||||
// Keep one egui galley alive in its cache each frame. A new identity means
|
// Keep one egui galley alive in its cache each frame. A new identity means
|
||||||
// fonts/DPI/the atlas were reset, invalidating every cached glyph's UVs.
|
// fonts/DPI/the atlas were reset, invalidating every cached glyph's UVs.
|
||||||
let marker = layout_glyph(&painter, "M".into(), font, cell.y);
|
let marker = layout_glyph(&painter, "M".into(), font, cell.y);
|
||||||
if self
|
let fonts_changed = self
|
||||||
.font_marker
|
.font_marker
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.is_none_or(|old| !Arc::ptr_eq(old, &marker))
|
.is_none_or(|old| !Arc::ptr_eq(old, &marker))
|
||||||
|| self.cached_cell != cell
|
|| self.cached_cell != cell
|
||||||
|| self.glyphs.len() > 4096
|
|| self.glyphs.len() > 4096;
|
||||||
{
|
if fonts_changed {
|
||||||
self.row_cache.clear();
|
self.row_cache.clear();
|
||||||
self.glyphs.clear();
|
self.glyphs.clear();
|
||||||
|
self.frame.clear();
|
||||||
}
|
}
|
||||||
self.font_marker = Some(marker);
|
self.font_marker = Some(marker);
|
||||||
self.cached_cell = cell;
|
self.cached_cell = cell;
|
||||||
|
// Editors may clear and redraw in separate PTY reads. Keep presenting
|
||||||
|
// the last complete frame until DEC synchronized output ends. Bound
|
||||||
|
// the wait so a crashed application cannot leave the display frozen.
|
||||||
|
if term.mode(Mode::SYNC_OUTPUT)? {
|
||||||
|
let elapsed = self.sync_started.get_or_insert_with(Instant::now).elapsed();
|
||||||
|
let timeout = Duration::from_secs(1);
|
||||||
|
if elapsed < timeout && !self.frame.is_empty() {
|
||||||
|
painter.ctx().request_repaint_after(timeout - elapsed);
|
||||||
|
self.present(&painter, rect);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.sync_started = None;
|
||||||
|
}
|
||||||
|
let screen_rect = rect;
|
||||||
|
let rect = Rect::from_min_size(egui::Pos2::ZERO, rect.size());
|
||||||
|
let style_fonts = painter.ctx().fonts(|fonts| {
|
||||||
|
[(false, false), (true, false), (false, true), (true, true)].map(|(bold, italic)| {
|
||||||
|
let family = crate::fonts::family(bold, italic);
|
||||||
|
if font.family == egui::FontFamily::Monospace
|
||||||
|
&& fonts.definitions().families.contains_key(&family)
|
||||||
|
{
|
||||||
|
FontId::new(font.size, family)
|
||||||
|
} else {
|
||||||
|
font.clone()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
if fonts_changed {
|
||||||
|
self.synthetic_styles = painter.ctx().fonts(|fonts| {
|
||||||
|
let first_face = |index: usize| {
|
||||||
|
fonts.definitions().families[&style_fonts[index].family]
|
||||||
|
.first()
|
||||||
|
.map(|name| &fonts.definitions().font_data[name])
|
||||||
|
};
|
||||||
|
std::array::from_fn::<_, 4, _>(|index| {
|
||||||
|
(
|
||||||
|
index & 1 != 0 && first_face(index) == first_face(index & !1),
|
||||||
|
index & 2 != 0 && first_face(index) == first_face(index & !2),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let synthetic = self.synthetic_styles;
|
||||||
let snapshot = self.state.update(term)?;
|
let snapshot = self.state.update(term)?;
|
||||||
let colors = snapshot.colors()?;
|
let colors = snapshot.colors()?;
|
||||||
let cols = snapshot.cols()?;
|
let cols = snapshot.cols()?;
|
||||||
let row_count = snapshot.rows()? as usize;
|
let row_count = snapshot.rows()? as usize;
|
||||||
|
let selected_colors = (
|
||||||
|
theme::color(theme.selection_bg),
|
||||||
|
theme::color(theme.selection_fg),
|
||||||
|
);
|
||||||
let rebuild_all = snapshot.dirty()? == Dirty::Full
|
let rebuild_all = snapshot.dirty()? == Dirty::Full
|
||||||
|| self.cached_colors.as_ref() != Some(&colors)
|
|| self.cached_colors.as_ref() != Some(&colors)
|
||||||
|
|| self.cached_selection != selected_colors
|
||||||
|| self.cached_cols != cols
|
|| self.cached_cols != cols
|
||||||
|| self.row_cache.len() != row_count;
|
|| self.row_cache.len() != row_count;
|
||||||
self.row_cache.resize_with(row_count, CachedRow::default);
|
self.row_cache.resize_with(row_count, CachedRow::default);
|
||||||
self.cached_colors = Some(colors.clone());
|
self.cached_colors = Some(colors.clone());
|
||||||
|
self.cached_selection = selected_colors;
|
||||||
self.cached_cols = cols;
|
self.cached_cols = cols;
|
||||||
painter.rect_filled(rect, 0, color(colors.background));
|
let mut shapes = vec![egui::Shape::rect_filled(rect, 0, color(colors.background))];
|
||||||
|
let mut cursor_shapes = Vec::new();
|
||||||
let mut rows = self.rows.update(&snapshot)?;
|
let mut rows = self.rows.update(&snapshot)?;
|
||||||
let mut text = String::new();
|
let mut text = String::new();
|
||||||
let mut y = 0;
|
let mut y = 0;
|
||||||
@@ -237,50 +380,111 @@ impl Renderer {
|
|||||||
let explicit_bg = c.bg_color()?;
|
let explicit_bg = c.bg_color()?;
|
||||||
let mut bg = color(explicit_bg.unwrap_or(colors.background));
|
let mut bg = color(explicit_bg.unwrap_or(colors.background));
|
||||||
let selected = c.is_selected()?;
|
let selected = c.is_selected()?;
|
||||||
if style.inverse ^ selected {
|
if style.inverse {
|
||||||
std::mem::swap(&mut fg, &mut bg);
|
std::mem::swap(&mut fg, &mut bg);
|
||||||
}
|
}
|
||||||
if explicit_bg.is_some() || style.inverse || selected {
|
// A selection takes the theme's own colors rather than inverting
|
||||||
backgrounds.push(egui::Shape::rect_filled(cell_rect, 0, bg));
|
// the cell, which would be invisible over inverted text.
|
||||||
|
if selected {
|
||||||
|
(bg, fg) = selected_colors;
|
||||||
}
|
}
|
||||||
if style.faint {
|
if style.faint {
|
||||||
fg = fg.gamma_multiply(0.6);
|
fg = fg.gamma_multiply(0.6);
|
||||||
}
|
}
|
||||||
if !style.invisible && c.graphemes_len()? > 0 {
|
let wide = c.raw_cell()?.wide()?;
|
||||||
c.graphemes_utf8(&mut text)?;
|
text.clear();
|
||||||
// Placeholder cells are reserved by the Kitty protocol, not printable text.
|
c.graphemes_utf8(&mut text)?;
|
||||||
if let Some(separator) = powerline_shape(&text, cell_rect, fg) {
|
let appearance = CellAppearance {
|
||||||
foregrounds.push(separator);
|
text: text.clone(),
|
||||||
} else if text != " " && !text.starts_with('\u{10eeee}') {
|
style,
|
||||||
let galley = if let Some(galley) = self.glyphs.get(&text) {
|
fg,
|
||||||
galley.clone()
|
bg,
|
||||||
} else {
|
background: explicit_bg.is_some() || style.inverse || selected,
|
||||||
let galley = layout_glyph(&painter, text.clone(), font, cell.y);
|
wide,
|
||||||
self.glyphs.insert(text.clone(), galley.clone());
|
};
|
||||||
galley
|
// Dirty flags are row-granular. Compare cells so edits in one
|
||||||
};
|
// split don't rebuild its unchanged neighbor on the same row.
|
||||||
foregrounds.push(egui::Shape::galley(pos, galley.clone(), fg));
|
let background_start = backgrounds.len();
|
||||||
if style.bold {
|
let foreground_start = foregrounds.len();
|
||||||
foregrounds.push(egui::Shape::galley(
|
if let Some(old) = self.row_cache[y].cells.get(x)
|
||||||
pos + vec2(0.45, 0.0),
|
&& old.appearance == appearance
|
||||||
galley,
|
{
|
||||||
fg,
|
backgrounds
|
||||||
|
.extend_from_slice(&self.row_cache[y].backgrounds[old.backgrounds.clone()]);
|
||||||
|
foregrounds
|
||||||
|
.extend_from_slice(&self.row_cache[y].foregrounds[old.foregrounds.clone()]);
|
||||||
|
} else {
|
||||||
|
#[cfg(test)]
|
||||||
|
{
|
||||||
|
self.rebuilt_cells += 1;
|
||||||
|
}
|
||||||
|
if appearance.background {
|
||||||
|
backgrounds.push(egui::Shape::rect_filled(cell_rect, 0, bg));
|
||||||
|
}
|
||||||
|
if !style.invisible
|
||||||
|
&& !matches!(wide, CellWide::SpacerHead | CellWide::SpacerTail)
|
||||||
|
&& c.graphemes_len()? > 0
|
||||||
|
{
|
||||||
|
// Placeholder cells are reserved by the Kitty protocol, not printable text.
|
||||||
|
if let Some(separator) = powerline_shape(&text, cell_rect, fg) {
|
||||||
|
foregrounds.push(separator);
|
||||||
|
} else if text != " " && !text.starts_with('\u{10eeee}') {
|
||||||
|
let index = usize::from(style.bold) + 2 * usize::from(style.italic);
|
||||||
|
let icon = nerd_icon(&text);
|
||||||
|
let key = (text.clone(), style.bold, style.italic);
|
||||||
|
let galley = if let Some(galley) = self.glyphs.get(&key) {
|
||||||
|
galley.clone()
|
||||||
|
} else {
|
||||||
|
let font = &style_fonts[index];
|
||||||
|
let galley = layout_styled_glyph(
|
||||||
|
&painter,
|
||||||
|
text.clone(),
|
||||||
|
font,
|
||||||
|
cell.y,
|
||||||
|
synthetic[index].1 && !icon,
|
||||||
|
);
|
||||||
|
self.glyphs.insert(key, galley.clone());
|
||||||
|
galley
|
||||||
|
};
|
||||||
|
// Keep style emphasis for regular-only fonts; real style
|
||||||
|
// faces are drawn once. Never distort symbol outlines.
|
||||||
|
if synthetic[index].0 && !icon {
|
||||||
|
foregrounds.push(egui::Shape::galley(
|
||||||
|
pos + vec2(0.45, 0.0),
|
||||||
|
galley.clone(),
|
||||||
|
fg,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
foregrounds.push(if icon {
|
||||||
|
let width = if wide == CellWide::Wide { 2.0 } else { 1.0 };
|
||||||
|
icon_shape(
|
||||||
|
galley,
|
||||||
|
Rect::from_min_size(pos, vec2(cell.x * width, cell.y)),
|
||||||
|
fg,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
egui::Shape::galley(pos, galley, fg)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (enabled, height) in [
|
||||||
|
(style.underline != Underline::None, cell.y - 2.0),
|
||||||
|
(style.strikethrough, cell.y * 0.55),
|
||||||
|
(style.overline, 1.0),
|
||||||
|
] {
|
||||||
|
if enabled {
|
||||||
|
foregrounds.push(egui::Shape::line_segment(
|
||||||
|
[pos + vec2(0.0, height), pos + vec2(cell.x, height)],
|
||||||
|
Stroke::new(1.0_f32, fg),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (enabled, height) in [
|
cached.cells.push(CachedCell {
|
||||||
(style.underline != Underline::None, cell.y - 2.0),
|
appearance,
|
||||||
(style.strikethrough, cell.y * 0.55),
|
backgrounds: background_start..backgrounds.len(),
|
||||||
(style.overline, 1.0),
|
foregrounds: foreground_start..foregrounds.len(),
|
||||||
] {
|
});
|
||||||
if enabled {
|
|
||||||
foregrounds.push(egui::Shape::line_segment(
|
|
||||||
[pos + vec2(0.0, height), pos + vec2(cell.x, height)],
|
|
||||||
Stroke::new(1.0_f32, fg),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
x += 1;
|
x += 1;
|
||||||
}
|
}
|
||||||
self.row_cache[y] = cached;
|
self.row_cache[y] = cached;
|
||||||
@@ -291,7 +495,7 @@ impl Renderer {
|
|||||||
let mut seen = HashSet::new();
|
let mut seen = HashSet::new();
|
||||||
for layer in [Layer::BelowBg, Layer::BelowText, Layer::AboveText] {
|
for layer in [Layer::BelowBg, Layer::BelowText, Layer::AboveText] {
|
||||||
if layer == Layer::BelowText {
|
if layer == Layer::BelowText {
|
||||||
painter.extend(
|
shapes.extend(
|
||||||
self.row_cache
|
self.row_cache
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|row| row.backgrounds.iter())
|
.flat_map(|row| row.backgrounds.iter())
|
||||||
@@ -303,7 +507,7 @@ impl Renderer {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if layer == Layer::AboveText {
|
if layer == Layer::AboveText {
|
||||||
painter.extend(
|
shapes.extend(
|
||||||
self.row_cache
|
self.row_cache
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|row| row.foregrounds.iter())
|
.flat_map(|row| row.foregrounds.iter())
|
||||||
@@ -323,6 +527,7 @@ impl Renderer {
|
|||||||
&mut self.placements,
|
&mut self.placements,
|
||||||
&mut self.textures,
|
&mut self.textures,
|
||||||
&mut seen,
|
&mut seen,
|
||||||
|
&mut shapes,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
self.textures.retain(|id, _| seen.contains(id));
|
self.textures.retain(|id, _| seen.contains(id));
|
||||||
@@ -337,25 +542,74 @@ impl Renderer {
|
|||||||
match snapshot.cursor_visual_style()? {
|
match snapshot.cursor_visual_style()? {
|
||||||
CursorVisualStyle::Bar if active => {
|
CursorVisualStyle::Bar if active => {
|
||||||
cursor_rect.max.x = cursor_rect.min.x + 2.0;
|
cursor_rect.max.x = cursor_rect.min.x + 2.0;
|
||||||
painter.rect_filled(cursor_rect, 0, c);
|
shapes.push(egui::Shape::rect_filled(cursor_rect, 0, c));
|
||||||
}
|
}
|
||||||
CursorVisualStyle::Underline if active => {
|
CursorVisualStyle::Underline if active => {
|
||||||
cursor_rect.min.y = cursor_rect.max.y - 2.0;
|
cursor_rect.min.y = cursor_rect.max.y - 2.0;
|
||||||
painter.rect_filled(cursor_rect, 0, c);
|
shapes.push(egui::Shape::rect_filled(cursor_rect, 0, c));
|
||||||
|
}
|
||||||
|
CursorVisualStyle::Block if active => {
|
||||||
|
shapes.push(egui::Shape::rect_filled(cursor_rect, 0, c));
|
||||||
|
// Redraw the covered glyph in the background color so an
|
||||||
|
// application's solid block cursor leaves text readable.
|
||||||
|
let ink = color(colors.background);
|
||||||
|
cursor_shapes.extend(
|
||||||
|
self.row_cache[cursor.y as usize]
|
||||||
|
.foregrounds
|
||||||
|
.iter()
|
||||||
|
.cloned()
|
||||||
|
.map(|mut shape| {
|
||||||
|
shape.translate(rect.min.to_vec2());
|
||||||
|
egui::epaint::shape_transform::adjust_colors(
|
||||||
|
&mut shape,
|
||||||
|
move |color| {
|
||||||
|
if *color != Color32::TRANSPARENT {
|
||||||
|
*color = ink;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
egui::epaint::ClippedShape {
|
||||||
|
clip_rect: cursor_rect.intersect(rect),
|
||||||
|
shape,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
painter.rect_stroke(
|
shapes.push(egui::Shape::rect_stroke(
|
||||||
cursor_rect,
|
cursor_rect,
|
||||||
0,
|
theme::CURSOR_CORNER_RADIUS,
|
||||||
Stroke::new(if active { 1.5_f32 } else { 0.75_f32 }, c),
|
Stroke::new(theme::BORDER_WIDTH, c),
|
||||||
egui::StrokeKind::Inside,
|
egui::StrokeKind::Inside,
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
snapshot.set_dirty(Dirty::Clean)?;
|
snapshot.set_dirty(Dirty::Clean)?;
|
||||||
|
self.frame = shapes
|
||||||
|
.into_iter()
|
||||||
|
.map(|shape| egui::epaint::ClippedShape {
|
||||||
|
clip_rect: rect,
|
||||||
|
shape,
|
||||||
|
})
|
||||||
|
.chain(cursor_shapes)
|
||||||
|
.collect();
|
||||||
|
self.present(&painter, screen_rect);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn present(&self, painter: &Painter, rect: Rect) {
|
||||||
|
for cached in &self.frame {
|
||||||
|
let mut shape = cached.shape.clone();
|
||||||
|
shape.translate(rect.min.to_vec2());
|
||||||
|
let clip = cached
|
||||||
|
.clip_rect
|
||||||
|
.translate(rect.min.to_vec2())
|
||||||
|
.intersect(rect)
|
||||||
|
.intersect(painter.clip_rect());
|
||||||
|
painter.with_clip_rect(clip).add(shape);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
@@ -368,6 +622,7 @@ fn paint_images(
|
|||||||
iterator: &mut PlacementIterator<'_>,
|
iterator: &mut PlacementIterator<'_>,
|
||||||
textures: &mut HashMap<u32, (u64, TextureHandle)>,
|
textures: &mut HashMap<u32, (u64, TextureHandle)>,
|
||||||
seen: &mut HashSet<u32>,
|
seen: &mut HashSet<u32>,
|
||||||
|
shapes: &mut Vec<egui::Shape>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let graphics = term.kitty_graphics()?;
|
let graphics = term.kitty_graphics()?;
|
||||||
let mut placements = iterator.update(&graphics)?;
|
let mut placements = iterator.update(&graphics)?;
|
||||||
@@ -442,7 +697,12 @@ fn paint_images(
|
|||||||
}
|
}
|
||||||
images.sort_by_key(|(z, id, pid, _, _)| (*z, *id, *pid));
|
images.sort_by_key(|(z, id, pid, _, _)| (*z, *id, *pid));
|
||||||
for (_, id, _, dest, uv) in images {
|
for (_, id, _, dest, uv) in images {
|
||||||
painter.image(textures[&id].1.id(), dest, uv, Color32::WHITE);
|
shapes.push(egui::Shape::image(
|
||||||
|
textures[&id].1.id(),
|
||||||
|
dest,
|
||||||
|
uv,
|
||||||
|
Color32::WHITE,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -451,6 +711,82 @@ fn paint_images(
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn sgr_styles_use_distinct_cached_faces_without_double_drawing() {
|
||||||
|
let ctx = egui::Context::default();
|
||||||
|
let config = crate::config::Config {
|
||||||
|
font_path: std::env::var_os("SLERM_TEST_FONT").map(Into::into),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
ctx.set_fonts(crate::fonts::load(&config).unwrap());
|
||||||
|
let mut term = crate::pane::terminal(&config, &theme::DEFAULT).unwrap();
|
||||||
|
term.resize(20, 2, 8, 16).unwrap();
|
||||||
|
term.vt_write(b"M\x1b[1mM\x1b[22;3mM\x1b[1mM\x1b[0mM");
|
||||||
|
let mut renderer = Renderer::new().unwrap();
|
||||||
|
let rect = Rect::from_min_size(egui::Pos2::ZERO, vec2(200.0, 100.0));
|
||||||
|
let font = FontId::monospace(16.0);
|
||||||
|
frame(&ctx, &mut renderer, &term, rect, &font);
|
||||||
|
assert_eq!(renderer.glyphs.len(), 4);
|
||||||
|
assert_eq!(
|
||||||
|
renderer.row_cache[0].foregrounds.len(),
|
||||||
|
if config.font_path.is_some() { 5 } else { 7 }
|
||||||
|
);
|
||||||
|
for (bold, italic) in [(false, false), (true, false), (false, true), (true, true)] {
|
||||||
|
let galley = &renderer.glyphs[&("M".into(), bold, italic)];
|
||||||
|
assert_eq!(
|
||||||
|
galley.job.sections[0].format.font_id.family,
|
||||||
|
crate::fonts::family(bold, italic)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let before = renderer.glyphs[&("M".into(), true, true)].clone();
|
||||||
|
let mut fonts = crate::fonts::load(&config).unwrap();
|
||||||
|
fonts
|
||||||
|
.families
|
||||||
|
.get_mut(&crate::fonts::family(true, true))
|
||||||
|
.unwrap()
|
||||||
|
.reverse();
|
||||||
|
ctx.set_fonts(fonts);
|
||||||
|
frame(&ctx, &mut renderer, &term, rect, &font);
|
||||||
|
assert!(!Arc::ptr_eq(
|
||||||
|
&before,
|
||||||
|
&renderer.glyphs[&("M".into(), true, true)]
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn icons_fit_ink_bounds_at_different_scales_and_cell_widths() {
|
||||||
|
let config = crate::config::Config {
|
||||||
|
font_path: std::env::var_os("SLERM_TEST_FONT").map(Into::into),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let fonts = crate::fonts::load(&config).unwrap();
|
||||||
|
for scale in [1.0, 1.5, 2.0] {
|
||||||
|
let ctx = egui::Context::default();
|
||||||
|
ctx.set_fonts(fonts.clone());
|
||||||
|
ctx.set_pixels_per_point(scale);
|
||||||
|
let _ = ctx.run(egui::RawInput::default(), |ctx| {
|
||||||
|
let painter = ctx.layer_painter(egui::LayerId::background());
|
||||||
|
for text in ["\u{e0a0}", "\u{f121}", "\u{f0001}"] {
|
||||||
|
assert!(nerd_icon(text));
|
||||||
|
for width in [4.0, 9.0, 18.0] {
|
||||||
|
let rect = Rect::from_min_size(pos2(23.0, 41.0), vec2(width, 18.0));
|
||||||
|
let galley =
|
||||||
|
layout_glyph(&painter, text.into(), &FontId::monospace(20.0), 18.0);
|
||||||
|
let shape = icon_shape(galley, rect, Color32::WHITE);
|
||||||
|
let bounds = shape.visual_bounding_rect();
|
||||||
|
assert!(
|
||||||
|
rect.expand(0.001).contains_rect(bounds),
|
||||||
|
"{text:?}: {bounds:?} outside {rect:?}"
|
||||||
|
);
|
||||||
|
assert!(bounds.center().distance(rect.center()) < 0.001);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
assert!(!nerd_icon("M"));
|
||||||
|
assert!(!nerd_icon("\u{10eeee}"));
|
||||||
|
}
|
||||||
|
|
||||||
fn frame(
|
fn frame(
|
||||||
ctx: &egui::Context,
|
ctx: &egui::Context,
|
||||||
renderer: &mut Renderer,
|
renderer: &mut Renderer,
|
||||||
@@ -461,12 +797,85 @@ mod tests {
|
|||||||
ctx.run(egui::RawInput::default(), |ctx| {
|
ctx.run(egui::RawInput::default(), |ctx| {
|
||||||
let painter = ctx.layer_painter(egui::LayerId::background());
|
let painter = ctx.layer_painter(egui::LayerId::background());
|
||||||
renderer
|
renderer
|
||||||
.paint(term, &painter, rect, cell_size(&painter, font), font, true)
|
.paint(
|
||||||
|
term,
|
||||||
|
&painter,
|
||||||
|
&Grid {
|
||||||
|
rect,
|
||||||
|
cell: cell_size(&painter, font),
|
||||||
|
font,
|
||||||
|
theme: &theme::DEFAULT,
|
||||||
|
active: true,
|
||||||
|
},
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
})
|
})
|
||||||
.shapes
|
.shapes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn scrolling_one_editor_split_reuses_unchanged_cells() {
|
||||||
|
let ctx = egui::Context::default();
|
||||||
|
let mut term =
|
||||||
|
crate::pane::terminal(&crate::config::Config::default(), &theme::DEFAULT).unwrap();
|
||||||
|
term.resize(20, 5, 8, 16).unwrap();
|
||||||
|
term.vt_write(b"\x1b[?25l");
|
||||||
|
for row in 1..=5 {
|
||||||
|
term.vt_write(format!("\x1b[{row};1Hleft {row} right {row}").as_bytes());
|
||||||
|
}
|
||||||
|
let rect = Rect::from_min_size(pos2(12.0, 24.0), vec2(200.0, 120.0));
|
||||||
|
let font = FontId::monospace(16.0);
|
||||||
|
let mut renderer = Renderer::new().unwrap();
|
||||||
|
frame(&ctx, &mut renderer, &term, rect, &font);
|
||||||
|
assert_eq!(renderer.rebuilt_cells, 100);
|
||||||
|
|
||||||
|
// Simulate an editor repainting entire rows while only its left split changes.
|
||||||
|
for row in 1..=5 {
|
||||||
|
term.vt_write(format!("\x1b[{row};1Hleft {} right {row}", row + 1).as_bytes());
|
||||||
|
}
|
||||||
|
let actual = frame(&ctx, &mut renderer, &term, rect, &font);
|
||||||
|
assert_eq!(renderer.rebuilt_cells, 105, "only five digits changed");
|
||||||
|
assert_eq!(
|
||||||
|
actual,
|
||||||
|
frame(&ctx, &mut Renderer::new().unwrap(), &term, rect, &font)
|
||||||
|
);
|
||||||
|
// Rewriting identical text should reuse every cell, even on dirty rows.
|
||||||
|
term.vt_write(b"\x1b[1;1Hleft 2 right 1");
|
||||||
|
frame(&ctx, &mut renderer, &term, rect, &font);
|
||||||
|
assert_eq!(renderer.rebuilt_cells, 105);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn synchronized_updates_keep_the_last_complete_frame() {
|
||||||
|
let ctx = egui::Context::default();
|
||||||
|
let mut term =
|
||||||
|
crate::pane::terminal(&crate::config::Config::default(), &theme::DEFAULT).unwrap();
|
||||||
|
term.resize(20, 5, 8, 16).unwrap();
|
||||||
|
term.vt_write(b"\x1b[?25lleft buffer\r\nright buffer");
|
||||||
|
let rect = Rect::from_min_size(pos2(12.0, 24.0), vec2(200.0, 120.0));
|
||||||
|
let font = FontId::monospace(16.0);
|
||||||
|
let mut renderer = Renderer::new().unwrap();
|
||||||
|
let initial = frame(&ctx, &mut renderer, &term, rect, &font);
|
||||||
|
let cells = renderer.rebuilt_cells;
|
||||||
|
term.vt_write(b"\x1b[?2026h\x1b[2J\x1b[Hpartial");
|
||||||
|
assert!(term.mode(Mode::SYNC_OUTPUT).unwrap());
|
||||||
|
assert_eq!(initial, frame(&ctx, &mut renderer, &term, rect, &font));
|
||||||
|
assert_eq!(renderer.rebuilt_cells, cells);
|
||||||
|
term.vt_write(b"\rcomplete\r\nright buffer\x1b[?2026l");
|
||||||
|
let completed = frame(&ctx, &mut renderer, &term, rect, &font);
|
||||||
|
assert_ne!(initial, completed);
|
||||||
|
assert_eq!(
|
||||||
|
completed,
|
||||||
|
frame(&ctx, &mut Renderer::new().unwrap(), &term, rect, &font)
|
||||||
|
);
|
||||||
|
|
||||||
|
// A missing end marker must not freeze the terminal indefinitely.
|
||||||
|
term.vt_write(b"\x1b[?2026h\x1b[Htimeout");
|
||||||
|
assert_eq!(completed, frame(&ctx, &mut renderer, &term, rect, &font));
|
||||||
|
renderer.sync_started = Some(Instant::now() - Duration::from_secs(2));
|
||||||
|
assert_ne!(completed, frame(&ctx, &mut renderer, &term, rect, &font));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cached_rows_match_fresh_rendering_after_terminal_changes() {
|
fn cached_rows_match_fresh_rendering_after_terminal_changes() {
|
||||||
use libghostty_vt::{
|
use libghostty_vt::{
|
||||||
@@ -475,7 +884,9 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let ctx = egui::Context::default();
|
let ctx = egui::Context::default();
|
||||||
let mut term = crate::pane::terminal(&crate::config::Config::default()).unwrap();
|
let mut term =
|
||||||
|
crate::pane::terminal(&crate::config::Config::default(), &crate::theme::DEFAULT)
|
||||||
|
.unwrap();
|
||||||
term.resize(20, 5, 8, 16).unwrap();
|
term.resize(20, 5, 8, 16).unwrap();
|
||||||
term.vt_write("\x1b[31mNOR\u{e0b4}\x1b[0m Android\r\nsecond line".as_bytes());
|
term.vt_write("\x1b[31mNOR\u{e0b4}\x1b[0m Android\r\nsecond line".as_bytes());
|
||||||
let rect = Rect::from_min_size(pos2(12.0, 24.0), vec2(200.0, 120.0));
|
let rect = Rect::from_min_size(pos2(12.0, 24.0), vec2(200.0, 120.0));
|
||||||
@@ -548,7 +959,9 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn cached_glyphs_rebuild_after_font_or_scale_changes() {
|
fn cached_glyphs_rebuild_after_font_or_scale_changes() {
|
||||||
let ctx = egui::Context::default();
|
let ctx = egui::Context::default();
|
||||||
let mut term = crate::pane::terminal(&crate::config::Config::default()).unwrap();
|
let mut term =
|
||||||
|
crate::pane::terminal(&crate::config::Config::default(), &crate::theme::DEFAULT)
|
||||||
|
.unwrap();
|
||||||
term.resize(20, 5, 8, 16).unwrap();
|
term.resize(20, 5, 8, 16).unwrap();
|
||||||
term.vt_write(b"font cache");
|
term.vt_write(b"font cache");
|
||||||
let rect = Rect::from_min_size(egui::Pos2::ZERO, vec2(200.0, 120.0));
|
let rect = Rect::from_min_size(egui::Pos2::ZERO, vec2(200.0, 120.0));
|
||||||
@@ -595,7 +1008,7 @@ mod tests {
|
|||||||
};
|
};
|
||||||
let ctx = egui::Context::default();
|
let ctx = egui::Context::default();
|
||||||
ctx.set_fonts(crate::app::fonts(&config).unwrap());
|
ctx.set_fonts(crate::app::fonts(&config).unwrap());
|
||||||
let mut term = crate::pane::terminal(&config).unwrap();
|
let mut term = crate::pane::terminal(&config, &theme::DEFAULT).unwrap();
|
||||||
term.resize(160, 50, 9, 18).unwrap();
|
term.resize(160, 50, 9, 18).unwrap();
|
||||||
let screen = (1..=50)
|
let screen = (1..=50)
|
||||||
.map(|row| {
|
.map(|row| {
|
||||||
@@ -629,10 +1042,16 @@ mod tests {
|
|||||||
.paint(
|
.paint(
|
||||||
&term,
|
&term,
|
||||||
&ctx.layer_painter(egui::LayerId::background()),
|
&ctx.layer_painter(egui::LayerId::background()),
|
||||||
Rect::from_min_size(egui::Pos2::ZERO, vec2(1440.0, 900.0)),
|
&Grid {
|
||||||
vec2(9.0, 18.0),
|
rect: Rect::from_min_size(
|
||||||
&FontId::monospace(16.0),
|
egui::Pos2::ZERO,
|
||||||
true,
|
vec2(1440.0, 900.0),
|
||||||
|
),
|
||||||
|
cell: vec2(9.0, 18.0),
|
||||||
|
font: &FontId::monospace(16.0),
|
||||||
|
theme: &theme::DEFAULT,
|
||||||
|
active: true,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
},
|
},
|
||||||
@@ -680,15 +1099,30 @@ mod tests {
|
|||||||
ctx.set_fonts(crate::app::fonts(&config).unwrap());
|
ctx.set_fonts(crate::app::fonts(&config).unwrap());
|
||||||
let _ = ctx.run(egui::RawInput::default(), |ctx| {
|
let _ = ctx.run(egui::RawInput::default(), |ctx| {
|
||||||
let painter = ctx.layer_painter(egui::LayerId::background());
|
let painter = ctx.layer_painter(egui::LayerId::background());
|
||||||
for size in [12.0, 16.0, 20.0, 24.0] {
|
for size in [12.0, 13.0, 14.5, 16.0, 17.0, 20.0, 24.0] {
|
||||||
let font = FontId::monospace(size);
|
let font = FontId::monospace(size);
|
||||||
let cell = cell_size(&painter, &font);
|
let cell = cell_size(&painter, &font);
|
||||||
let line_height = ctx.fonts_mut(|fonts| fonts.row_height(&font));
|
let line_height = ctx.fonts_mut(|fonts| fonts.row_height(&font));
|
||||||
assert_eq!(
|
assert_eq!(cell.y, line_height, "font size {size}, scale {scale}");
|
||||||
cell.y,
|
// The pitch must fit within the glyph advance and differ
|
||||||
line_height.ceil(),
|
// by less than one physical pixel.
|
||||||
"font size {size}, scale {scale}"
|
let row = painter.layout_no_wrap("M".repeat(80), font.clone(), Color32::WHITE);
|
||||||
|
let advance: f32 = row.rows[0].glyphs.iter().map(|g| g.advance_width).sum();
|
||||||
|
assert!(
|
||||||
|
advance - 80.0 * cell.x >= -0.01 && advance - 80.0 * cell.x < 80.0 / scale,
|
||||||
|
"grid width {} vs glyph advances {advance}, size {size}, scale {scale}",
|
||||||
|
80.0 * cell.x
|
||||||
);
|
);
|
||||||
|
// Check the positions egui will actually use, including a
|
||||||
|
// pane origin that falls between physical pixels.
|
||||||
|
let pitch = cell.x * scale;
|
||||||
|
for origin in [0.0, 0.37, 12.25] {
|
||||||
|
for column in 0..80 {
|
||||||
|
let left = ((origin + column as f32 * cell.x) * scale).round();
|
||||||
|
let right = ((origin + (column + 1) as f32 * cell.x) * scale).round();
|
||||||
|
assert!((right - left - pitch).abs() < 0.001);
|
||||||
|
}
|
||||||
|
}
|
||||||
let text = painter.layout_no_wrap("NOR Android".into(), font, Color32::WHITE);
|
let text = painter.layout_no_wrap("NOR Android".into(), font, Color32::WHITE);
|
||||||
assert!(
|
assert!(
|
||||||
(cell.y - text.size().y).abs() <= 1.0,
|
(cell.y - text.size().y).abs() <= 1.0,
|
||||||
|
|||||||
+86
-12
@@ -1,4 +1,4 @@
|
|||||||
use crate::{config::Config, input, pane, render};
|
use crate::{config::Config, input, pane, render, theme};
|
||||||
use base64::Engine;
|
use base64::Engine;
|
||||||
use egui::{Event, Key, Modifiers};
|
use egui::{Event, Key, Modifiers};
|
||||||
use libghostty_vt::{
|
use libghostty_vt::{
|
||||||
@@ -28,9 +28,32 @@ fn key(key: Key, modifiers: Modifiers) -> Event {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn cursor_defaults_to_hollow_and_respects_application_styles() {
|
||||||
|
use libghostty_vt::{RenderState, render::CursorVisualStyle};
|
||||||
|
|
||||||
|
let mut term = pane::terminal(&Config::default(), &theme::DEFAULT).unwrap();
|
||||||
|
let mut state = RenderState::new().unwrap();
|
||||||
|
let snapshot = state.update(&term).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
snapshot.cursor_visual_style().unwrap(),
|
||||||
|
CursorVisualStyle::BlockHollow
|
||||||
|
);
|
||||||
|
for (sequence, expected) in [
|
||||||
|
(b"\x1b[2 q", CursorVisualStyle::Block),
|
||||||
|
(b"\x1b[4 q", CursorVisualStyle::Underline),
|
||||||
|
(b"\x1b[6 q", CursorVisualStyle::Bar),
|
||||||
|
(b"\x1b[0 q", CursorVisualStyle::BlockHollow),
|
||||||
|
] {
|
||||||
|
term.vt_write(sequence);
|
||||||
|
let snapshot = state.update(&term).unwrap();
|
||||||
|
assert_eq!(snapshot.cursor_visual_style().unwrap(), expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn terminal_preserves_unicode_colors_and_application_input_modes() {
|
fn terminal_preserves_unicode_colors_and_application_input_modes() {
|
||||||
let mut term = pane::terminal(&Config::default()).unwrap();
|
let mut term = pane::terminal(&Config::default(), &theme::DEFAULT).unwrap();
|
||||||
term.vt_write("hello \x1b[31mred\x1b[0m \u{754c}e\u{301}\r\n".as_bytes());
|
term.vt_write("hello \x1b[31mred\x1b[0m \u{754c}e\u{301}\r\n".as_bytes());
|
||||||
assert!(plain(&term).contains("hello red \u{754c}e\u{301}"));
|
assert!(plain(&term).contains("hello red \u{754c}e\u{301}"));
|
||||||
let events = [
|
let events = [
|
||||||
@@ -57,9 +80,57 @@ fn terminal_preserves_unicode_colors_and_application_input_modes() {
|
|||||||
assert!(plain(&term).contains("hello red"));
|
assert!(plain(&term).contains("hello red"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn input_encoding_grows_buffers_without_losing_events() {
|
||||||
|
let term = pane::terminal(&Config::default(), &theme::DEFAULT).unwrap();
|
||||||
|
let mut events = vec![Event::Text("a".into()), Event::Text("123456789".into())];
|
||||||
|
let long_text = "界".repeat(200);
|
||||||
|
events.push(Event::Text(long_text.clone()));
|
||||||
|
for _ in 0..100 {
|
||||||
|
events.push(key(Key::ArrowUp, Modifiers::NONE));
|
||||||
|
}
|
||||||
|
let expected = format!("a123456789{long_text}{}", "\x1b[A".repeat(100));
|
||||||
|
assert_eq!(input::encode(&term, &events).unwrap(), expected.as_bytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn mouse_encoding_appends_when_destination_has_insufficient_spare_capacity() {
|
||||||
|
use libghostty_vt::mouse;
|
||||||
|
|
||||||
|
let mut term = pane::terminal(&Config::default(), &theme::DEFAULT).unwrap();
|
||||||
|
term.vt_write(b"\x1b[?1000h\x1b[?1006h");
|
||||||
|
let mut encoder = mouse::Encoder::new().unwrap();
|
||||||
|
encoder
|
||||||
|
.set_options_from_terminal(&term)
|
||||||
|
.set_size(mouse::EncoderSize {
|
||||||
|
screen_width: 800,
|
||||||
|
screen_height: 600,
|
||||||
|
cell_width: 8,
|
||||||
|
cell_height: 16,
|
||||||
|
padding_top: 0,
|
||||||
|
padding_bottom: 0,
|
||||||
|
padding_left: 0,
|
||||||
|
padding_right: 0,
|
||||||
|
});
|
||||||
|
let mut event = mouse::Event::new().unwrap();
|
||||||
|
event
|
||||||
|
.set_action(mouse::Action::Press)
|
||||||
|
.set_button(Some(mouse::Button::Left))
|
||||||
|
.set_position(mouse::Position { x: 0.0, y: 0.0 });
|
||||||
|
let mut out = Vec::with_capacity(16);
|
||||||
|
out.resize(9, b'x');
|
||||||
|
for _ in 0..100 {
|
||||||
|
input::append_encoded(&mut out, |buffer| encoder.encode(&event, buffer)).unwrap();
|
||||||
|
}
|
||||||
|
assert_eq!(
|
||||||
|
out,
|
||||||
|
format!("xxxxxxxxx{}", "\x1b[<0;1;1M".repeat(100)).as_bytes()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn queries_return_to_the_pty_and_alternate_screen_restores() {
|
fn queries_return_to_the_pty_and_alternate_screen_restores() {
|
||||||
let mut term = pane::terminal(&Config::default()).unwrap();
|
let mut term = pane::terminal(&Config::default(), &theme::DEFAULT).unwrap();
|
||||||
let response = Rc::new(RefCell::new(vec![]));
|
let response = Rc::new(RefCell::new(vec![]));
|
||||||
let writer = response.clone();
|
let writer = response.clone();
|
||||||
term.on_pty_write(move |_, bytes| writer.borrow_mut().extend_from_slice(bytes))
|
term.on_pty_write(move |_, bytes| writer.borrow_mut().extend_from_slice(bytes))
|
||||||
@@ -74,7 +145,7 @@ fn queries_return_to_the_pty_and_alternate_screen_restores() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn kitty_images_decode_render_reuse_and_delete() {
|
fn kitty_images_decode_render_reuse_and_delete() {
|
||||||
graphics::set_png_decoder(Some(Box::new(render::PngDecoder))).unwrap();
|
graphics::set_png_decoder(Some(Box::new(render::PngDecoder))).unwrap();
|
||||||
let mut term = pane::terminal(&Config::default()).unwrap();
|
let mut term = pane::terminal(&Config::default(), &theme::DEFAULT).unwrap();
|
||||||
let replies = Rc::new(RefCell::new(vec![]));
|
let replies = Rc::new(RefCell::new(vec![]));
|
||||||
let output = replies.clone();
|
let output = replies.clone();
|
||||||
term.on_pty_write(move |_, data| output.borrow_mut().extend_from_slice(data))
|
term.on_pty_write(move |_, data| output.borrow_mut().extend_from_slice(data))
|
||||||
@@ -137,10 +208,13 @@ fn kitty_images_decode_render_reuse_and_delete() {
|
|||||||
.paint(
|
.paint(
|
||||||
&term,
|
&term,
|
||||||
&painter,
|
&painter,
|
||||||
rect,
|
&render::Grid {
|
||||||
egui::vec2(8.0, 16.0),
|
rect,
|
||||||
&egui::FontId::monospace(12.0),
|
cell: egui::vec2(8.0, 16.0),
|
||||||
true,
|
font: &egui::FontId::monospace(12.0),
|
||||||
|
theme: &theme::DEFAULT,
|
||||||
|
active: true,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
})
|
})
|
||||||
@@ -173,7 +247,7 @@ fn pty_executes_input_and_bracketed_paste_is_sanitized() {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let ctx = egui::Context::default();
|
let ctx = egui::Context::default();
|
||||||
let mut pane = pane::Pane::new(&config, &ctx, None).unwrap();
|
let mut pane = pane::Pane::new(&config, &theme::DEFAULT, &ctx, None).unwrap();
|
||||||
pane.send(b"printf '\\033[31mpty-%s\\033[0m\\n' 'success'\r".to_vec())
|
pane.send(b"printf '\\033[31mpty-%s\\033[0m\\n' 'success'\r".to_vec())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let deadline = Instant::now() + Duration::from_secs(5);
|
let deadline = Instant::now() + Duration::from_secs(5);
|
||||||
@@ -216,7 +290,7 @@ fn new_panes_start_in_the_directory_of_the_pane_they_came_from() {
|
|||||||
let dir = std::env::temp_dir().join(format!("slerm cwd {}", std::process::id()));
|
let dir = std::env::temp_dir().join(format!("slerm cwd {}", std::process::id()));
|
||||||
std::fs::create_dir_all(&dir).unwrap();
|
std::fs::create_dir_all(&dir).unwrap();
|
||||||
let dir = dir.canonicalize().unwrap();
|
let dir = dir.canonicalize().unwrap();
|
||||||
let mut pane = pane::Pane::new(&config, &ctx, None).unwrap();
|
let mut pane = pane::Pane::new(&config, &theme::DEFAULT, &ctx, None).unwrap();
|
||||||
pane.send(format!("cd '{}'\r", dir.display()).into_bytes())
|
pane.send(format!("cd '{}'\r", dir.display()).into_bytes())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
// /bin/sh reports no OSC 7, so the directory has to come from the process.
|
// /bin/sh reports no OSC 7, so the directory has to come from the process.
|
||||||
@@ -227,7 +301,7 @@ fn new_panes_start_in_the_directory_of_the_pane_they_came_from() {
|
|||||||
}
|
}
|
||||||
assert_eq!(pane.cwd().as_deref(), Some(dir.as_path()));
|
assert_eq!(pane.cwd().as_deref(), Some(dir.as_path()));
|
||||||
|
|
||||||
let mut child = pane::Pane::new(&config, &ctx, pane.cwd().as_deref()).unwrap();
|
let mut child = pane::Pane::new(&config, &theme::DEFAULT, &ctx, pane.cwd().as_deref()).unwrap();
|
||||||
child
|
child
|
||||||
.send(b"printf 'at:%s\\n' \"$PWD\"\r".to_vec())
|
.send(b"printf 'at:%s\\n' \"$PWD\"\r".to_vec())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -251,7 +325,7 @@ fn osc7_wins_over_the_process_directory_but_only_for_this_machine() {
|
|||||||
let reported = std::env::temp_dir().join(format!("slerm osc7 {}", std::process::id()));
|
let reported = std::env::temp_dir().join(format!("slerm osc7 {}", std::process::id()));
|
||||||
std::fs::create_dir_all(&reported).unwrap();
|
std::fs::create_dir_all(&reported).unwrap();
|
||||||
let reported = reported.canonicalize().unwrap();
|
let reported = reported.canonicalize().unwrap();
|
||||||
let mut pane = pane::Pane::new(&config, &ctx, None).unwrap();
|
let mut pane = pane::Pane::new(&config, &theme::DEFAULT, &ctx, None).unwrap();
|
||||||
let process_cwd = pane.cwd().unwrap();
|
let process_cwd = pane.cwd().unwrap();
|
||||||
assert_ne!(process_cwd, reported);
|
assert_ne!(process_cwd, reported);
|
||||||
|
|
||||||
|
|||||||
+266
@@ -0,0 +1,266 @@
|
|||||||
|
use crate::themes::THEMES;
|
||||||
|
use anyhow::{Result, bail};
|
||||||
|
use egui::Color32;
|
||||||
|
use libghostty_vt::style::{Palette, PaletteIndex, RgbColor};
|
||||||
|
|
||||||
|
/// A packed `0xRRGGBB` color. Themes are compiled in, so they hold plain
|
||||||
|
/// integers rather than anything that needs allocating or parsing at startup.
|
||||||
|
pub type Rgb = u32;
|
||||||
|
|
||||||
|
/// Shared stroke width for pane borders and the default hollow cursor.
|
||||||
|
pub const BORDER_WIDTH: f32 = 1.0;
|
||||||
|
pub const CORNER_RADIUS: u8 = 5;
|
||||||
|
pub const CURSOR_CORNER_RADIUS: u8 = 2;
|
||||||
|
|
||||||
|
/// Every color slerm draws with. A theme covers the terminal grid, the sixteen
|
||||||
|
/// ANSI colors programs address by index, and the chrome around them, so that
|
||||||
|
/// picking a light theme does not leave a dark tab bar behind.
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
|
pub struct Theme {
|
||||||
|
/// Whether the chrome should be drawn as a dark or a light widget set.
|
||||||
|
pub dark: bool,
|
||||||
|
pub background: Rgb,
|
||||||
|
pub foreground: Rgb,
|
||||||
|
pub cursor: Rgb,
|
||||||
|
pub selection_bg: Rgb,
|
||||||
|
pub selection_fg: Rgb,
|
||||||
|
/// The focused pane: its border, its title and the cursor.
|
||||||
|
pub accent: Rgb,
|
||||||
|
/// The tab bar, menus and pane title bars.
|
||||||
|
pub chrome_bg: Rgb,
|
||||||
|
pub chrome_fg: Rgb,
|
||||||
|
/// The title bar of the focused pane.
|
||||||
|
pub chrome_active_bg: Rgb,
|
||||||
|
/// The border of an unfocused pane.
|
||||||
|
pub border: Rgb,
|
||||||
|
pub popup_bg: Rgb,
|
||||||
|
/// ANSI 0..=15: black, red, green, yellow, blue, magenta, cyan, white, then
|
||||||
|
/// the same eight again in their bright form.
|
||||||
|
pub ansi: [Rgb; 16],
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The name of slerm's own theme, which is what a config without a `theme` gets.
|
||||||
|
pub const DEFAULT_NAME: &str = "slerm";
|
||||||
|
|
||||||
|
/// slerm's own colors. The palette is libghostty's built-in one, so the default
|
||||||
|
/// look is exactly what the terminal renders with no theme applied at all.
|
||||||
|
pub const DEFAULT: Theme = Theme {
|
||||||
|
dark: true,
|
||||||
|
background: 0x17191c,
|
||||||
|
foreground: 0xe2e4e8,
|
||||||
|
cursor: 0x58c4ad,
|
||||||
|
selection_bg: 0x2f3d44,
|
||||||
|
selection_fg: 0xe2e4e8,
|
||||||
|
accent: 0x58c4ad,
|
||||||
|
chrome_bg: 0x1f2124,
|
||||||
|
chrome_fg: 0xa8adb5,
|
||||||
|
chrome_active_bg: 0x2b2e33,
|
||||||
|
border: 0x363636,
|
||||||
|
popup_bg: 0x1f2124,
|
||||||
|
ansi: [
|
||||||
|
0x1d1f21, 0xcc6666, 0xb5bd68, 0xf0c674, 0x81a2be, 0xb294bb, 0x8abeb7, 0xc5c8c6, 0x666666,
|
||||||
|
0xd54e53, 0xb9ca4a, 0xe7c547, 0x7aa6da, 0xc397d8, 0x70c0b1, 0xeaeaea,
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
/// The theme with this name, if there is one. slerm's own comes first; the rest
|
||||||
|
/// are the Helix themes, which `THEMES` keeps sorted for the binary search.
|
||||||
|
pub fn find(name: &str) -> Option<Theme> {
|
||||||
|
if name == DEFAULT_NAME {
|
||||||
|
return Some(DEFAULT);
|
||||||
|
}
|
||||||
|
let index = THEMES.binary_search_by_key(&name, |(name, _)| name).ok()?;
|
||||||
|
Some(THEMES[index].1)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Every theme name, in the order a picker should list them.
|
||||||
|
pub fn names() -> impl Iterator<Item = &'static str> {
|
||||||
|
std::iter::once(DEFAULT_NAME).chain(THEMES.iter().map(|(name, _)| *name))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn color(rgb: Rgb) -> Color32 {
|
||||||
|
Color32::from_rgb((rgb >> 16) as u8, (rgb >> 8) as u8, rgb as u8)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn rgb_color(rgb: Rgb) -> RgbColor {
|
||||||
|
RgbColor {
|
||||||
|
r: (rgb >> 16) as u8,
|
||||||
|
g: (rgb >> 8) as u8,
|
||||||
|
b: rgb as u8,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Where one of the names a config may override writes to.
|
||||||
|
type Field = fn(&mut Theme) -> &mut Rgb;
|
||||||
|
|
||||||
|
/// The names a config may override, paired with the field each one writes.
|
||||||
|
/// Ordered so that `[colors]` reads the way a palette is usually written.
|
||||||
|
const FIELDS: [(&str, Field); 27] = [
|
||||||
|
("background", |t| &mut t.background),
|
||||||
|
("foreground", |t| &mut t.foreground),
|
||||||
|
("cursor", |t| &mut t.cursor),
|
||||||
|
("selection_background", |t| &mut t.selection_bg),
|
||||||
|
("selection_foreground", |t| &mut t.selection_fg),
|
||||||
|
("accent", |t| &mut t.accent),
|
||||||
|
("chrome_background", |t| &mut t.chrome_bg),
|
||||||
|
("chrome_foreground", |t| &mut t.chrome_fg),
|
||||||
|
("chrome_active_background", |t| &mut t.chrome_active_bg),
|
||||||
|
("border", |t| &mut t.border),
|
||||||
|
("popup_background", |t| &mut t.popup_bg),
|
||||||
|
("black", |t| &mut t.ansi[0]),
|
||||||
|
("red", |t| &mut t.ansi[1]),
|
||||||
|
("green", |t| &mut t.ansi[2]),
|
||||||
|
("yellow", |t| &mut t.ansi[3]),
|
||||||
|
("blue", |t| &mut t.ansi[4]),
|
||||||
|
("magenta", |t| &mut t.ansi[5]),
|
||||||
|
("cyan", |t| &mut t.ansi[6]),
|
||||||
|
("white", |t| &mut t.ansi[7]),
|
||||||
|
("bright_black", |t| &mut t.ansi[8]),
|
||||||
|
("bright_red", |t| &mut t.ansi[9]),
|
||||||
|
("bright_green", |t| &mut t.ansi[10]),
|
||||||
|
("bright_yellow", |t| &mut t.ansi[11]),
|
||||||
|
("bright_blue", |t| &mut t.ansi[12]),
|
||||||
|
("bright_magenta", |t| &mut t.ansi[13]),
|
||||||
|
("bright_cyan", |t| &mut t.ansi[14]),
|
||||||
|
("bright_white", |t| &mut t.ansi[15]),
|
||||||
|
];
|
||||||
|
|
||||||
|
impl Theme {
|
||||||
|
/// Overrides one color by the name a config file uses for it.
|
||||||
|
pub fn set(&mut self, name: &str, value: Rgb) -> Result<()> {
|
||||||
|
let Some((_, field)) = FIELDS.iter().find(|(known, _)| *known == name) else {
|
||||||
|
bail!("unknown color: {name}");
|
||||||
|
};
|
||||||
|
*field(self) = value;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The 256-color palette a terminal renders indexed colors through. Only
|
||||||
|
/// the first sixteen are themed; the color cube and greyscale ramp above
|
||||||
|
/// them are fixed by the protocol, so they keep libghostty's values.
|
||||||
|
pub fn palette(&self, default: Palette) -> Palette {
|
||||||
|
const SLOTS: [PaletteIndex; 16] = [
|
||||||
|
PaletteIndex::BLACK,
|
||||||
|
PaletteIndex::RED,
|
||||||
|
PaletteIndex::GREEN,
|
||||||
|
PaletteIndex::YELLOW,
|
||||||
|
PaletteIndex::BLUE,
|
||||||
|
PaletteIndex::MAGENTA,
|
||||||
|
PaletteIndex::CYAN,
|
||||||
|
PaletteIndex::WHITE,
|
||||||
|
PaletteIndex::BRIGHT_BLACK,
|
||||||
|
PaletteIndex::BRIGHT_RED,
|
||||||
|
PaletteIndex::BRIGHT_GREEN,
|
||||||
|
PaletteIndex::BRIGHT_YELLOW,
|
||||||
|
PaletteIndex::BRIGHT_BLUE,
|
||||||
|
PaletteIndex::BRIGHT_MAGENTA,
|
||||||
|
PaletteIndex::BRIGHT_CYAN,
|
||||||
|
PaletteIndex::BRIGHT_WHITE,
|
||||||
|
];
|
||||||
|
let mut palette = default;
|
||||||
|
for (slot, rgb) in SLOTS.into_iter().zip(self.ansi) {
|
||||||
|
palette.set(slot, rgb_color(rgb));
|
||||||
|
}
|
||||||
|
palette
|
||||||
|
}
|
||||||
|
|
||||||
|
/// egui's widget colors, so that the tab bar, menus and buttons follow the
|
||||||
|
/// theme rather than staying on egui's own dark palette.
|
||||||
|
pub fn visuals(&self) -> egui::Visuals {
|
||||||
|
let mut visuals = if self.dark {
|
||||||
|
egui::Visuals::dark()
|
||||||
|
} else {
|
||||||
|
egui::Visuals::light()
|
||||||
|
};
|
||||||
|
let (chrome, accent, text) = (
|
||||||
|
color(self.chrome_bg),
|
||||||
|
color(self.accent),
|
||||||
|
color(self.chrome_fg),
|
||||||
|
);
|
||||||
|
let widgets = &mut visuals.widgets;
|
||||||
|
widgets.noninteractive.bg_fill = chrome;
|
||||||
|
widgets.noninteractive.weak_bg_fill = chrome;
|
||||||
|
widgets.noninteractive.fg_stroke = egui::Stroke::new(1.0_f32, text);
|
||||||
|
widgets.noninteractive.bg_stroke = egui::Stroke::new(1.0_f32, color(self.border));
|
||||||
|
for widget in [
|
||||||
|
&mut widgets.inactive,
|
||||||
|
&mut widgets.hovered,
|
||||||
|
&mut widgets.active,
|
||||||
|
&mut widgets.open,
|
||||||
|
] {
|
||||||
|
widget.bg_fill = color(self.chrome_active_bg);
|
||||||
|
widget.weak_bg_fill = color(self.chrome_active_bg);
|
||||||
|
widget.fg_stroke = egui::Stroke::new(1.0_f32, color(self.foreground));
|
||||||
|
widget.bg_stroke = egui::Stroke::new(1.0_f32, color(self.border));
|
||||||
|
}
|
||||||
|
widgets.hovered.weak_bg_fill = color(self.selection_bg);
|
||||||
|
widgets.active.weak_bg_fill = color(self.selection_bg);
|
||||||
|
widgets.active.fg_stroke = egui::Stroke::new(1.0_f32, accent);
|
||||||
|
visuals.panel_fill = chrome;
|
||||||
|
visuals.window_fill = color(self.popup_bg);
|
||||||
|
visuals.extreme_bg_color = color(self.background);
|
||||||
|
visuals.selection.bg_fill = color(self.selection_bg);
|
||||||
|
visuals.selection.stroke = egui::Stroke::new(1.0_f32, accent);
|
||||||
|
visuals.hyperlink_color = accent;
|
||||||
|
visuals.window_stroke = egui::Stroke::new(1.0_f32, color(self.border));
|
||||||
|
visuals
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn every_helix_theme_is_present_sorted_and_legible() {
|
||||||
|
assert!(THEMES.len() > 150, "expected the full Helix theme set");
|
||||||
|
assert!(
|
||||||
|
THEMES.windows(2).all(|w| w[0].0 < w[1].0),
|
||||||
|
"THEMES must be sorted for find() to binary search it"
|
||||||
|
);
|
||||||
|
for name in ["catppuccin_mocha", "gruvbox", "nord", "onedark", "dracula"] {
|
||||||
|
assert!(find(name).is_some(), "missing {name}");
|
||||||
|
}
|
||||||
|
assert_eq!(find(DEFAULT_NAME), Some(DEFAULT));
|
||||||
|
assert_eq!(find("no such theme"), None);
|
||||||
|
assert_eq!(names().count(), THEMES.len() + 1);
|
||||||
|
|
||||||
|
// A theme whose text matches its background, or whose palette collapses
|
||||||
|
// onto one color, would render an unusable terminal.
|
||||||
|
for (name, theme) in THEMES {
|
||||||
|
let luma = |rgb: Rgb| {
|
||||||
|
let channel = |shift: u32| ((rgb >> shift) & 0xff) as f32 / 255.0;
|
||||||
|
0.2126 * channel(16) + 0.7152 * channel(8) + 0.0722 * channel(0)
|
||||||
|
};
|
||||||
|
assert!(
|
||||||
|
(luma(theme.foreground) - luma(theme.background)).abs() > 0.15,
|
||||||
|
"{name}: text is not readable on its background"
|
||||||
|
);
|
||||||
|
assert_eq!(theme.dark, luma(theme.background) < luma(theme.foreground));
|
||||||
|
// Themes built on three or four colors (acme, vesper) reuse them
|
||||||
|
// across slots; anything flatter than that has lost its palette.
|
||||||
|
let distinct: std::collections::BTreeSet<_> = theme.ansi.iter().collect();
|
||||||
|
assert!(distinct.len() >= 9, "{name}: palette is too flat");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn overrides_are_named_and_reach_the_palette() {
|
||||||
|
let mut theme = DEFAULT;
|
||||||
|
theme.set("red", 0x123456).unwrap();
|
||||||
|
theme.set("bright_white", 0xfedcba).unwrap();
|
||||||
|
theme.set("accent", 0x00ff00).unwrap();
|
||||||
|
assert_eq!(theme.ansi[1], 0x123456);
|
||||||
|
assert_eq!(theme.ansi[15], 0xfedcba);
|
||||||
|
assert_eq!(theme.accent, 0x00ff00);
|
||||||
|
for unknown in ["dark", "purple", "ansi", ""] {
|
||||||
|
assert!(theme.set(unknown, 0).is_err(), "accepted {unknown}");
|
||||||
|
}
|
||||||
|
|
||||||
|
let palette = theme.palette(Palette([RgbColor { r: 0, g: 0, b: 0 }; 256]));
|
||||||
|
assert_eq!(palette.get(PaletteIndex::RED), rgb_color(0x123456));
|
||||||
|
assert_eq!(palette.get(PaletteIndex::BRIGHT_WHITE), rgb_color(0xfedcba));
|
||||||
|
// Everything above the sixteen named slots is left as it was.
|
||||||
|
assert_eq!(palette.0[16], RgbColor { r: 0, g: 0, b: 0 });
|
||||||
|
}
|
||||||
|
}
|
||||||
+3623
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,22 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2025 Daniel Fichtinger
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2021 James Simpson
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2016 CloudCannon
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2021 Aaron Young
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2025 NTBBloodbath
|
||||||
|
|
||||||
|
This theme has been ported by spentbliss <zyhkekrz.hatbox475@passinbox.com>.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2019 sainnhe
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2025 Strash
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2025 Alex Barnett
|
||||||
|
|
||||||
|
This theme has been ported by spentbliss <zyhkekrz.hatbox475@passinbox.com>.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Copyright (C) 2020-2023 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with the Front-Cover Texts being “A GNU Manual,” and with the Back-Cover Texts as in (a) below. A copy of the license is included in the section entitled “GNU Free Documentation License.”
|
||||||
|
|
||||||
|
(a) The FSF’s Back-Cover Text is: “You have the freedom to copy and modify this GNU manual.”
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Copyright (C) 2020-2023 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with the Front-Cover Texts being “A GNU Manual,” and with the Back-Cover Texts as in (a) below. A copy of the license is included in the section entitled “GNU Free Documentation License.”
|
||||||
|
|
||||||
|
(a) The FSF’s Back-Cover Text is: “You have the freedom to copy and modify this GNU manual.”
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Copyright (C) 2020-2023 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with the Front-Cover Texts being “A GNU Manual,” and with the Back-Cover Texts as in (a) below. A copy of the license is included in the section entitled “GNU Free Documentation License.”
|
||||||
|
|
||||||
|
(a) The FSF’s Back-Cover Text is: “You have the freedom to copy and modify this GNU manual.”
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Copyright (C) 2020-2023 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with the Front-Cover Texts being “A GNU Manual,” and with the Back-Cover Texts as in (a) below. A copy of the license is included in the section entitled “GNU Free Documentation License.”
|
||||||
|
|
||||||
|
(a) The FSF’s Back-Cover Text is: “You have the freedom to copy and modify this GNU manual.”
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2023 drcmda
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2018 arturoalviar
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2020 sainnhe
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
This is free and unencumbered software released into the public domain.
|
||||||
|
|
||||||
|
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||||
|
distribute this software, either in source code form or as a compiled
|
||||||
|
binary, for any purpose, commercial or non-commercial, and by any
|
||||||
|
means.
|
||||||
|
|
||||||
|
In jurisdictions that recognize copyright laws, the author or authors
|
||||||
|
of this software dedicate any and all copyright interest in the
|
||||||
|
software to the public domain. We make this dedication for the benefit
|
||||||
|
of the public at large and to the detriment of our heirs and
|
||||||
|
successors. We intend this dedication to be an overt act of
|
||||||
|
relinquishment in perpetuity of all present and future rights to this
|
||||||
|
software under copyright law.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
For more information, please refer to <https://unlicense.org>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2023 Rauno Freiberg
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
Reference in New Issue
Block a user