Skip to main content

taba_cli/tui/msg/
mod.rs

1//! Everything that can happen to the interface (doc 34, section 4): a key, a tick of the clock, a reply that came
2//! back from a worker. `update` takes one at a time.
3
4use ratatui::crossterm::event::KeyEvent;
5use taba_client::{Error, Reply};
6
7use crate::profile::ConfigFile;
8use crate::tui::api::ApiCall;
9use crate::tui::keymap::Action;
10
11#[derive(Debug)]
12pub enum Msg {
13    Key(KeyEvent),
14    /// The wheel: lines to scroll (negative is up).
15    Scroll(i16),
16    Resize(u16, u16),
17    /// The terminal gained or lost the focus: the reading pauses while it is away.
18    Focus(bool),
19    /// The clock: milliseconds since the app opened, and the wall clock (UTC, ms since the epoch).
20    Tick {
21        now: u64,
22        wall_ms: i64,
23    },
24    /// An action chosen in the command palette.
25    Action(Action),
26    /// A worker's answer, marked with the request and the generation it was asked in.
27    Reply {
28        id: u64,
29        generation: u64,
30        call: ApiCall,
31        result: Result<Reply, Error>,
32    },
33    /// The result of writing a file the person asked for.
34    FileWritten {
35        path: String,
36        result: Result<(), String>,
37    },
38    /// The result of saving the language.
39    LanguageSaved(Result<(), String>),
40    /// Text pasted into the terminal.
41    Paste(String),
42    /// The result of writing the profiles file; `select` is the profile to leave selected.
43    ProfilesSaved {
44        file: ConfigFile,
45        select: Option<String>,
46        result: Result<(), String>,
47    },
48    /// The result of testing a connection with the values of a form.
49    ProfileChecked(CheckResult),
50    /// The result of connecting with a profile.
51    Connected {
52        profile: String,
53        url: String,
54        result: Result<(), String>,
55    },
56}
57
58/// How testing the connection of a profile went (the screens say it in the person's language).
59#[derive(Debug, Clone, PartialEq, Eq)]
60pub enum CheckResult {
61    /// The server answered: its address and how long it took.
62    Reachable { url: String, millis: u64 },
63    /// The server refused the token (`401` or `403`).
64    Refused { url: String, status: u16 },
65    /// The server answered something else.
66    Answered {
67        url: String,
68        status: u16,
69        code: String,
70    },
71    /// Nothing could be tried or nobody answered (a token file that cannot be read, no connection).
72    Failed(String),
73}