Skip to main content

typ_core/
event.rs

1use std::path::PathBuf;
2
3/// Identifies a live panel instance.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub struct PanelId(pub u32);
6
7/// Identifies a registered handler in `typ-registry`.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
9pub struct HandlerId(pub &'static str);
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12pub enum NotifyLevel {
13    Info,
14    Warn,
15    Error,
16}
17
18/// The complete vocabulary a panel may emit.
19///
20/// This set is deliberately closed. Editors that let every viewer add its own
21/// variant end up with an enum that each new panel type must edit, turning it
22/// into a chokepoint. New panels register a handler in `typ-registry` and route
23/// through `OpenWith` instead.
24#[derive(Debug, Clone, PartialEq, Eq)]
25pub enum PanelEvent {
26    /// Panel state changed; the app should repaint.
27    NeedsRedraw,
28    /// Quit the application.
29    Quit,
30    /// Close the emitting panel.
31    CloseSelf,
32    /// Move focus to another panel.
33    Focus(PanelId),
34    /// Open a path in whichever panel the registry says owns it.
35    OpenFile {
36        path: PathBuf,
37        line: usize,
38        col: usize,
39    },
40    /// Open a path with an explicitly chosen handler.
41    OpenWith { handler: HandlerId, path: PathBuf },
42    /// Run a shell command, optionally in a given directory.
43    RunCommand {
44        command: String,
45        cwd: Option<PathBuf>,
46    },
47    /// Surface a message to the user.
48    Notify { level: NotifyLevel, message: String },
49}