1 | import { JSONPrimitive } from '@lumino/coreutils';
|
2 | import { IObservableDisposable } from '@lumino/disposable';
|
3 | import { ISignal } from '@lumino/signaling';
|
4 | import { ServerConnection } from '..';
|
5 | import { IManager as IBaseManager } from '../basemanager';
|
6 | import { IModel, isAvailable } from './restapi';
|
7 | export { IModel, isAvailable };
|
8 | export declare namespace ITerminal {
|
9 | interface IOptions {
|
10 | /**
|
11 | * The terminal name.
|
12 | */
|
13 | name?: string;
|
14 | /**
|
15 | * The terminal current directory.
|
16 | */
|
17 | cwd?: string;
|
18 | }
|
19 | }
|
20 | /**
|
21 | * An interface for a terminal session.
|
22 | */
|
23 | export interface ITerminalConnection extends IObservableDisposable {
|
24 | /**
|
25 | * A signal emitted when a message is received from the server.
|
26 | */
|
27 | messageReceived: ISignal<ITerminalConnection, IMessage>;
|
28 | /**
|
29 | * Get the name of the terminal session.
|
30 | */
|
31 | readonly name: string;
|
32 | /**
|
33 | * The model associated with the session.
|
34 | */
|
35 | readonly model: IModel;
|
36 | /**
|
37 | * The server settings for the session.
|
38 | */
|
39 | readonly serverSettings: ServerConnection.ISettings;
|
40 | /**
|
41 | * The current connection status of the terminal.
|
42 | */
|
43 | readonly connectionStatus: ConnectionStatus;
|
44 | /**
|
45 | * A signal emitted when the terminal connection status changes.
|
46 | */
|
47 | connectionStatusChanged: ISignal<this, ConnectionStatus>;
|
48 | /**
|
49 | * Send a message to the terminal session.
|
50 | */
|
51 | send(message: IMessage): void;
|
52 | /**
|
53 | * Reconnect to the terminal.
|
54 | *
|
55 | * @returns A promise that resolves when the terminal has reconnected.
|
56 | */
|
57 | reconnect(): Promise<void>;
|
58 | /**
|
59 | * Shut down the terminal session.
|
60 | */
|
61 | shutdown(): Promise<void>;
|
62 | }
|
63 | export declare namespace ITerminalConnection {
|
64 | interface IOptions {
|
65 | /**
|
66 | * Terminal model.
|
67 | */
|
68 | model: IModel;
|
69 | /**
|
70 | * The server settings.
|
71 | */
|
72 | serverSettings?: ServerConnection.ISettings;
|
73 | }
|
74 | }
|
75 | /**
|
76 | * A message from the terminal session.
|
77 | */
|
78 | export interface IMessage {
|
79 | /**
|
80 | * The type of the message.
|
81 | */
|
82 | readonly type: MessageType;
|
83 | /**
|
84 | * The content of the message.
|
85 | */
|
86 | readonly content?: JSONPrimitive[];
|
87 | }
|
88 | /**
|
89 | * Valid message types for the terminal.
|
90 | */
|
91 | export type MessageType = 'stdout' | 'disconnect' | 'set_size' | 'stdin';
|
92 | /**
|
93 | * The interface for a terminal manager.
|
94 | *
|
95 | * #### Notes
|
96 | * The manager is responsible for maintaining the state of running
|
97 | * terminal sessions.
|
98 | */
|
99 | export interface IManager extends IBaseManager {
|
100 | /**
|
101 | * A signal emitted when the running terminals change.
|
102 | */
|
103 | runningChanged: ISignal<IManager, IModel[]>;
|
104 | /**
|
105 | * A signal emitted when there is a connection failure.
|
106 | */
|
107 | connectionFailure: ISignal<IManager, ServerConnection.NetworkError>;
|
108 | /**
|
109 | * Test whether the manager is ready.
|
110 | */
|
111 | readonly isReady: boolean;
|
112 | /**
|
113 | * A promise that fulfills when the manager is ready.
|
114 | */
|
115 | readonly ready: Promise<void>;
|
116 | /**
|
117 | * Whether the terminal service is available.
|
118 | */
|
119 | isAvailable(): boolean;
|
120 | /**
|
121 | * Create an iterator over the known running terminals.
|
122 | *
|
123 | * @returns A new iterator over the running terminals.
|
124 | */
|
125 | running(): IterableIterator<IModel>;
|
126 | /**
|
127 | * Create a new terminal session.
|
128 | *
|
129 | * @param options - The options used to create the terminal.
|
130 | *
|
131 | * @returns A promise that resolves with the terminal connection instance.
|
132 | *
|
133 | * #### Notes
|
134 | * The manager `serverSettings` will be always be used.
|
135 | */
|
136 | startNew(options?: ITerminal.IOptions): Promise<ITerminalConnection>;
|
137 | connectTo(options: Omit<ITerminalConnection.IOptions, 'serverSettings'>): ITerminalConnection;
|
138 | /**
|
139 | * Shut down a terminal session by name.
|
140 | *
|
141 | * @param name - The name of the terminal session.
|
142 | *
|
143 | * @returns A promise that resolves when the session is shut down.
|
144 | */
|
145 | shutdown(name: string): Promise<void>;
|
146 | /**
|
147 | * Shut down all terminal sessions.
|
148 | *
|
149 | * @returns A promise that resolves when all of the sessions are shut down.
|
150 | */
|
151 | shutdownAll(): Promise<void>;
|
152 | /**
|
153 | * Force a refresh of the running terminal sessions.
|
154 | *
|
155 | * @returns A promise that with the list of running sessions.
|
156 | *
|
157 | * #### Notes
|
158 | * This is not typically meant to be called by the user, since the
|
159 | * manager maintains its own internal state.
|
160 | */
|
161 | refreshRunning(): Promise<void>;
|
162 | }
|
163 | /**
|
164 | * The valid terminal connection states.
|
165 | *
|
166 | * #### Notes
|
167 | * The status states are:
|
168 | * * `connected`: The terminal connection is live.
|
169 | * * `connecting`: The terminal connection is not live, but we are attempting
|
170 | * to reconnect to the terminal.
|
171 | * * `disconnected`: The terminal connection is down, we are not
|
172 | * trying to reconnect.
|
173 | */
|
174 | export type ConnectionStatus = 'connected' | 'connecting' | 'disconnected';
|