1
//! Input routing while the console prompt is focused.
2

            
3
use super::Intent;
4
use crate::app::App;
5
use crate::tabs::nms::ConsoleState;
6
use crate::view::ViewId;
7

            
8
/// Route input while the console is focused. `Enter` assembles the input
9
/// line into the pending form; a complete (balanced) form is submitted
10
/// to the eval, an incomplete one keeps buffering. Editing intents
11
/// mutate the console input editor; history keys walk prior submissions.
12
213
pub(super) fn handle(app: &mut App, intent: Intent) {
13
213
    match intent {
14
5
        Intent::ConsoleBlur => app.set_console_focused(false),
15
        Intent::ConsoleSubmit => {
16
8
            let Some(console) = app.front_or_say(ViewId::Console) else {
17
                return;
18
            };
19
8
            let form = app
20
8
                .win_mut::<ConsoleState>(console)
21
8
                .and_then(ConsoleState::take_complete_form);
22
8
            if let Some(form) = form {
23
7
                app.submit_console_form(console, form);
24
1
            }
25
        }
26
4
        Intent::ConsoleInterrupt => app.interrupt_console(),
27
        _ => {
28
196
            if let Some(console) = app.front_mut::<ConsoleState>() {
29
196
                edit(console, intent);
30
            }
31
        }
32
    }
33
213
}
34

            
35
196
fn edit(console: &mut ConsoleState, intent: Intent) {
36
196
    match intent {
37
4
        Intent::ConsoleHistoryPrev => console.history_prev(),
38
2
        Intent::ConsoleHistoryNext => console.history_next(),
39
6
        Intent::ConsoleCyclePane => console.panes.cycle(true),
40
3
        Intent::ScrollLineUp => console.scroll_up(1),
41
3
        Intent::ScrollLineDown => console.scroll_down(1),
42
3
        Intent::ScrollPageUp => console.scroll_up(10),
43
2
        Intent::ScrollPageDown => console.scroll_down(10),
44
167
        Intent::InsertChar(c) => console.input.insert_char(c),
45
2
        Intent::DeleteBackward => console.input.delete_backward(),
46
        Intent::MoveLeft => console.input.move_left(),
47
        Intent::MoveRight => console.input.move_right(),
48
1
        Intent::MoveHome => console.input.move_home(),
49
        Intent::MoveEnd => console.input.move_end(),
50
2
        Intent::DeleteForward => console.input.delete_forward(),
51
        Intent::MoveWordForward => console.input.word_forward(),
52
1
        Intent::MoveWordBackward => console.input.word_backward(),
53
        Intent::KillToEnd => console.input.kill_to_end(),
54
        Intent::KillWordBackward => console.input.kill_word_backward(),
55
        _ => {}
56
    }
57
196
}