mouser_mode_api/mode.rs
1//! What a mode asks of the host, and where it may draw.
2
3use crate::ui::{Rect, Viewport};
4use std::path::PathBuf;
5
6/// Where a mode may draw.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
8pub struct Context {
9 pub viewport: Viewport,
10 /// The terminal area (left of the sidebar, below the tab strip); the view
11 /// takes its top part and the terminal grid moves down.
12 pub area: Rect,
13 /// Skip motion such as the fullscreen viewer open/close transition
14 /// (`appearance.reduce_motion` in preferences.toml).
15 #[serde(default)]
16 pub reduce_motion: bool,
17}
18
19/// What the mode asks Mouser to do. The host checks each one against the
20/// plugin's granted permissions (`Type` and `Run` need `shell.type`).
21#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
22pub enum Effect {
23 None,
24 /// Type this into the shell.
25 Type(String),
26 /// Run a command line in the shell; what the user has typed is kept
27 /// (cut to the kill ring and yanked back when the prompt returns).
28 Run(String),
29 /// Change the shell's directory (commander's sync): silently through the
30 /// shell integration (Fuzzball `s c`, fuzzball docs/shell.md), at the next
31 /// prompt when a command runs. Never typed: without an integration the
32 /// host says so in the status bar instead.
33 Cd(PathBuf),
34 /// Hand a file to the desktop's opener (players etc.).
35 Open(PathBuf),
36 /// Open a link (a Markdown link clicked in chat): web, mail and file
37 /// links only, never through a shell.
38 OpenLink(String),
39 /// Show the key mappings window.
40 ShowKeys,
41 /// Status-bar message.
42 Say(String),
43 /// Not handled now: the key goes to the shell.
44 Pass,
45}
46
47impl Effect {
48 /// The permission the host requires before carrying this out.
49 pub fn permission(&self) -> Option<&'static str> {
50 match self {
51 Effect::Type(_) | Effect::Run(_) | Effect::Cd(_) => Some("shell.type"),
52 Effect::Open(_) => Some("files.read"),
53 _ => None,
54 }
55 }
56}