1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! Requests and Responses, communicated between `tab-cli` and `tab-daemon`.

use crate::chunk::OutputChunk;
use crate::{
    chunk::InputChunk,
    tab::{CreateTabMetadata, TabId, TabMetadata},
};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
/// A request, sent from a CLI connection to the daemon process.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub enum Request {
    /// Subscribes to stdout/stderr on the given tab
    /// The WebSocket will produce a series of Chunk messages,
    /// The messages will have incrementing (but not sequential) indices.
    /// The messages may begin with data from the scrollback buffer
    Subscribe(TabId),

    /// Deactivates the subscription for the given tab.
    Unsubscribe(TabId),

    /// Sends the stdin data to the given tab
    Input(TabId, InputChunk),

    /// Terminates the shell on the given tab
    CreateTab(CreateTabMetadata),

    /// Resizes the given tab, to the provided (cols, rows)
    ResizeTab(TabId, (u16, u16)),

    /// Re-tasks clients with the tabid selected to the given tab
    Retask(TabId, TabId),

    /// Terminates the shell on the given tab
    CloseTab(TabId),

    /// Disconnects any sessions for the given tab
    DisconnectTab(TabId),

    /// Shuts down all tab processes, including the daemon and all ptys
    GlobalShutdown,
}

/// A response, sent from the daemon process to a connected CLI
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub enum Response {
    /// An initial 'hello' message with introductory state, including a full list of running tabs.
    Init(InitResponse),
    /// A raw output chunk, identified by a `TabId` and an index.
    Output(TabId, OutputChunk),
    /// A notification that metadata about a running tab has changed.
    TabUpdate(TabMetadata),
    /// A notification that the client is being re-tasks, and will now be serving the user on another tab.
    Retask(TabId),
    /// A notification that the active tab has been terminated
    TabTerminated(TabId),
    /// A notification that the client should disconnect
    Disconnect,
}

/// An initialization message sent to CLI connections.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct InitResponse {
    /// A complete set of active tabs, identified by TabId values.
    pub tabs: HashMap<TabId, TabMetadata>,
}