use std::time::Duration; use crossterm::event::KeyEvent; use entity::NanoId; use fil_api::ChangeSet; use fil_core::ZettelId; // wire types, carried in messages pub use crate::client::{Snapshot, TodoUpdate}; /// All messages the event loop feeds into `update`. #[derive(Debug)] pub enum Msg { Tick, Resize, Key(KeyEvent), /// The event stream to the daemon is open. EventsConnected, /// The event stream closed or couldn't open; why, for the status line. EventsDisconnected(String), /// The daemon published changes. Changes(ChangeSet), /// The daemon dropped changes this client was too slow to receive. Resync, SnapshotLoaded(Snapshot), SnapshotFailed(String), /// A zettel's body, or why it couldn't be fetched, for fetch `ticket`. BodyFetched { id: ZettelId, ticket: u64, body: Result, }, /// The daemon's ranking for search `seq`. SearchResults { seq: u64, results: Result, String>, }, /// Raw file contents of `id`, front matter included. FileFetched { id: ZettelId, contents: String, }, FileFetchFailed(String), /// The editor exited. `result` holds the edited temp file's contents, or /// why the editor couldn't run. EditorClosed { id: ZettelId, original: String, result: Result, }, ZettelSaved, ZettelSaveFailed(String), /// A zettel was created; select it once its change arrives and open it. ZettelCreated(ZettelId), ZettelCreateFailed(String), /// A task or group was created; select it once its change arrives. TodoCreated(NanoId), /// A todo item was toggled or edited. TodoUpdated, TodoMutationFailed(String), } /// Side effects `update` hands back to the event loop. #[derive(Debug)] pub enum Cmd { /// Opens the event stream to the daemon after waiting `after`; it /// reports back until it closes. The wait is the reconnect backoff. Subscribe { after: Duration, }, /// Fetches the full state, to (re)sync from, after waiting `after`; the /// wait is the retry backoff after a failed fetch. FetchSnapshot { after: Duration, }, /// Fetches `id`'s body to show; `ticket` tells a stale response apart. FetchBody { id: ZettelId, ticket: u64, }, /// Asks the daemon to rank zettels for `query`. Search { seq: u64, query: String, }, /// Fetches the raw file for `id` from the daemon. FetchFile(ZettelId), /// Dumps `contents` to a temp file and hands the terminal to the editor /// on it. Run inline by the event loop rather than spawned, since it /// needs exclusive use of the TUI. OpenEditor { id: ZettelId, contents: String, }, /// Hands the terminal back to the shell (Ctrl-Z). Run inline by the /// event loop, like `OpenEditor`. Suspend, /// Uploads the edited file for `id`; the daemon overwrites it. SaveFile { id: ZettelId, contents: String, }, CreateZettel { title: String, }, CreateTask { name: String, group_id: NanoId, }, /// `parent_id: None` creates a top-level group. CreateGroup { name: String, parent_id: Option, }, /// Flips the task between finished and unfinished. ToggleTask(NanoId), /// Saves an inspector edit. UpdateTodo(TodoUpdate), }