typ_core/event.rs
1use std::path::PathBuf;
2
3/// Everything the event loop can be woken by.
4///
5/// The loop blocks on a channel of these rather than on `event::read()`, so a
6/// worker thread can deliver a result without waiting for the user to press a
7/// key. A terminal event is one variant among several, not the only input.
8///
9/// M2.5 adds `Parsed(Tree)` and M3 adds an LSP response. That is the point of
10/// the type: a new off-thread producer is a variant here and a match arm in the
11/// loop, not a change to how the loop waits.
12#[derive(Debug, Clone, PartialEq, Eq)]
13pub enum AppEvent {
14 /// Something arrived from the terminal: a key, a mouse report, a paste.
15 Input(crossterm::event::Event),
16 /// The file at this path changed on disk.
17 FileChanged(PathBuf),
18}
19
20/// Identifies a live panel instance.
21#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22pub struct PanelId(pub u32);
23
24/// Identifies a registered handler in `typ-registry`.
25#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
26pub struct HandlerId(pub &'static str);
27
28#[derive(Debug, Clone, Copy, PartialEq, Eq)]
29pub enum NotifyLevel {
30 Info,
31 Warn,
32 Error,
33}
34
35/// The complete vocabulary a panel may emit.
36///
37/// This set is deliberately closed. Editors that let every viewer add its own
38/// variant end up with an enum that each new panel type must edit, turning it
39/// into a chokepoint. New panels register a handler in `typ-registry` and route
40/// through `OpenWith` instead.
41#[derive(Debug, Clone, PartialEq, Eq)]
42pub enum PanelEvent {
43 /// Panel state changed; the app should repaint.
44 NeedsRedraw,
45 /// Quit the application.
46 Quit,
47 /// Close the emitting panel.
48 CloseSelf,
49 /// Move focus to another panel.
50 Focus(PanelId),
51 /// Open a path in whichever panel the registry says owns it.
52 OpenFile {
53 path: PathBuf,
54 line: usize,
55 col: usize,
56 },
57 /// Open a path with an explicitly chosen handler.
58 OpenWith { handler: HandlerId, path: PathBuf },
59 /// Run a shell command, optionally in a given directory.
60 RunCommand {
61 command: String,
62 cwd: Option<PathBuf>,
63 },
64 /// Surface a message to the user.
65 Notify { level: NotifyLevel, message: String },
66}