tab_api/
client.rs

1//! Requests and Responses, communicated between `tab-cli` and `tab-daemon`.
2
3use crate::chunk::OutputChunk;
4use crate::{
5    chunk::InputChunk,
6    tab::{CreateTabMetadata, TabId, TabMetadata},
7};
8use serde::{Deserialize, Serialize};
9use std::collections::HashMap;
10/// A request, sent from a CLI connection to the daemon process.
11#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
12pub enum Request {
13    /// Subscribes to stdout/stderr on the given tab
14    /// The WebSocket will produce a series of Chunk messages,
15    /// The messages will have incrementing (but not sequential) indices.
16    /// The messages may begin with data from the scrollback buffer
17    Subscribe(TabId),
18
19    /// Deactivates the subscription for the given tab.
20    Unsubscribe(TabId),
21
22    /// Sends the stdin data to the given tab
23    Input(TabId, InputChunk),
24
25    /// Terminates the shell on the given tab
26    CreateTab(CreateTabMetadata),
27
28    /// Resizes the given tab, to the provided (cols, rows)
29    ResizeTab(TabId, (u16, u16)),
30
31    /// Re-tasks clients with the tabid selected to the given tab
32    Retask(TabId, TabId),
33
34    /// Terminates the shell on the given tab
35    CloseTab(TabId),
36
37    /// Disconnects any sessions for the given tab
38    DisconnectTab(TabId),
39
40    /// Shuts down all tab processes, including the daemon and all ptys
41    GlobalShutdown,
42}
43
44/// A response, sent from the daemon process to a connected CLI
45#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
46pub enum Response {
47    /// An initial 'hello' message with introductory state, including a full list of running tabs.
48    Init(InitResponse),
49    /// A raw output chunk, identified by a `TabId` and an index.
50    Output(TabId, OutputChunk),
51    /// A notification that metadata about a running tab has changed.
52    TabUpdate(TabMetadata),
53    /// A notification that the client is being re-tasks, and will now be serving the user on another tab.
54    Retask(TabId),
55    /// A notification that the active tab has been terminated
56    TabTerminated(TabId),
57    /// A notification that the client should disconnect
58    Disconnect,
59}
60
61/// An initialization message sent to CLI connections.
62#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
63pub struct InitResponse {
64    /// A complete set of active tabs, identified by TabId values.
65    pub tabs: HashMap<TabId, TabMetadata>,
66}