Skip to content

Commit de3031c

Browse files
authored
Merge pull request #51 from myrk-kale/fix/tmux-shift-arrow-switch
feat(tmux): switch between the agent and the reviewer with Shift+arrows
2 parents a8700ff + f893994 commit de3031c

2 files changed

Lines changed: 33 additions & 5 deletions

File tree

‎docs/configuration.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Every key has a default, so an empty file (or none) is valid. The schema lives i
3030
| `ui.hold_to_peek` | `false` | Hold `B` (the `peek_previous` key) while reading code to see the previous version, and let go to come back. It needs a terminal that reports key releases (the kitty keyboard protocol: kitty, Ghostty, WezTerm, recent iTerm2 and foot). Where that is missing, which includes tmux, the key says so and `v` still toggles. While it is on, the terminal sends keys as escape codes except inside text fields, which keep ordinary input so compose and `AltGr` characters still type. |
3131
| `integration.submit_mode` | `"manual"` | The only mode. Klaub never presses `Enter` in the agent. |
3232
| `integration.paste_requires_confirmation` | `true` | Putting text in the agent's input always asks first. |
33-
| `integration.tmux_prefix` | `"C-b"` | The prefix of the session chords (`Prefix+R`, `Prefix+A`, `Prefix+I`, `Prefix+C`, `Prefix+T`, `Prefix+B`, `Prefix+L`, `Prefix+Q`, `Prefix+?`). |
33+
| `integration.tmux_prefix` | `"C-b"` | The prefix of the session chords. Moving between the agent and the reviewer needs no prefix: `Shift+←` goes to the agent and `Shift+→` to the reviewer. The rest are `Prefix+R`, `Prefix+A`, `Prefix+I`, `Prefix+C`, `Prefix+T`, `Prefix+B`, `Prefix+L`, `Prefix+Q` and `Prefix+?`. |
3434

3535
## `[keys]`
3636

‎src/adapters/tmux/config.rs‎

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ pub struct SessionConfig<'a> {
2525
}
2626

2727
/// The help shown by `Prefix ?`.
28-
pub const HELP_TEXT: &str = "klaub Prefix+R review Prefix+A agent Prefix+I impact Prefix+C comments \
29-
Prefix+T tests Prefix+B brief Prefix+L flow Prefix+d detach Prefix+Q quit \
30-
(Prefix is Ctrl+B unless configured; R and A also work in lower case)";
28+
pub const HELP_TEXT: &str = "klaub Shift+Left agent Shift+Right review (no prefix) Prefix+R review \
29+
Prefix+A agent Prefix+I impact Prefix+C comments Prefix+T tests Prefix+B brief Prefix+L flow \
30+
Prefix+d detach Prefix+Q quit (Prefix is Ctrl+B unless configured; R and A also work in lower case)";
3131

3232
/// Checks a tmux key name such as `C-b`, `C-Space` or `M-a`.
3333
pub fn validate_prefix(prefix: &str) -> Result<()> {
@@ -97,7 +97,7 @@ pub fn configuration(spec: &SessionConfig<'_>) -> Result<Vec<Vec<String>>> {
9797
"set-option",
9898
"-g",
9999
"status-right",
100-
" Prefix+R review Prefix+A agent Prefix+Q quit Prefix+? help ",
100+
" Shift+← agent Shift+→ review Prefix+Q quit Prefix+? help ",
101101
]),
102102
command(&["set-option", "-g", "status-right-length", "80"]),
103103
command(&[
@@ -163,6 +163,24 @@ pub fn configuration(spec: &SessionConfig<'_>) -> Result<Vec<Vec<String>>> {
163163
"#{@klaub-focus-agent}",
164164
]));
165165
}
166+
// Moving between the two windows is the thing done most, so it takes one key and no prefix. The
167+
// agent window is the first and the reviewer the second, which is the way the arrows point.
168+
// Neither the agent nor the reader uses these keys, and they reach tmux whole in every terminal
169+
// that encodes Shift+arrow the usual way.
170+
for (key, target) in [
171+
("S-Left", "#{@klaub-focus-agent}"),
172+
("S-Right", "#{@klaub-focus-review}"),
173+
] {
174+
commands.push(command(&[
175+
"bind-key",
176+
"-T",
177+
"root",
178+
key,
179+
"run-shell",
180+
"-b",
181+
target,
182+
]));
183+
}
166184
// Ends the whole session (the agent included), which `Prefix+d` does not: that only detaches.
167185
commands.push(command(&[
168186
"bind-key",
@@ -258,6 +276,16 @@ mod tests {
258276
flat.iter()
259277
.any(|c| c == "bind-key -T prefix A run-shell -b #{@klaub-focus-agent}")
260278
);
279+
assert!(
280+
flat.iter()
281+
.any(|c| c == "bind-key -T root S-Left run-shell -b #{@klaub-focus-agent}"),
282+
"Shift+Left reaches the agent without the prefix"
283+
);
284+
assert!(
285+
flat.iter()
286+
.any(|c| c == "bind-key -T root S-Right run-shell -b #{@klaub-focus-review}"),
287+
"Shift+Right reaches the reviewer without the prefix"
288+
);
261289
assert!(flat.iter().any(|c| c == "set-option -g @klaub-focus-review /usr/bin/klaub session focus --id ses_abc123 review"));
262290
for key in ["r", "a"] {
263291
assert!(

0 commit comments

Comments
 (0)