changing newline hint + unit test if kpp enabled/disabled

This commit is contained in:
pap
2025-07-31 22:02:18 +01:00
parent 6efe3474d4
commit a527223a59
3 changed files with 39 additions and 1 deletions

View File

@@ -712,7 +712,11 @@ impl WidgetRef for &ChatComposer<'_> {
Span::from(" to quit"),
]
} else {
let newline_hint = if crate::tui::is_kkp_enabled() { "Shift+⏎" } else { "Ctrl+J" };
let newline_hint = if crate::tui::is_kkp_enabled() {
"Shift+⏎"
} else {
"Ctrl+J"
};
vec![
Span::from(" "),
"".set_style(key_hint_style),
@@ -962,6 +966,9 @@ mod tests {
use ratatui::Terminal;
use ratatui::backend::TestBackend;
// First, run snapshots with KKP enabled so hints show Shift+⏎.
crate::tui::set_kkp_for_tests(true);
let (tx, _rx) = std::sync::mpsc::channel();
let sender = AppEventSender::new(tx);
let mut terminal = match Terminal::new(TestBackend::new(100, 10)) {
@@ -1006,6 +1013,18 @@ mod tests {
assert_snapshot!(name, terminal.backend());
}
// Also add one snapshot with KKP disabled so we still see Ctrl+J.
crate::tui::set_kkp_for_tests(false);
let mut terminal_ctrlj = match Terminal::new(TestBackend::new(100, 10)) {
Ok(t) => t,
Err(e) => panic!("Failed to create terminal: {e}"),
};
let composer = ChatComposer::new(true, sender.clone());
terminal_ctrlj
.draw(|f| f.render_widget_ref(&composer, f.area()))
.unwrap_or_else(|e| panic!("Failed to draw empty_ctrlj composer: {e}"));
assert_snapshot!("empty_ctrlj", terminal_ctrlj.backend());
}
#[test]

View File

@@ -0,0 +1,14 @@
---
source: tui/src/bottom_pane/chat_composer.rs
expression: terminal_ctrlj.backend()
---
"▌ ... "
"▌ "
"▌ "
"▌ "
"▌ "
"▌ "
"▌ "
"▌ "
"▌ "
" ⏎ send Ctrl+J newline Ctrl+C quit "

View File

@@ -27,6 +27,11 @@ pub(crate) fn is_kkp_enabled() -> bool {
KKP_ENABLED.load(Ordering::Relaxed)
}
#[cfg(test)]
pub(crate) fn set_kkp_for_tests(value: bool) {
KKP_ENABLED.store(value, Ordering::Relaxed);
}
/// Try to detect Kitty Keyboard Protocol support by issuing a progressive
/// enhancement query and waiting briefly for a response.
#[cfg(unix)]