Skip to content

Commit b2b60ee

Browse files
refactor: remove stale input map logic from App + add tests
1 parent 14e719f commit b2b60ee

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

television/app.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -608,18 +608,12 @@ impl App {
608608
self.action_tx.send(action)?;
609609
}
610610

611-
// Update keymap if channel changed (remote control to channel mode transition)
612-
// This ensures channel-specific keybindings are properly loaded
611+
// Update watch timer and history
613612
if was_remote_control
614613
&& matches!(action, Action::ConfirmSelection)
615614
&& self.television.mode == Mode::Channel
615+
|| matches!(action, Action::SwitchToChannel(_))
616616
{
617-
self.update_input_map();
618-
self.update_history();
619-
self.restart_watch_timer();
620-
} else if matches!(action, Action::SwitchToChannel(_)) {
621-
// Channel changed via shortcut, refresh keymap and watch timer
622-
self.update_input_map();
623617
self.update_history();
624618
self.restart_watch_timer();
625619
}

tests/channels.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,24 @@ test_channel! {
4848
test_channel_text: "text",
4949
test_channel_diff: "git-diff",
5050
}
51+
52+
#[test]
53+
fn test_channel_shortcuts() {
54+
let mut tester = PtyTester::new();
55+
let mut child = tester
56+
.spawn_command_tui(tv_local_config_and_cable_with_args(&["files"]));
57+
58+
tester.assert_tui_frame_contains("CHANNEL files");
59+
60+
// switch to the "dirs" channel
61+
tester.send(&f(2));
62+
tester.assert_tui_frame_contains("CHANNEL dirs");
63+
64+
// switch back to the "files" channel
65+
tester.send(&f(1));
66+
tester.assert_tui_frame_contains("CHANNEL files");
67+
68+
// Send Ctrl-C to exit
69+
tester.send(&ctrl('c'));
70+
PtyTester::assert_exit_ok(&mut child, DEFAULT_DELAY * 2);
71+
}

tests/common/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,28 @@ pub fn ctrl(c: char) -> String {
339339
((c as u8 & 0x1F) as char).to_string()
340340
}
341341

342+
pub fn f(c: u8) -> String {
343+
let seq = match c {
344+
1 => "\x1bOP", // F1
345+
2 => "\x1bOQ", // F2
346+
3 => "\x1bOR", // F3
347+
4 => "\x1bOS", // F4
348+
5 => "\x1b[15~", // F5
349+
6 => "\x1b[17~", // F6
350+
7 => "\x1b[18~", // F7
351+
8 => "\x1b[19~", // F8
352+
9 => "\x1b[20~", // F9
353+
10 => "\x1b[21~", // F10
354+
11 => "\x1b[23~", // F11
355+
12 => "\x1b[24~", // F12
356+
_ => {
357+
panic!("Invalid function key: {}", c);
358+
}
359+
};
360+
361+
seq.to_string()
362+
}
363+
342364
pub const ENTER: &str = "\r";
343365
pub const ESC: &str = "\x1b";
344366

0 commit comments

Comments
 (0)