Lines
99.16 %
Functions
100 %
Branches
//! Keys of the focused console: prompt and scrollback panes.
use super::tests::{ctrl, key, press, seen, type_text};
use crate::app::App;
use crate::pane::PaneId;
use ratatui::crossterm::event::KeyCode;
fn console_app() -> App {
let mut a = crate::test_support::app();
a.focus_console();
a
}
fn scrollback_app() -> App {
let mut a = console_app();
a.console_mut().panes.focus(PaneId::Scrollback);
a.console_mut().scrollback = (0..30).map(|n| n.to_string()).collect();
/// Runs a long eval, moves to `pane`, presses Ctrl-C and reports whether the eval was interrupted.
async fn ctrl_c_interrupts_from(pane: PaneId) -> bool {
use crate::tabs::nms_eval::ConsoleEval;
use rpc::{ScriptCtx, ScriptLimits};
use sqlx::types::Uuid;
use std::time::Duration;
use tokio::time::sleep;
let ctx = ScriptCtx::new(Uuid::nil()).with_limits(ScriptLimits {
fuel: u64::MAX,
..ScriptLimits::default()
});
let eval = ConsoleEval::connect(&tokio::runtime::Handle::current(), ctx, rpc::Session::new)
.expect("spawn");
let mut app = crate::test_support::app();
app.attach_console(eval);
assert!(
app.await_ui_config_read().await,
"the theme read was never answered"
);
app.focus_console();
type_text(&mut app, "(do ((i 0 (+ i 1))) ((>= i 1073741823) i))");
press(&mut app, key(KeyCode::Enter));
sleep(Duration::from_millis(40)).await;
app.console_mut().panes.focus(pane);
press(&mut app, ctrl(KeyCode::Char('c')));
for _ in 0..200 {
app.drain_eval();
if app
.console()
.scrollback
.iter()
.any(|line| line.contains("[error] interrupted:"))
{
return true;
sleep(Duration::from_millis(20)).await;
false
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn ctrl_c_in_the_prompt_interrupts_the_eval() {
assert!(ctrl_c_interrupts_from(PaneId::Prompt).await);
async fn ctrl_c_in_the_scrollback_interrupts_the_eval() {
assert!(ctrl_c_interrupts_from(PaneId::Scrollback).await);
#[test]
fn console_prompt_types_under_the_vim_preset() {
let mut a = crate::test_support::vim_app();
press(&mut a, key(KeyCode::Char('h')));
assert_eq!(a.console().input.buffer(), "h");
press(&mut a, key(KeyCode::Esc));
assert!(!a.console_input_focused());
fn console_prompt_types_and_deletes() {
type_text(&mut a, "xy");
assert_eq!(a.console().input.buffer(), "xy");
press(&mut a, key(KeyCode::Backspace));
assert_eq!(a.console().input.buffer(), "x");
fn console_enter_submits_the_line() {
type_text(&mut a, "x");
press(&mut a, key(KeyCode::Enter));
assert_eq!(a.console().input.buffer(), "");
fn console_esc_blurs_the_prompt() {
fn console_up_and_down_walk_the_history() {
a.console_mut().history = vec!["first".to_string(), "second".to_string()];
press(&mut a, key(KeyCode::Up));
assert_eq!(a.console().input.buffer(), "second");
assert_eq!(a.console().input.buffer(), "first");
press(&mut a, key(KeyCode::Down));
fn console_focused_tab_cycles_pane() {
press(&mut a, key(KeyCode::Tab));
assert_eq!(a.console().panes.focused(), PaneId::Scrollback);
press(&mut a, key(KeyCode::BackTab));
assert_eq!(a.console().panes.focused(), PaneId::Prompt);
fn scrollback_pane_routes_scroll_keys() {
let mut a = scrollback_app();
assert_eq!(a.console().scroll, 1);
assert_eq!(a.console().scroll, 0);
press(&mut a, key(KeyCode::PageUp));
assert_eq!(a.console().scroll, 10);
press(&mut a, key(KeyCode::PageDown));
fn scrollback_esc_blurs_the_console() {
fn scrollback_pane_letter_key_changes_nothing() {
let before = seen(&a);
press(&mut a, key(KeyCode::Char('x')));
assert_eq!(seen(&a), before);
fn scrollback_pane_tab_cycles_back_to_prompt() {