rustimal 0.8.0

A minimal, GPU-rendered terminal for Windows that runs Git Bash, with animated split panes and a glass look
//! What happens to a pane and what it tells the app: the app's event type, and the
//! signals that commands hide in a terminal's title.

use std::path::PathBuf;

use alacritty_terminal::event::{Event as TermEvent, EventListener};
use winit::event_loop::EventLoopProxy;

use crate::terminal::embeds::WebKind;
use crate::terminal::layout::PaneId;

/// Something that just finished running in a pane, worth telling the user about.
pub struct Done {
    pub what: String,
    pub secs: f32,
}

pub enum TitleSignal {
    None,
    Pick(PathBuf),
    Done(Done),
    /// The shell's `review` or `pr`: the folder it was typed in, and the arguments.
    Review {
        cwd: PathBuf,
        args: String,
    },
    /// The shell's `t3`: the folder to show, and which conversation (empty for the latest).
    T3 {
        cwd: PathBuf,
        args: String,
    },
    /// The shell's `do`: the folder, and which agent. The task is in [`Pane::take_task`].
    Do {
        cwd: PathBuf,
        agent: String,
    },
    /// The shell's `vscode` or `open`: the folder, and which of the two (`mode`). What to
    /// open is in [`Pane::take_note`].
    Code {
        cwd: PathBuf,
        mode: String,
    },
    /// The shell's `embed`: `start:PID`, the shell to look below for the window.
    Embed {
        args: String,
    },
}

pub enum UserEvent {
    Term(PaneId, TermEvent),
    /// The global hotkey was pressed.
    Hotkey,
    /// The config file changed on disk.
    ConfigChanged,
    /// A review job for a pane's panel finished.
    Review(PaneId, Box<crate::review_ui::Message>),
    /// The T3 Code page for a pane's folder was looked up.
    T3Page {
        pane: PaneId,
        dir: PathBuf,
        page: Result<crate::programs::t3::Page, String>,
    },
    /// A message from a web app's view in a pane.
    WebMessage(PaneId, WebKind, String),
    /// A one-time link that pairs a pane's T3 Code view, or why there is none.
    T3Pairing {
        pane: PaneId,
        link: Result<String, String>,
    },
    /// VS Code's server is running (or isn't), for what a pane asked to see.
    CodeReady {
        pane: PaneId,
        request: crate::app::CodeRequest,
        server: Result<crate::programs::vscode::Server, String>,
    },
    /// A hosted program asked for one of rustimal's shortcuts: the action's id.
    HostKey(String),
    /// A mouse button went down at this place on the screen, over a hosted program maybe.
    HostClick(i32, i32),
    /// News from the agent working for a pane's conversation.
    Chat {
        pane: PaneId,
        run: u64,
        update: crate::agent::chat::Update,
    },
}

#[derive(Clone)]
pub struct Listener {
    id: PaneId,
    proxy: EventLoopProxy<UserEvent>,
}

impl Listener {
    pub fn new(id: PaneId, proxy: EventLoopProxy<UserEvent>) -> Self {
        Self { id, proxy }
    }
}

impl EventListener for Listener {
    fn send_event(&self, event: TermEvent) {
        let _ = self.proxy.send_event(UserEvent::Term(self.id, event));
    }
}