1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
use serde::{Deserialize, Deserializer, Serialize};
use super::{CommandKeybindConfig, SoundConfig, ThemeConfig, DEFAULT_SCROLLBACK_LIMIT_BYTES};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum ToastDelivery {
#[default]
Off,
Herdr,
Terminal,
}
#[derive(Debug, Clone)]
pub struct ToastConfig {
pub delivery: ToastDelivery,
}
#[derive(Debug, Default, Deserialize)]
#[serde(default)]
pub struct Config {
pub onboarding: Option<bool>,
pub theme: ThemeConfig,
pub keys: KeysConfig,
pub ui: UiConfig,
pub advanced: AdvancedConfig,
}
#[derive(Debug)]
pub struct LoadedConfig {
pub config: Config,
pub diagnostics: Vec<String>,
}
#[derive(Debug, Deserialize)]
#[serde(default)]
pub struct KeysConfig {
/// Prefix key to toggle navigate mode (e.g. "ctrl+b", "f12", "esc").
pub prefix: String,
/// Create a new workspace. Default: "n"
pub new_workspace: String,
/// Rename the selected workspace. Default: "shift+n"
pub rename_workspace: String,
/// Close the selected workspace. Default: "shift+d"
pub close_workspace: String,
/// Optional explicit detach shortcut in server/client mode. Unset by default.
pub detach: String,
/// Select the previous workspace. Unset by default.
pub previous_workspace: String,
/// Select the next workspace. Unset by default.
pub next_workspace: String,
/// Create a new tab in the active workspace. Default: "c"
pub new_tab: String,
/// Rename the active tab. Unset by default.
pub rename_tab: String,
/// Select the previous tab. Unset by default.
pub previous_tab: String,
/// Select the next tab. Unset by default.
pub next_tab: String,
/// Close the active tab. Unset by default.
pub close_tab: String,
/// Focus the pane to the left in terminal mode. Unset by default.
pub focus_pane_left: String,
/// Focus the pane below in terminal mode. Unset by default.
pub focus_pane_down: String,
/// Focus the pane above in terminal mode. Unset by default.
pub focus_pane_up: String,
/// Focus the pane to the right in terminal mode. Unset by default.
pub focus_pane_right: String,
/// Split pane vertically (side by side). Default: "v"
pub split_vertical: String,
/// Split pane horizontally (stacked). Default: "-"
pub split_horizontal: String,
/// Close the focused pane. Default: "x"
pub close_pane: String,
/// Toggle fullscreen for the focused pane. Default: "f"
pub fullscreen: String,
/// Enter resize mode. Default: "r"
pub resize_mode: String,
/// Toggle sidebar collapse. Default: "b"
pub toggle_sidebar: String,
/// Prefix-mode custom command bindings.
pub command: Vec<CommandKeybindConfig>,
}
#[derive(Debug, Deserialize)]
#[serde(default)]
pub struct UiConfig {
pub sidebar_width: u16,
/// Ask for confirmation before closing a workspace. Default: true.
pub confirm_close: bool,
/// Accent color for highlights, borders, and navigation UI.
/// Accepts hex (#89b4fa), named colors (cyan, blue), or RGB (rgb(137,180,250)).
pub accent: String,
/// Optional visual toast notifications for background workspace events.
pub toast: ToastConfig,
/// Play sounds when agents change state in background workspaces.
pub sound: SoundConfig,
}
#[derive(Debug, Deserialize)]
#[serde(default)]
pub struct AdvancedConfig {
/// Allow launching herdr inside an existing herdr pane. Default: false.
pub allow_nested: bool,
/// Maximum scrollback buffer size in bytes retained per pane terminal. Default: 10000000.
#[serde(alias = "scrollback_lines")]
pub scrollback_limit_bytes: usize,
}
impl Default for KeysConfig {
fn default() -> Self {
Self {
prefix: "ctrl+b".into(),
new_workspace: "n".into(),
rename_workspace: "shift+n".into(),
close_workspace: "shift+d".into(),
detach: "".into(),
previous_workspace: "".into(),
next_workspace: "".into(),
new_tab: "c".into(),
rename_tab: "".into(),
previous_tab: "".into(),
next_tab: "".into(),
close_tab: "".into(),
focus_pane_left: "".into(),
focus_pane_down: "".into(),
focus_pane_up: "".into(),
focus_pane_right: "".into(),
split_vertical: "v".into(),
split_horizontal: "-".into(),
close_pane: "x".into(),
fullscreen: "f".into(),
resize_mode: "r".into(),
toggle_sidebar: "b".into(),
command: Vec::new(),
}
}
}
impl Default for UiConfig {
fn default() -> Self {
Self {
sidebar_width: 26,
confirm_close: true,
accent: "cyan".into(),
toast: ToastConfig::default(),
sound: SoundConfig::default(),
}
}
}
impl Default for ToastConfig {
fn default() -> Self {
Self {
delivery: ToastDelivery::Off,
}
}
}
impl<'de> Deserialize<'de> for ToastConfig {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
#[derive(Deserialize, Default)]
#[serde(default)]
struct RawToastConfig {
delivery: Option<ToastDelivery>,
enabled: Option<bool>,
}
let raw = RawToastConfig::deserialize(deserializer)?;
let delivery = raw.delivery.unwrap_or_else(|| match raw.enabled {
Some(true) => ToastDelivery::Herdr,
Some(false) => ToastDelivery::Off,
None => ToastDelivery::Off,
});
Ok(Self { delivery })
}
}
impl Default for AdvancedConfig {
fn default() -> Self {
Self {
allow_nested: false,
scrollback_limit_bytes: DEFAULT_SCROLLBACK_LIMIT_BYTES,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn toast_config_parses() {
let toml = r#"
[ui.toast]
delivery = "terminal"
"#;
let config: Config = toml::from_str(toml).unwrap();
assert_eq!(config.ui.toast.delivery, ToastDelivery::Terminal);
}
#[test]
fn toast_config_legacy_enabled_true_maps_to_herdr() {
let toml = r#"
[ui.toast]
enabled = true
"#;
let config: Config = toml::from_str(toml).unwrap();
assert_eq!(config.ui.toast.delivery, ToastDelivery::Herdr);
}
#[test]
fn toast_config_legacy_enabled_false_maps_to_off() {
let toml = r#"
[ui.toast]
enabled = false
"#;
let config: Config = toml::from_str(toml).unwrap();
assert_eq!(config.ui.toast.delivery, ToastDelivery::Off);
}
#[test]
fn toast_config_delivery_wins_over_legacy_enabled() {
let toml = r#"
[ui.toast]
enabled = true
delivery = "terminal"
"#;
let config: Config = toml::from_str(toml).unwrap();
assert_eq!(config.ui.toast.delivery, ToastDelivery::Terminal);
}
#[test]
fn missing_onboarding_shows_setup() {
let config = Config::default();
assert!(config.should_show_onboarding());
}
#[test]
fn onboarding_false_skips_setup() {
let config: Config = toml::from_str("onboarding = false").unwrap();
assert!(!config.should_show_onboarding());
}
#[test]
fn advanced_defaults_include_scrollback_limit_bytes() {
let config = Config::default();
assert_eq!(
config.advanced.scrollback_limit_bytes,
DEFAULT_SCROLLBACK_LIMIT_BYTES
);
}
#[test]
fn advanced_config_parses() {
let toml = r#"
[advanced]
allow_nested = true
scrollback_limit_bytes = 12345
"#;
let config: Config = toml::from_str(toml).unwrap();
assert!(config.advanced.allow_nested);
assert_eq!(config.advanced.scrollback_limit_bytes, 12345);
}
#[test]
fn advanced_legacy_scrollback_lines_alias_parses() {
let toml = r#"
[advanced]
scrollback_lines = 12345
"#;
let config: Config = toml::from_str(toml).unwrap();
assert_eq!(config.advanced.scrollback_limit_bytes, 12345);
}
}
|