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