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
|
use ratatui::{
layout::{Constraint, Layout, Rect},
style::{Modifier, Style},
text::{Line, Span},
widgets::{Paragraph, Wrap},
Frame,
};
use super::release_notes::release_notes_close_button_rect;
use super::scrollbar::{release_notes_scrollbar_rect, render_scrollbar};
use super::widgets::{
modal_stack_areas, panel_contrast_fg, render_action_button, render_modal_header,
render_modal_shell,
};
use crate::app::AppState;
fn optional_keybind_label(label: &Option<String>) -> String {
label.clone().unwrap_or_else(|| "unset".to_string())
}
pub(super) fn keybind_help_groups(
app: &AppState,
) -> Vec<(&'static str, Vec<(String, &'static str)>)> {
let kb = &app.keybinds;
let mut groups = Vec::new();
groups.push((
"global",
vec![
(
crate::config::format_key_combo((app.prefix_code, app.prefix_mods)),
"navigate mode",
),
("prefix + ?".to_string(), "keybinds"),
(
optional_keybind_label(&kb.reload_config_label),
"reload config",
),
],
));
groups.push((
"navigation",
vec![
("esc".to_string(), "back"),
("↑ / ↓".to_string(), "workspace list"),
("h j k l / arrows".to_string(), "move focus"),
("tab / shift+tab".to_string(), "cycle pane"),
("enter".to_string(), "open workspace"),
("s".to_string(), "settings"),
("q".to_string(), "quit"),
],
));
let mut workspace_tab = vec![
(kb.new_workspace_label.clone(), "new workspace"),
(kb.rename_workspace_label.clone(), "rename workspace"),
(kb.close_workspace_label.clone(), "close workspace"),
(
optional_keybind_label(&kb.open_notification_target_label),
"open notification target",
),
(
optional_keybind_label(&kb.previous_workspace_label),
"previous workspace",
),
(
optional_keybind_label(&kb.next_workspace_label),
"next workspace",
),
(
optional_keybind_label(&kb.indexed_workspaces_label),
"switch workspace 1-9",
),
(
optional_keybind_label(&kb.previous_agent_label),
"previous agent",
),
(optional_keybind_label(&kb.next_agent_label), "next agent"),
(
optional_keybind_label(&kb.indexed_agents_label),
"focus agent 1-9",
),
(kb.new_tab_label.clone(), "new tab"),
(optional_keybind_label(&kb.rename_tab_label), "rename tab"),
(
optional_keybind_label(&kb.previous_tab_label),
"previous tab",
),
(optional_keybind_label(&kb.next_tab_label), "next tab"),
(
optional_keybind_label(&kb.indexed_tabs_label),
"switch tab 1-9",
),
(optional_keybind_label(&kb.close_tab_label), "close tab"),
];
if let Some(label) = &kb.detach_label {
workspace_tab.insert(3, (label.clone(), "detach from server"));
}
groups.push(("workspaces / tabs", workspace_tab));
let panes = vec![
(kb.split_vertical_label.clone(), "split vertical"),
(kb.split_horizontal_label.clone(), "split horizontal"),
(kb.close_pane_label.clone(), "close pane"),
(optional_keybind_label(&kb.rename_pane_label), "rename pane"),
(
optional_keybind_label(&kb.edit_scrollback_label),
"edit scrollback",
),
(kb.zoom_label.clone(), "zoom pane"),
(kb.resize_mode_label.clone(), "resize mode"),
(kb.toggle_sidebar_label.clone(), "toggle sidebar"),
(
optional_keybind_label(&kb.focus_pane_left_label),
"focus pane left",
),
(
optional_keybind_label(&kb.focus_pane_down_label),
"focus pane down",
),
(
optional_keybind_label(&kb.focus_pane_up_label),
"focus pane up",
),
(
optional_keybind_label(&kb.focus_pane_right_label),
"focus pane right",
),
];
groups.push(("panes", panes));
if !kb.custom_commands.is_empty() {
groups.push((
"custom",
kb.custom_commands
.iter()
.map(|binding| (binding.label.clone(), "custom command"))
.collect(),
));
}
groups
}
pub(crate) fn keybind_help_lines(app: &AppState) -> Vec<(usize, Line<'static>)> {
let heading_style = Style::default()
.fg(app.palette.accent)
.add_modifier(Modifier::BOLD);
let key_style = Style::default()
.fg(app.palette.mauve)
.add_modifier(Modifier::BOLD);
let label_style = Style::default().fg(app.palette.text);
let groups = keybind_help_groups(app);
let key_width = groups
.iter()
.flat_map(|(_, entries)| entries.iter().map(|(key, _)| key.chars().count()))
.max()
.unwrap_or(8);
let mut lines = Vec::new();
for (group, entries) in groups {
lines.push((
group.len() + 1,
Line::from(vec![Span::styled(format!(" {group}"), heading_style)]),
));
for (key, label) in entries {
let padded_key = format!(" {:<width$} ", key, width = key_width);
let width = padded_key.chars().count() + label.chars().count();
lines.push((
width,
Line::from(vec![
Span::styled(padded_key, key_style),
Span::styled(label.to_string(), label_style),
]),
));
}
lines.push((0, Line::raw("")));
}
lines
}
pub(super) fn render_keybind_help_overlay(app: &AppState, frame: &mut Frame) {
super::dim_background(frame, frame.area());
let Some(inner) = render_modal_shell(frame, frame.area(), 76, 22, &app.palette) else {
return;
};
if inner.height < 6 || inner.width < 20 {
return;
}
let stack = modal_stack_areas(inner, 2, 1, 0, 1);
let header_rows =
Layout::vertical([Constraint::Length(1), Constraint::Length(1)]).areas::<2>(stack.header);
render_modal_header(frame, header_rows[0], "keybinds", &app.palette);
render_action_button(
frame,
release_notes_close_button_rect(header_rows[0]),
Some("esc"),
"close",
Style::default()
.fg(panel_contrast_fg(&app.palette))
.bg(app.palette.accent)
.add_modifier(Modifier::BOLD),
);
frame.render_widget(
Paragraph::new(" available commands and configured shortcuts")
.style(Style::default().fg(app.palette.overlay1)),
header_rows[1],
);
let body_area = stack.content;
let metrics = crate::pane::ScrollMetrics {
offset_from_bottom: app
.keybind_help_max_scroll()
.saturating_sub(app.keybind_help.scroll) as usize,
max_offset_from_bottom: app.keybind_help_max_scroll() as usize,
viewport_rows: body_area.height.max(1) as usize,
};
let track = release_notes_scrollbar_rect(body_area, metrics);
let text_area = track
.map(|_| {
Rect::new(
body_area.x,
body_area.y,
body_area.width.saturating_sub(1),
body_area.height,
)
})
.unwrap_or(body_area);
let body = Paragraph::new(
keybind_help_lines(app)
.into_iter()
.map(|(_, line)| line)
.collect::<Vec<_>>(),
)
.wrap(Wrap { trim: false })
.scroll((app.keybind_help.scroll, 0));
frame.render_widget(body, text_area);
if let Some(track) = track {
render_scrollbar(
frame,
metrics,
track,
app.palette.overlay0,
app.palette.overlay1,
"▐",
);
}
frame.render_widget(
Paragraph::new(Line::from(vec![
Span::styled(" scroll ", Style::default().fg(app.palette.overlay0)),
Span::styled("wheel ↑↓", Style::default().fg(app.palette.text)),
Span::styled(" · ", Style::default().fg(app.palette.overlay0)),
Span::styled("jump", Style::default().fg(app.palette.overlay0)),
Span::styled(" pgup / pgdn ", Style::default().fg(app.palette.text)),
Span::styled(" · ", Style::default().fg(app.palette.overlay0)),
Span::styled("close", Style::default().fg(app.palette.overlay0)),
Span::styled(" esc / enter ", Style::default().fg(app.palette.text)),
])),
stack.footer.unwrap_or_default(),
);
}
|