Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8157793282 | ||
|
|
a1816a0838 | ||
|
|
e01b0616b1 | ||
|
|
74d8d3c37a | ||
|
|
cc9b027bd1 |
@@ -22,7 +22,8 @@ use std::collections::BTreeMap;
|
|||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::de::Error as _;
|
||||||
|
use serde::{Deserialize, Deserializer};
|
||||||
|
|
||||||
/// Directory name under `$XDG_CONFIG_HOME` (default `~/.config`).
|
/// Directory name under `$XDG_CONFIG_HOME` (default `~/.config`).
|
||||||
pub const DIR_NAME: &str = "maestro";
|
pub const DIR_NAME: &str = "maestro";
|
||||||
@@ -146,11 +147,14 @@ pub struct WebSection {
|
|||||||
|
|
||||||
/// `[tui]` — `maestro tui` settings (NAP-275 epic, phase 2 NAP-277).
|
/// `[tui]` — `maestro tui` settings (NAP-275 epic, phase 2 NAP-277).
|
||||||
///
|
///
|
||||||
/// Leader key, chord timeout, and per-mode keymap overrides. The TUI ships
|
/// Theme, leader key, chord timeout, and per-mode keymap overrides. The TUI
|
||||||
/// with a default keymap; entries in `keymap_normal` / `keymap_insert` are
|
/// ships with a default keymap; entries in `keymap_normal` / `keymap_insert`
|
||||||
/// applied **over** the defaults, so a partial override is enough.
|
/// are applied **over** the defaults, so a partial override is enough.
|
||||||
#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize)]
|
||||||
pub struct TuiSection {
|
pub struct TuiSection {
|
||||||
|
/// Named palette preset. Defaults to the dark preset.
|
||||||
|
#[serde(default, deserialize_with = "deserialize_theme")]
|
||||||
|
pub theme: Option<TuiTheme>,
|
||||||
/// Canonical key form, e.g. `"ctrl-a"`. Default `ctrl-a`.
|
/// Canonical key form, e.g. `"ctrl-a"`. Default `ctrl-a`.
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub leader: Option<String>,
|
pub leader: Option<String>,
|
||||||
@@ -167,6 +171,33 @@ pub struct TuiSection {
|
|||||||
pub keymap_insert: BTreeMap<String, String>,
|
pub keymap_insert: BTreeMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Palette presets supported by the TUI's `[tui].theme` setting.
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub enum TuiTheme {
|
||||||
|
/// The terminal-native dark palette and the default.
|
||||||
|
Dark,
|
||||||
|
/// A high-contrast light palette.
|
||||||
|
Light,
|
||||||
|
/// Named ANSI colours, allowing the terminal to provide the colour set.
|
||||||
|
Ansi,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_theme<'de, D>(deserializer: D) -> Result<Option<TuiTheme>, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let raw = Option::<String>::deserialize(deserializer)?;
|
||||||
|
raw.map(|name| match name.as_str() {
|
||||||
|
"dark" => Ok(TuiTheme::Dark),
|
||||||
|
"light" => Ok(TuiTheme::Light),
|
||||||
|
"ansi" => Ok(TuiTheme::Ansi),
|
||||||
|
_ => Err(D::Error::custom(format!(
|
||||||
|
"invalid [tui].theme {name:?}; expected \"dark\", \"light\", or \"ansi\""
|
||||||
|
))),
|
||||||
|
})
|
||||||
|
.transpose()
|
||||||
|
}
|
||||||
|
|
||||||
/// `[spawn]` — command presets for the spawn form (#22, part of #21).
|
/// `[spawn]` — command presets for the spawn form (#22, part of #21).
|
||||||
///
|
///
|
||||||
/// Defined in shared config so every binary sees the same list: the web reads
|
/// Defined in shared config so every binary sees the same list: the web reads
|
||||||
@@ -596,6 +627,30 @@ bind_addr = "127.0.0.1:9090"
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tui_theme_parses_named_presets_and_defaults_when_absent() {
|
||||||
|
assert_eq!(TuiSection::default().theme, None);
|
||||||
|
let cfg = file_with("[tui]\ntheme = \"light\"\n");
|
||||||
|
assert_eq!(cfg.tui.theme, Some(TuiTheme::Light));
|
||||||
|
let cfg = file_with("[tui]\ntheme = \"ansi\"\n");
|
||||||
|
assert_eq!(cfg.tui.theme, Some(TuiTheme::Ansi));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tui_theme_rejects_unknown_names_with_the_field_name() {
|
||||||
|
let err =
|
||||||
|
toml::from_str::<MaestroConfigFile>("[tui]\ntheme = \"solarized\"\n").unwrap_err();
|
||||||
|
let message = err.to_string();
|
||||||
|
assert!(
|
||||||
|
message.contains("[tui].theme"),
|
||||||
|
"diagnostic should name the field: {message}"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
message.contains("solarized"),
|
||||||
|
"diagnostic should name the invalid value: {message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
fn file_with(body: &str) -> MaestroConfigFile {
|
fn file_with(body: &str) -> MaestroConfigFile {
|
||||||
toml::from_str(body).expect("parse")
|
toml::from_str(body).expect("parse")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,13 +8,15 @@
|
|||||||
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use maestro_config::TuiSection;
|
use maestro_config::{TuiSection, TuiTheme};
|
||||||
|
|
||||||
use crate::input::InputKey;
|
use crate::input::InputKey;
|
||||||
use crate::keymap::{Keymap, KeymapError, Mode};
|
use crate::keymap::{Keymap, KeymapError, Mode};
|
||||||
|
use crate::palette::Palette;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TuiConfig {
|
pub struct TuiConfig {
|
||||||
|
pub palette: Palette,
|
||||||
pub leader: InputKey,
|
pub leader: InputKey,
|
||||||
pub chord_timeout: Duration,
|
pub chord_timeout: Duration,
|
||||||
pub keymap: Keymap,
|
pub keymap: Keymap,
|
||||||
@@ -76,6 +78,11 @@ impl TuiConfig {
|
|||||||
/// field of the loaded `MaestroConfigFile`). The shipped defaults are
|
/// field of the loaded `MaestroConfigFile`). The shipped defaults are
|
||||||
/// applied first, then user overrides on top.
|
/// applied first, then user overrides on top.
|
||||||
pub fn load(section: &TuiSection) -> Result<Self, TuiConfigError> {
|
pub fn load(section: &TuiSection) -> Result<Self, TuiConfigError> {
|
||||||
|
let palette = match section.theme.unwrap_or(TuiTheme::Dark) {
|
||||||
|
TuiTheme::Dark => Palette::DARK,
|
||||||
|
TuiTheme::Light => Palette::LIGHT,
|
||||||
|
TuiTheme::Ansi => Palette::ANSI,
|
||||||
|
};
|
||||||
let leader_str = section.leader.as_deref().unwrap_or("ctrl-a");
|
let leader_str = section.leader.as_deref().unwrap_or("ctrl-a");
|
||||||
let leader = InputKey::parse(leader_str)
|
let leader = InputKey::parse(leader_str)
|
||||||
.map_err(|_| TuiConfigError::BadLeader(leader_str.to_string()))?;
|
.map_err(|_| TuiConfigError::BadLeader(leader_str.to_string()))?;
|
||||||
@@ -131,6 +138,7 @@ impl TuiConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(TuiConfig {
|
Ok(TuiConfig {
|
||||||
|
palette,
|
||||||
leader,
|
leader,
|
||||||
chord_timeout,
|
chord_timeout,
|
||||||
keymap,
|
keymap,
|
||||||
@@ -143,6 +151,28 @@ impl TuiConfig {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::action::Action;
|
use crate::action::Action;
|
||||||
|
use maestro_config::{TuiSection, TuiTheme};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn absent_theme_selects_the_dark_default() {
|
||||||
|
let cfg = TuiConfig::load(&TuiSection::default()).unwrap();
|
||||||
|
assert_eq!(cfg.palette, Palette::DARK);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn named_themes_select_the_matching_complete_palette() {
|
||||||
|
for (theme, expected) in [
|
||||||
|
(TuiTheme::Dark, Palette::DARK),
|
||||||
|
(TuiTheme::Light, Palette::LIGHT),
|
||||||
|
(TuiTheme::Ansi, Palette::ANSI),
|
||||||
|
] {
|
||||||
|
let section = TuiSection {
|
||||||
|
theme: Some(theme),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
assert_eq!(TuiConfig::load(§ion).unwrap().palette, expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn defaults_cover_core_actions() {
|
fn defaults_cover_core_actions() {
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ pub async fn run(cfg: RunConfig) -> Result<(), TuiError> {
|
|||||||
Err(_) => maestro_config::MaestroConfigFile::default(),
|
Err(_) => maestro_config::MaestroConfigFile::default(),
|
||||||
};
|
};
|
||||||
let tui_cfg = TuiConfig::load(&cfg_file.tui).map_err(|e| TuiError::Config(e.to_string()))?;
|
let tui_cfg = TuiConfig::load(&cfg_file.tui).map_err(|e| TuiError::Config(e.to_string()))?;
|
||||||
|
palette::set_active(tui_cfg.palette);
|
||||||
|
|
||||||
let catalog = CatalogStore::default();
|
let catalog = CatalogStore::default();
|
||||||
let ws_url = daemon
|
let ws_url = daemon
|
||||||
|
|||||||
@@ -16,9 +16,8 @@
|
|||||||
//! the selected card uses the selection surface's own state colours; the dot
|
//! the selected card uses the selection surface's own state colours; the dot
|
||||||
//! keeps carrying the state either way (docs/SIDEBAR.md).
|
//! keeps carrying the state either way (docs/SIDEBAR.md).
|
||||||
//!
|
//!
|
||||||
//! One palette ships today, reached through [`active`]. Selecting between
|
//! [`Palette::DARK`] is the default. [`Palette::LIGHT`] is its light peer and
|
||||||
//! presets from config is a separate issue; [`active`] is the seam it
|
//! [`Palette::ANSI`] uses terminal-provided ANSI colours.
|
||||||
//! replaces.
|
|
||||||
//!
|
//!
|
||||||
//! Out of scope: PTY cell colours. Those belong to the program running in the
|
//! Out of scope: PTY cell colours. Those belong to the program running in the
|
||||||
//! pane and pass through `pane::translate_color` verbatim.
|
//! pane and pass through `pane::translate_color` verbatim.
|
||||||
@@ -130,40 +129,162 @@ pub struct Palette {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Palette {
|
impl Palette {
|
||||||
/// The one palette that ships today.
|
/// The dark terminal-native palette and the default preset.
|
||||||
pub const DEFAULT: Palette = Palette {
|
pub const DARK: Palette = Palette {
|
||||||
card: Surface {
|
card: Surface {
|
||||||
bg: Color::Rgb(0x14, 0x16, 0x1b),
|
bg: Color::Rgb(0x1f, 0x23, 0x2b),
|
||||||
fg: Color::Rgb(0xd6, 0xdc, 0xe5),
|
fg: Color::Rgb(0xe5, 0xe7, 0xeb),
|
||||||
muted: Color::Rgb(0x9a, 0xa3, 0xb2),
|
muted: Color::Rgb(0xae, 0xb7, 0xc4),
|
||||||
dim: Color::Rgb(0x6b, 0x72, 0x80),
|
dim: Color::Rgb(0x85, 0x8f, 0x9e),
|
||||||
active: Color::Rgb(0x3f, 0xb9, 0x50),
|
active: Color::Rgb(0x72, 0xd6, 0x87),
|
||||||
idle: Color::Rgb(0x8b, 0x94, 0x9e),
|
idle: Color::Rgb(0xae, 0xb7, 0xc4),
|
||||||
awaiting: Color::Rgb(0xd2, 0x99, 0x22),
|
awaiting: Color::Rgb(0xf2, 0xc9, 0x5c),
|
||||||
error: Color::Rgb(0xf8, 0x51, 0x49),
|
error: Color::Rgb(0xff, 0x82, 0x7a),
|
||||||
},
|
},
|
||||||
selection: Surface {
|
selection: Surface {
|
||||||
bg: Color::Rgb(0x2b, 0x3f, 0x6e),
|
bg: Color::Rgb(0x3d, 0x51, 0x44),
|
||||||
fg: Color::Rgb(0xf0, 0xf4, 0xfa),
|
fg: Color::Rgb(0xf3, 0xf7, 0xf4),
|
||||||
muted: Color::Rgb(0xc0, 0xc9, 0xda),
|
muted: Color::Rgb(0xd0, 0xd9, 0xd3),
|
||||||
dim: Color::Rgb(0x93, 0xa0, 0xbc),
|
dim: Color::Rgb(0xa1, 0xb0, 0xa6),
|
||||||
active: Color::Rgb(0x7e, 0xe7, 0x87),
|
active: Color::Rgb(0x9a, 0xf0, 0xa6),
|
||||||
idle: Color::Rgb(0xb6, 0xc0, 0xd4),
|
idle: Color::Rgb(0xc4, 0xcf, 0xc7),
|
||||||
awaiting: Color::Rgb(0xf2, 0xcc, 0x60),
|
awaiting: Color::Rgb(0xf6, 0xd9, 0x78),
|
||||||
error: Color::Rgb(0xff, 0x94, 0x92),
|
error: Color::Rgb(0xff, 0xa8, 0xa3),
|
||||||
},
|
},
|
||||||
chrome_bg: Color::Rgb(0x14, 0x16, 0x1b),
|
chrome_bg: Color::Rgb(0x1f, 0x23, 0x2b),
|
||||||
border_focused: Color::Rgb(0x58, 0xa6, 0xff),
|
border_focused: Color::Rgb(0x72, 0xd6, 0x87),
|
||||||
border_unfocused: Color::Rgb(0x6b, 0x72, 0x80),
|
border_unfocused: Color::Rgb(0x68, 0x73, 0x84),
|
||||||
focus_accent: Color::Rgb(0x58, 0xa6, 0xff),
|
focus_accent: Color::Rgb(0x72, 0xd6, 0x87),
|
||||||
group_row: Color::Rgb(0x8f, 0xa3, 0xc8),
|
group_row: Color::Rgb(0xb6, 0xc1, 0xd3),
|
||||||
mode_normal_bg: Color::Rgb(0x58, 0xa6, 0xff),
|
mode_normal_bg: Color::Rgb(0x72, 0xd6, 0x87),
|
||||||
mode_normal_fg: Color::Rgb(0x0b, 0x0d, 0x11),
|
mode_normal_fg: Color::Rgb(0x1f, 0x23, 0x2b),
|
||||||
mode_insert_bg: Color::Rgb(0xd2, 0x99, 0x22),
|
mode_insert_bg: Color::Rgb(0xf2, 0xc9, 0x5c),
|
||||||
mode_insert_fg: Color::Rgb(0x0b, 0x0d, 0x11),
|
mode_insert_fg: Color::Rgb(0x1f, 0x23, 0x2b),
|
||||||
error_text: Color::Rgb(0xf8, 0x51, 0x49),
|
error_text: Color::Rgb(0xff, 0x82, 0x7a),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// A high-contrast light peer to [`Self::DARK`].
|
||||||
|
pub const LIGHT: Palette = Palette {
|
||||||
|
card: Surface {
|
||||||
|
bg: Color::Rgb(0xff, 0xff, 0xff),
|
||||||
|
fg: Color::Rgb(0x27, 0x31, 0x3d),
|
||||||
|
muted: Color::Rgb(0x4c, 0x5b, 0x6b),
|
||||||
|
dim: Color::Rgb(0x68, 0x78, 0x8a),
|
||||||
|
active: Color::Rgb(0x21, 0x7a, 0x3c),
|
||||||
|
idle: Color::Rgb(0x4c, 0x5b, 0x6b),
|
||||||
|
awaiting: Color::Rgb(0x8f, 0x63, 0x00),
|
||||||
|
error: Color::Rgb(0xb4, 0x23, 0x18),
|
||||||
|
},
|
||||||
|
selection: Surface {
|
||||||
|
bg: Color::Rgb(0xb5, 0xcf, 0xba),
|
||||||
|
fg: Color::Rgb(0x1d, 0x2a, 0x24),
|
||||||
|
muted: Color::Rgb(0x3f, 0x55, 0x45),
|
||||||
|
dim: Color::Rgb(0x52, 0x68, 0x5a),
|
||||||
|
active: Color::Rgb(0x15, 0x5b, 0x2e),
|
||||||
|
idle: Color::Rgb(0x3f, 0x55, 0x45),
|
||||||
|
awaiting: Color::Rgb(0x69, 0x46, 0x00),
|
||||||
|
error: Color::Rgb(0xa5, 0x1d, 0x14),
|
||||||
|
},
|
||||||
|
chrome_bg: Color::Rgb(0xff, 0xff, 0xff),
|
||||||
|
border_focused: Color::Rgb(0x21, 0x7a, 0x3c),
|
||||||
|
border_unfocused: Color::Rgb(0x65, 0x73, 0x6b),
|
||||||
|
focus_accent: Color::Rgb(0x21, 0x7a, 0x3c),
|
||||||
|
group_row: Color::Rgb(0x3f, 0x55, 0x45),
|
||||||
|
mode_normal_bg: Color::Rgb(0x21, 0x7a, 0x3c),
|
||||||
|
mode_normal_fg: Color::Rgb(0xff, 0xff, 0xff),
|
||||||
|
mode_insert_bg: Color::Rgb(0xb6, 0x81, 0x08),
|
||||||
|
mode_insert_fg: Color::Rgb(0x0b, 0x12, 0x0e),
|
||||||
|
error_text: Color::Rgb(0xb4, 0x23, 0x18),
|
||||||
|
};
|
||||||
|
|
||||||
|
/// A palette of named ANSI colours for terminals without truecolour.
|
||||||
|
pub const ANSI: Palette = Palette {
|
||||||
|
card: Surface {
|
||||||
|
bg: Color::Black,
|
||||||
|
fg: Color::White,
|
||||||
|
muted: Color::Gray,
|
||||||
|
dim: Color::DarkGray,
|
||||||
|
active: Color::Green,
|
||||||
|
idle: Color::Gray,
|
||||||
|
awaiting: Color::Yellow,
|
||||||
|
error: Color::Red,
|
||||||
|
},
|
||||||
|
selection: Surface {
|
||||||
|
bg: Color::Blue,
|
||||||
|
fg: Color::White,
|
||||||
|
muted: Color::White,
|
||||||
|
dim: Color::LightBlue,
|
||||||
|
active: Color::LightGreen,
|
||||||
|
idle: Color::White,
|
||||||
|
awaiting: Color::LightYellow,
|
||||||
|
error: Color::LightRed,
|
||||||
|
},
|
||||||
|
chrome_bg: Color::Black,
|
||||||
|
border_focused: Color::LightGreen,
|
||||||
|
border_unfocused: Color::DarkGray,
|
||||||
|
focus_accent: Color::LightGreen,
|
||||||
|
group_row: Color::LightCyan,
|
||||||
|
mode_normal_bg: Color::Green,
|
||||||
|
mode_normal_fg: Color::Black,
|
||||||
|
mode_insert_bg: Color::Yellow,
|
||||||
|
mode_insert_fg: Color::Black,
|
||||||
|
error_text: Color::LightRed,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// The default preset, retained as a named compatibility constant.
|
||||||
|
pub const DEFAULT: Palette = Self::DARK;
|
||||||
|
|
||||||
|
/// All preset names and their complete palettes.
|
||||||
|
pub fn presets() -> [(&'static str, Palette); 3] {
|
||||||
|
[
|
||||||
|
("dark", Self::DARK),
|
||||||
|
("light", Self::LIGHT),
|
||||||
|
("ansi", Self::ANSI),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Resolve a config name to a palette.
|
||||||
|
pub fn named(name: &str) -> Option<Palette> {
|
||||||
|
match name {
|
||||||
|
"dark" => Some(Self::DARK),
|
||||||
|
"light" => Some(Self::LIGHT),
|
||||||
|
"ansi" => Some(Self::ANSI),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Every role, including the backgrounds it is painted against.
|
||||||
|
pub fn roles(&self) -> [(&'static str, Color); 26] {
|
||||||
|
[
|
||||||
|
("card.bg", self.card.bg),
|
||||||
|
("card.fg", self.card.fg),
|
||||||
|
("card.muted", self.card.muted),
|
||||||
|
("card.dim", self.card.dim),
|
||||||
|
("card.active", self.card.active),
|
||||||
|
("card.idle", self.card.idle),
|
||||||
|
("card.awaiting", self.card.awaiting),
|
||||||
|
("card.error", self.card.error),
|
||||||
|
("selection.bg", self.selection.bg),
|
||||||
|
("selection.fg", self.selection.fg),
|
||||||
|
("selection.muted", self.selection.muted),
|
||||||
|
("selection.dim", self.selection.dim),
|
||||||
|
("selection.active", self.selection.active),
|
||||||
|
("selection.idle", self.selection.idle),
|
||||||
|
("selection.awaiting", self.selection.awaiting),
|
||||||
|
("selection.error", self.selection.error),
|
||||||
|
("chrome_bg", self.chrome_bg),
|
||||||
|
("border_focused", self.border_focused),
|
||||||
|
("border_unfocused", self.border_unfocused),
|
||||||
|
("focus_accent", self.focus_accent),
|
||||||
|
("group_row", self.group_row),
|
||||||
|
("mode_normal_bg", self.mode_normal_bg),
|
||||||
|
("mode_normal_fg", self.mode_normal_fg),
|
||||||
|
("mode_insert_bg", self.mode_insert_bg),
|
||||||
|
("mode_insert_fg", self.mode_insert_fg),
|
||||||
|
("error_text", self.error_text),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
/// The surface a card sits on: the selection surface when it is the
|
/// The surface a card sits on: the selection surface when it is the
|
||||||
/// highlighted card, the card surface otherwise.
|
/// highlighted card, the card surface otherwise.
|
||||||
pub fn surface(&self, selected: bool) -> &Surface {
|
pub fn surface(&self, selected: bool) -> &Surface {
|
||||||
@@ -218,9 +339,20 @@ impl Default for Palette {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The palette in force. Config-driven preset selection lands here.
|
fn active_slot() -> &'static std::sync::RwLock<Palette> {
|
||||||
|
static ACTIVE: std::sync::OnceLock<std::sync::RwLock<Palette>> = std::sync::OnceLock::new();
|
||||||
|
ACTIVE.get_or_init(|| std::sync::RwLock::new(Palette::DEFAULT))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the palette used by the running TUI.
|
||||||
|
pub(crate) fn set_active(palette: Palette) {
|
||||||
|
*active_slot().write().expect("active palette lock poisoned") = palette;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The palette in force. Config-driven preset selection lands here at TUI
|
||||||
|
/// startup, before the first frame is drawn.
|
||||||
pub fn active() -> Palette {
|
pub fn active() -> Palette {
|
||||||
Palette::DEFAULT
|
*active_slot().read().expect("active palette lock poisoned")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// WCAG relative luminance of an RGB role. Non-RGB colours have no fixed
|
/// WCAG relative luminance of an RGB role. Non-RGB colours have no fixed
|
||||||
@@ -264,30 +396,43 @@ mod tests {
|
|||||||
/// decoration and only has to clear the 3:1 non-text threshold.
|
/// decoration and only has to clear the 3:1 non-text threshold.
|
||||||
#[test]
|
#[test]
|
||||||
fn every_role_is_legible_on_its_own_surface() {
|
fn every_role_is_legible_on_its_own_surface() {
|
||||||
let p = active();
|
for (preset, p) in [("dark", Palette::DARK), ("light", Palette::LIGHT)] {
|
||||||
for (name, surface) in [("card", &p.card), ("selection", &p.selection)] {
|
for (surface_name, surface) in [("card", &p.card), ("selection", &p.selection)] {
|
||||||
for (role, color) in surface.roles() {
|
for (role, color) in surface.roles() {
|
||||||
let ratio = contrast_ratio(surface.bg, color)
|
let ratio = contrast_ratio(surface.bg, color)
|
||||||
.unwrap_or_else(|| panic!("{name}.{role} must be an RGB value"));
|
.unwrap_or_else(|| panic!("{preset}.{surface_name}.{role} must be RGB"));
|
||||||
let floor = if role == "dim" { 3.0 } else { 4.5 };
|
let floor = if role == "dim" { 3.0 } else { 4.5 };
|
||||||
assert!(
|
assert!(
|
||||||
ratio >= floor,
|
ratio >= floor,
|
||||||
"{name}.{role} contrast {ratio:.2} is below {floor}"
|
"{preset}.{surface_name}.{role} contrast {ratio:.2} is below {floor}"
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn every_preset_supplies_every_role() {
|
||||||
|
for (name, p) in Palette::presets() {
|
||||||
|
assert_eq!(p.roles().len(), 26, "{name} role set is incomplete");
|
||||||
|
}
|
||||||
|
assert_eq!(Palette::named("dark"), Some(Palette::DARK));
|
||||||
|
assert_eq!(Palette::named("light"), Some(Palette::LIGHT));
|
||||||
|
assert_eq!(Palette::named("ansi"), Some(Palette::ANSI));
|
||||||
|
assert_eq!(Palette::named("unknown"), None);
|
||||||
|
}
|
||||||
|
|
||||||
/// The selection background exists to be seen as a different surface, not
|
/// The selection background exists to be seen as a different surface, not
|
||||||
/// merely a slightly different shade of the card.
|
/// merely a slightly different shade of the card.
|
||||||
#[test]
|
#[test]
|
||||||
fn selection_background_is_distinguishable_from_the_card_background() {
|
fn selection_background_is_distinguishable_from_the_card_background() {
|
||||||
let p = active();
|
for (name, p) in [("dark", Palette::DARK), ("light", Palette::LIGHT)] {
|
||||||
let ratio = contrast_ratio(p.card.bg, p.selection.bg).unwrap();
|
let ratio = contrast_ratio(p.card.bg, p.selection.bg).unwrap();
|
||||||
assert!(
|
assert!(
|
||||||
ratio >= 1.6,
|
ratio >= 1.6,
|
||||||
"card and selection backgrounds differ by only {ratio:.2}"
|
"{name} card and selection backgrounds differ by only {ratio:.2}"
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The bug this palette fixes: a state colour chosen for the dark card
|
/// The bug this palette fixes: a state colour chosen for the dark card
|
||||||
@@ -295,13 +440,14 @@ mod tests {
|
|||||||
/// selection surface carries its own — distinct — state colours.
|
/// selection surface carries its own — distinct — state colours.
|
||||||
#[test]
|
#[test]
|
||||||
fn selection_state_colours_are_not_the_card_state_colours() {
|
fn selection_state_colours_are_not_the_card_state_colours() {
|
||||||
let p = active();
|
for (name, p) in Palette::presets() {
|
||||||
for state in STATES {
|
for state in STATES {
|
||||||
assert_ne!(
|
assert_ne!(
|
||||||
p.card.activity(state),
|
p.card.activity(state),
|
||||||
p.selection.activity(state),
|
p.selection.activity(state),
|
||||||
"{state:?} must have a selection-specific colour"
|
"{name} {state:?} must have a selection-specific colour"
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,44 +456,37 @@ mod tests {
|
|||||||
/// actually painted on; they must never rely on the terminal default.
|
/// actually painted on; they must never rely on the terminal default.
|
||||||
#[test]
|
#[test]
|
||||||
fn chrome_roles_are_rgb_values() {
|
fn chrome_roles_are_rgb_values() {
|
||||||
let p = active();
|
for (preset, p) in [("dark", Palette::DARK), ("light", Palette::LIGHT)] {
|
||||||
for (name, color) in [
|
for (name, color) in p.roles().into_iter().skip(16) {
|
||||||
("chrome_bg", p.chrome_bg),
|
assert!(
|
||||||
("border_focused", p.border_focused),
|
relative_luminance(color).is_some(),
|
||||||
("border_unfocused", p.border_unfocused),
|
"{preset}.{name} must be an RGB value"
|
||||||
("focus_accent", p.focus_accent),
|
);
|
||||||
("group_row", p.group_row),
|
}
|
||||||
("mode_normal_bg", p.mode_normal_bg),
|
// The mode indicator paints fg on bg; both pairs must stay readable.
|
||||||
("mode_normal_fg", p.mode_normal_fg),
|
for (name, fg, bg) in [
|
||||||
("mode_insert_bg", p.mode_insert_bg),
|
("normal", p.mode_normal_fg, p.mode_normal_bg),
|
||||||
("mode_insert_fg", p.mode_insert_fg),
|
("insert", p.mode_insert_fg, p.mode_insert_bg),
|
||||||
("error_text", p.error_text),
|
] {
|
||||||
] {
|
let ratio = contrast_ratio(fg, bg).unwrap();
|
||||||
assert!(
|
assert!(
|
||||||
relative_luminance(color).is_some(),
|
ratio >= 4.5,
|
||||||
"{name} must be an RGB value"
|
"{preset} mode {name} contrast {ratio:.2} is below 4.5"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// The mode indicator paints fg on bg; both pairs must stay readable.
|
for (name, fg, floor) in [
|
||||||
for (name, fg, bg) in [
|
("border_focused", p.border_focused, 3.0),
|
||||||
("normal", p.mode_normal_fg, p.mode_normal_bg),
|
("border_unfocused", p.border_unfocused, 3.0),
|
||||||
("insert", p.mode_insert_fg, p.mode_insert_bg),
|
("focus_accent", p.focus_accent, 3.0),
|
||||||
] {
|
("group_row", p.group_row, 4.5),
|
||||||
let ratio = contrast_ratio(fg, bg).unwrap();
|
("error_text", p.error_text, 4.5),
|
||||||
assert!(ratio >= 4.5, "mode {name} contrast {ratio:.2} is below 4.5");
|
] {
|
||||||
}
|
let ratio = contrast_ratio(fg, p.chrome_bg).unwrap();
|
||||||
for (name, fg, floor) in [
|
assert!(
|
||||||
("border_focused", p.border_focused, 3.0),
|
ratio >= floor,
|
||||||
("border_unfocused", p.border_unfocused, 3.0),
|
"{preset}.{name} contrast {ratio:.2} is below {floor} on chrome_bg"
|
||||||
("focus_accent", p.focus_accent, 3.0),
|
);
|
||||||
("group_row", p.group_row, 4.5),
|
}
|
||||||
("error_text", p.error_text, 4.5),
|
|
||||||
] {
|
|
||||||
let ratio = contrast_ratio(fg, p.chrome_bg).unwrap();
|
|
||||||
assert!(
|
|
||||||
ratio >= floor,
|
|
||||||
"{name} contrast {ratio:.2} is below {floor} on chrome_bg"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
//!
|
//!
|
||||||
//! Line 1: status glyph (● attached / ○ live / ✗ dead) + name.
|
//! Line 1: status glyph (● attached / ○ live / ✗ dead) + name.
|
||||||
//! Line 2: activity dot + duration in the state's colour, plus the
|
//! Line 2: activity dot + duration in the state's colour, plus the
|
||||||
//! blocked-work and exited fragments when they apply. Absent entirely when
|
//! adaptive detail, blocked-work, exited, and command fragments.
|
||||||
//! it has nothing to say.
|
|
||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
@@ -18,8 +17,8 @@ use uuid::Uuid;
|
|||||||
|
|
||||||
use crate::palette;
|
use crate::palette;
|
||||||
|
|
||||||
/// Time-in-state alone earns a meta line only once the session has sat in
|
/// Time-in-state earns a duration fragment once the session has sat in its
|
||||||
/// its current activity state this long (docs/SIDEBAR.md).
|
/// current activity state this long (docs/SIDEBAR.md).
|
||||||
const META_LINE_AFTER_SECS: i64 = 30;
|
const META_LINE_AFTER_SECS: i64 = 30;
|
||||||
/// A payload predating #102 defaults `activity_since` to the Unix epoch. Per
|
/// A payload predating #102 defaults `activity_since` to the Unix epoch. Per
|
||||||
/// docs/SIDEBAR.md such a session contributes no duration — the dot still
|
/// docs/SIDEBAR.md such a session contributes no duration — the dot still
|
||||||
@@ -74,9 +73,8 @@ impl Sidebar {
|
|||||||
let highlighted = self.highlight == Some(s.id);
|
let highlighted = self.highlight == Some(s.id);
|
||||||
let base = card_base(highlighted);
|
let base = card_base(highlighted);
|
||||||
lines.push(Line::from(self.name_row(s, width)));
|
lines.push(Line::from(self.name_row(s, width)));
|
||||||
if let Some(meta) = self.meta_row(s, width) {
|
let meta = self.meta_row(s, width);
|
||||||
lines.push(Line::from(pad_to_width(meta, width, base)));
|
lines.push(Line::from(pad_to_width(meta, width, base)));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
f.render_widget(Paragraph::new(lines), inner);
|
f.render_widget(Paragraph::new(lines), inner);
|
||||||
}
|
}
|
||||||
@@ -123,8 +121,8 @@ impl Sidebar {
|
|||||||
spans
|
spans
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The adaptive second line: `<dot> <duration> [<blocked work> | exited]`.
|
/// The adaptive second line: `<dot> [<duration>] [<detail>] [<blocked work> | exited] <command>`.
|
||||||
fn meta_row(&self, s: &Session, width: usize) -> Option<Vec<Span<'static>>> {
|
fn meta_row(&self, s: &Session, width: usize) -> Vec<Span<'static>> {
|
||||||
let now = Utc::now();
|
let now = Utc::now();
|
||||||
let held = held_for(s, now);
|
let held = held_for(s, now);
|
||||||
let held_secs = held.map(|d| d.num_seconds()).unwrap_or(0);
|
let held_secs = held.map(|d| d.num_seconds()).unwrap_or(0);
|
||||||
@@ -132,14 +130,6 @@ impl Sidebar {
|
|||||||
// on line 1; the kill confirm names the specifics.
|
// on line 1; the kill confirm names the specifics.
|
||||||
let blocked = s.blocked_work.filter(|b| !b.is_clear());
|
let blocked = s.blocked_work.filter(|b| !b.is_clear());
|
||||||
let dead = s.status == SessionStatus::Dead;
|
let dead = s.status == SessionStatus::Dead;
|
||||||
let errored = s.activity == ActivityState::Error;
|
|
||||||
if (held.is_none() || held_secs < META_LINE_AFTER_SECS)
|
|
||||||
&& blocked.is_none()
|
|
||||||
&& !dead
|
|
||||||
&& !errored
|
|
||||||
{
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
let highlighted = self.highlight == Some(s.id);
|
let highlighted = self.highlight == Some(s.id);
|
||||||
let base = card_base(highlighted);
|
let base = card_base(highlighted);
|
||||||
let dot_style = base.patch(Style::default().fg(activity_color(s.activity, highlighted)));
|
let dot_style = base.patch(Style::default().fg(activity_color(s.activity, highlighted)));
|
||||||
@@ -148,13 +138,10 @@ impl Sidebar {
|
|||||||
Span::styled(META_INDENT, base),
|
Span::styled(META_INDENT, base),
|
||||||
Span::styled("●", dot_style),
|
Span::styled("●", dot_style),
|
||||||
];
|
];
|
||||||
if let Some(d) = held {
|
if let Some(d) = held.filter(|_| held_secs >= META_LINE_AFTER_SECS) {
|
||||||
spans.push(Span::styled(" ", base));
|
spans.push(Span::styled(" ", base));
|
||||||
spans.push(Span::styled(format_state_duration(d), dot_style));
|
spans.push(Span::styled(format_state_duration(d), dot_style));
|
||||||
}
|
}
|
||||||
// The trailing fragments are measured up front so a long detail
|
|
||||||
// truncates ahead of them instead of pushing them off the line
|
|
||||||
// (docs/SIDEBAR.md).
|
|
||||||
let mut tail: Vec<Span<'static>> = Vec::new();
|
let mut tail: Vec<Span<'static>> = Vec::new();
|
||||||
if let Some(b) = blocked {
|
if let Some(b) = blocked {
|
||||||
tail.push(Span::styled(format!(" ⚠ {b}"), muted));
|
tail.push(Span::styled(format!(" ⚠ {b}"), muted));
|
||||||
@@ -162,17 +149,29 @@ impl Sidebar {
|
|||||||
if dead {
|
if dead {
|
||||||
tail.push(Span::styled(" exited", muted));
|
tail.push(Span::styled(" exited", muted));
|
||||||
}
|
}
|
||||||
|
let command = Span::styled(format!(" {}", s.command), muted);
|
||||||
|
|
||||||
|
// Reserve the triggered status fragments before detail and command.
|
||||||
|
// If the row is exceptionally narrow, keep one column for the
|
||||||
|
// unconditional command and truncate the status tail first. Detail
|
||||||
|
// then receives only space left after the full command reservation;
|
||||||
|
// when the full command cannot fit, it is the final truncation target.
|
||||||
|
let head_w: usize = spans.iter().map(|sp| sp.width()).sum();
|
||||||
|
let available = width.saturating_sub(head_w);
|
||||||
|
let command_floor = usize::from(available > 0);
|
||||||
|
let tail = fit_to_width(tail, available.saturating_sub(command_floor));
|
||||||
|
let tail_w: usize = tail.iter().map(|sp| sp.width()).sum();
|
||||||
|
let command_w = command.width().min(available.saturating_sub(tail_w));
|
||||||
if let Some(detail) = s.activity_detail.as_deref().filter(|d| !d.is_empty()) {
|
if let Some(detail) = s.activity_detail.as_deref().filter(|d| !d.is_empty()) {
|
||||||
let head_w: usize = spans.iter().map(|sp| sp.width()).sum();
|
let budget = available.saturating_sub(tail_w + command_w);
|
||||||
let tail_w: usize = tail.iter().map(|sp| sp.width()).sum();
|
|
||||||
let budget = width.saturating_sub(head_w + tail_w);
|
|
||||||
spans.extend(fit_to_width(
|
spans.extend(fit_to_width(
|
||||||
vec![Span::styled(format!(" {detail}"), muted)],
|
vec![Span::styled(format!(" {detail}"), muted)],
|
||||||
budget,
|
budget,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
spans.extend(tail);
|
spans.extend(tail);
|
||||||
Some(fit_to_width(spans, width))
|
spans.extend(fit_to_width(vec![command], command_w));
|
||||||
|
spans
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,10 +405,10 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A freshly-active session stays one line — never an empty placeholder
|
/// A fresh session still gets its unconditional second line, but no
|
||||||
/// row (docs/SIDEBAR.md).
|
/// duration until it has been held in state for 30 seconds.
|
||||||
#[test]
|
#[test]
|
||||||
fn freshly_active_session_stays_one_line() {
|
fn fresh_session_renders_two_lines_without_duration() {
|
||||||
let mut s = session_named(1, "claude");
|
let mut s = session_named(1, "claude");
|
||||||
s.activity_since = Utc::now() - Duration::seconds(10);
|
s.activity_since = Utc::now() - Duration::seconds(10);
|
||||||
let sb = Sidebar {
|
let sb = Sidebar {
|
||||||
@@ -421,8 +420,18 @@ mod tests {
|
|||||||
assert_eq!(content(&all[0]), "sessions");
|
assert_eq!(content(&all[0]), "sessions");
|
||||||
assert!(row_containing(&all, "claude").contains('○'));
|
assert!(row_containing(&all, "claude").contains('○'));
|
||||||
assert!(
|
assert!(
|
||||||
content(&all[2]).is_empty(),
|
all[2].contains('●'),
|
||||||
"line 2 must be absent, got {:?}",
|
"line 2 must carry the dot: {:?}",
|
||||||
|
all[2]
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
all[2].contains("bash"),
|
||||||
|
"line 2 must carry the command: {:?}",
|
||||||
|
all[2]
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
!all[2].contains("10s"),
|
||||||
|
"fresh cards have no duration: {:?}",
|
||||||
all[2]
|
all[2]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -553,11 +562,12 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The sidebar is narrow: the meta line truncates with `…` and never
|
/// The sidebar is narrow: the command truncates with `…` and never wraps
|
||||||
/// wraps onto a third row (docs/SIDEBAR.md).
|
/// onto a third row (docs/SIDEBAR.md).
|
||||||
#[test]
|
#[test]
|
||||||
fn meta_line_truncates_instead_of_wrapping() {
|
fn meta_line_command_truncates_instead_of_wrapping() {
|
||||||
let mut s = session_named(1, "claude");
|
let mut s = session_named(1, "claude");
|
||||||
|
s.command = "a command that cannot fit".into();
|
||||||
s.activity_since = Utc::now() - Duration::seconds(5);
|
s.activity_since = Utc::now() - Duration::seconds(5);
|
||||||
s.blocked_work = Some(InTheWay {
|
s.blocked_work = Some(InTheWay {
|
||||||
uncommitted_files: 120,
|
uncommitted_files: 120,
|
||||||
@@ -573,7 +583,7 @@ mod tests {
|
|||||||
let meta = content(&all[idx + 1]);
|
let meta = content(&all[idx + 1]);
|
||||||
assert!(
|
assert!(
|
||||||
meta.trim_end().ends_with('…'),
|
meta.trim_end().ends_with('…'),
|
||||||
"truncated meta line must end with …: {meta:?}"
|
"truncated command must end with …: {meta:?}"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
content(&all[idx + 2]).trim().is_empty(),
|
content(&all[idx + 2]).trim().is_empty(),
|
||||||
@@ -688,10 +698,6 @@ mod tests {
|
|||||||
rendered.contains("exited"),
|
rendered.contains("exited"),
|
||||||
"dead session must still show line 2:\n{rendered}"
|
"dead session must still show line 2:\n{rendered}"
|
||||||
);
|
);
|
||||||
assert!(
|
|
||||||
!rendered.contains('h') || !rendered.contains("● "),
|
|
||||||
"no duration may follow the dot for an epoch stamp:\n{rendered}"
|
|
||||||
);
|
|
||||||
for line in rendered.lines().filter(|l| l.contains('●')) {
|
for line in rendered.lines().filter(|l| l.contains('●')) {
|
||||||
assert!(
|
assert!(
|
||||||
!line
|
!line
|
||||||
@@ -736,6 +742,90 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn command_renders_on_line_two_even_when_name_is_metadata() {
|
||||||
|
let s = session_named(1, "friendly name");
|
||||||
|
let sb = Sidebar {
|
||||||
|
sessions: vec![s],
|
||||||
|
highlight: None,
|
||||||
|
attached: Default::default(),
|
||||||
|
};
|
||||||
|
let all = rows(&draw(&sb, 40, 6));
|
||||||
|
assert!(
|
||||||
|
all[1].contains("friendly name"),
|
||||||
|
"name must stay on line 1: {:?}",
|
||||||
|
all[1]
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
all[2].contains("bash"),
|
||||||
|
"command must be on line 2: {:?}",
|
||||||
|
all[2]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn narrow_meta_line_keeps_dot_and_truncates_command() {
|
||||||
|
let s = session_named(1, "name");
|
||||||
|
let sb = Sidebar {
|
||||||
|
sessions: vec![s],
|
||||||
|
highlight: None,
|
||||||
|
attached: Default::default(),
|
||||||
|
};
|
||||||
|
let all = rows(&draw(&sb, 10, 6));
|
||||||
|
assert!(
|
||||||
|
all[2].contains('●'),
|
||||||
|
"dot must survive narrow cards: {:?}",
|
||||||
|
all[2]
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
all[2].contains('…'),
|
||||||
|
"command should truncate: {:?}",
|
||||||
|
all[2]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn blocked_warning_survives_before_a_truncated_command() {
|
||||||
|
let mut s = session_named(1, "name");
|
||||||
|
s.command = "a command that cannot fit".into();
|
||||||
|
s.blocked_work = Some(InTheWay {
|
||||||
|
uncommitted_files: 1,
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
let sb = Sidebar {
|
||||||
|
sessions: vec![s],
|
||||||
|
highlight: None,
|
||||||
|
attached: Default::default(),
|
||||||
|
};
|
||||||
|
let all = rows(&draw(&sb, 29, 6));
|
||||||
|
assert!(all[2].contains("⚠ 1 uncommitted file"), "{:?}", all[2]);
|
||||||
|
let meta = content(&all[2]);
|
||||||
|
assert!(meta.ends_with('…'), "command must truncate: {meta:?}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn long_detail_yields_to_status_and_command() {
|
||||||
|
let mut s = session_named(1, "name");
|
||||||
|
s.activity_detail = Some("a very long agent-reported detail".into());
|
||||||
|
s.blocked_work = Some(InTheWay {
|
||||||
|
uncommitted_files: 1,
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
let sb = Sidebar {
|
||||||
|
sessions: vec![s],
|
||||||
|
highlight: None,
|
||||||
|
attached: Default::default(),
|
||||||
|
};
|
||||||
|
let all = rows(&draw(&sb, 40, 6));
|
||||||
|
assert!(all[2].contains("⚠ 1 uncommitted file"), "{:?}", all[2]);
|
||||||
|
assert!(
|
||||||
|
all[2].contains("bash"),
|
||||||
|
"command must survive: {:?}",
|
||||||
|
all[2]
|
||||||
|
);
|
||||||
|
assert!(all[2].contains('…'), "detail must truncate: {:?}", all[2]);
|
||||||
|
}
|
||||||
|
|
||||||
/// Reversed video makes a card unreadable against a background; cards
|
/// Reversed video makes a card unreadable against a background; cards
|
||||||
/// use explicit backgrounds instead (docs/SIDEBAR.md, #108).
|
/// use explicit backgrounds instead (docs/SIDEBAR.md, #108).
|
||||||
#[test]
|
#[test]
|
||||||
@@ -775,7 +865,7 @@ mod tests {
|
|||||||
let buf = draw(&sb, 28, 8);
|
let buf = draw(&sb, 28, 8);
|
||||||
let all = rows(&buf);
|
let all = rows(&buf);
|
||||||
let claude_y = all.iter().position(|l| l.contains("claude")).unwrap();
|
let claude_y = all.iter().position(|l| l.contains("claude")).unwrap();
|
||||||
let bash_y = all.iter().position(|l| l.contains("bash")).unwrap();
|
let bash_y = all.iter().position(|l| l.contains("○ bash")).unwrap();
|
||||||
|
|
||||||
let p = palette::active();
|
let p = palette::active();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ cover every v1 action — only override what you want to change:
|
|||||||
|
|
||||||
```toml
|
```toml
|
||||||
[tui]
|
[tui]
|
||||||
|
theme = "dark" # dark (default), light, or ansi
|
||||||
leader = "ctrl-a" # one byte that escapes Insert mode
|
leader = "ctrl-a" # one byte that escapes Insert mode
|
||||||
chord_timeout_ms = 1000 # how long to hold a partial chord like `g`
|
chord_timeout_ms = 1000 # how long to hold a partial chord like `g`
|
||||||
|
|
||||||
@@ -152,6 +153,11 @@ chord_timeout_ms = 1000 # how long to hold a partial chord like `g`
|
|||||||
# want extra Insert-mode bindings)
|
# want extra Insert-mode bindings)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`theme` selects the complete TUI palette. `dark` is the default and follows
|
||||||
|
Maestro's terminal-native dark product palette; `light` is its light peer;
|
||||||
|
`ansi` uses the terminal's named ANSI colours for terminals without truecolour.
|
||||||
|
An unknown name is rejected as an `[tui].theme` configuration error.
|
||||||
|
|
||||||
The full action vocabulary is the `Action` enum in
|
The full action vocabulary is the `Action` enum in
|
||||||
`crates/maestro-tui/src/action.rs`.
|
`crates/maestro-tui/src/action.rs`.
|
||||||
|
|
||||||
|
|||||||
+11
-2
@@ -791,7 +791,8 @@ textarea {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
gap: 1px;
|
gap: 1px;
|
||||||
height: 40px;
|
/* 24px action row + 16px meta row + 1px gap + 8px vertical padding. */
|
||||||
|
height: 49px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.card-line1 {
|
.card-line1 {
|
||||||
@@ -854,7 +855,8 @@ textarea {
|
|||||||
ellipsis so it never pushes the trailing fragments off the line. */
|
ellipsis so it never pushes the trailing fragments off the line. */
|
||||||
.activity-detail {
|
.activity-detail {
|
||||||
color: var(--faint);
|
color: var(--faint);
|
||||||
flex: 0 1 auto;
|
/* Consume only the space left after the trailing status + command. */
|
||||||
|
flex: 1 1 0;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
@@ -865,12 +867,19 @@ textarea {
|
|||||||
signals severity and "exited" dims with the row. */
|
signals severity and "exited" dims with the row. */
|
||||||
.card-flag {
|
.card-flag {
|
||||||
color: var(--faint);
|
color: var(--faint);
|
||||||
|
flex: 0 0 auto;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Status fragments stay intact. The unconditional command is the final
|
||||||
|
truncation target when even the complete trailing set cannot fit. */
|
||||||
|
.leaf-cmd {
|
||||||
|
flex: 0 1 auto;
|
||||||
|
}
|
||||||
|
|
||||||
/* Actions live in line 1's flow at its right edge — never overlaid on the
|
/* Actions live in line 1's flow at its right edge — never overlaid on the
|
||||||
name (#107). They reserve their width even while hover-faded. */
|
name (#107). They reserve their width even while hover-faded. */
|
||||||
.leaf-actions {
|
.leaf-actions {
|
||||||
|
|||||||
Reference in New Issue
Block a user