UNPKG

5.98 kBTypeScriptView Raw
1import { Cell } from '@jupyterlab/cells';
2import { ISessionContext } from '@jupyterlab/apputils';
3import { CodeEditor } from '@jupyterlab/codeeditor';
4import { KernelMessage } from '@jupyterlab/services';
5import { ITranslator } from '@jupyterlab/translation';
6import { IDisposable } from '@lumino/disposable';
7/**
8 * The definition of a console history manager object.
9 */
10export interface INotebookHistory extends IDisposable {
11 /**
12 * The current editor used by the history widget.
13 */
14 editor: CodeEditor.IEditor | null;
15 /**
16 * The placeholder text that a history session began with.
17 */
18 readonly placeholder: string;
19 /**
20 * The session number of the current kernel session
21 */
22 readonly kernelSession: string;
23 /**
24 * Get the previous item in the console history.
25 *
26 * @param activeCell - The currently selected Cell in the notebook.
27 *
28 * @returns A Promise for console command text or `undefined` if unavailable.
29 */
30 back(activeCell: Cell): Promise<string | undefined>;
31 /**
32 * Get the next item in the console history.
33 *
34 * @param activeCell - The currently selected Cell in the notebook.
35 *
36 * @returns A Promise for console command text or `undefined` if unavailable.
37 */
38 forward(activeCell: Cell): Promise<string | undefined>;
39 /**
40 * Reset the history navigation state, i.e., start a new history session.
41 */
42 reset(): void;
43 /**
44 * Get the next item in the console history.
45 *
46 * @param activeCell - The currently selected Cell in the notebook.
47 * @param content - the result from back or forward
48 */
49 updateEditor(activeCell: Cell, content: string | undefined): void;
50}
51/**
52 * A console history manager object.
53 */
54export declare class NotebookHistory implements INotebookHistory {
55 /**
56 * Construct a new console history object.
57 */
58 constructor(options: NotebookHistory.IOptions);
59 /**
60 * The client session used to query history.
61 */
62 private _sessionContext;
63 /**
64 * Translator to be used for warnings
65 */
66 private _trans;
67 /**
68 * The number of history items to request.
69 */
70 private _toRequest;
71 /**
72 * The number of history items to increase a batch size by per subsequent request.
73 */
74 private _requestBatchSize;
75 /**
76 * The current editor used by the history manager.
77 */
78 get editor(): CodeEditor.IEditor | null;
79 set editor(value: CodeEditor.IEditor | null);
80 /**
81 * The placeholder text that a history session began with.
82 */
83 get placeholder(): string;
84 /**
85 * Kernel session number for filtering
86 */
87 get kernelSession(): string;
88 /**
89 * Get whether the notebook history manager is disposed.
90 */
91 get isDisposed(): boolean;
92 /**
93 * Dispose of the resources held by the notebook history manager.
94 */
95 dispose(): void;
96 /**
97 * Set placeholder and editor. Start session if one is not already started.
98 *
99 * @param activeCell - The currently selected Cell in the notebook.
100 */
101 protected checkSession(activeCell: Cell): Promise<void>;
102 /**
103 * Get the previous item in the notebook history.
104 *
105 * @param activeCell - The currently selected Cell in the notebook.
106 *
107 * @returns A Promise resolving to the historical cell content text.
108 */
109 back(activeCell: Cell): Promise<string | undefined>;
110 /**
111 * Get the next item in the notebook history.
112 *
113 * @param activeCell - The currently selected Cell in the notebook.
114 *
115 * @returns A Promise resolving to the historical cell content text.
116 */
117 forward(activeCell: Cell): Promise<string | undefined>;
118 /**
119 * Update the editor of the cell with provided text content.
120 *
121 * @param activeCell - The currently selected Cell in the notebook.
122 * @param content - the result from back or forward
123 */
124 updateEditor(activeCell: Cell, content: string | undefined): void;
125 /**
126 * Reset the history navigation state, i.e., start a new history session.
127 */
128 reset(): void;
129 /**
130 * Fetches a subsequent batch of history. Updates the filtered history and cursor to correct place in history,
131 * accounting for potentially new history items above it.
132 */
133 private fetchBatch;
134 /**
135 * Populate the history collection on history reply from a kernel.
136 *
137 * @param value The kernel message history reply.
138 *
139 * #### Notes
140 * History entries have the shape:
141 * [session: number, line: number, input: string]
142 * Contiguous duplicates are stripped out of the API response.
143 */
144 protected onHistory(value: KernelMessage.IHistoryReplyMsg, cell?: Cell): void;
145 /**
146 * Handle a text change signal from the editor.
147 */
148 protected onTextChange(): void;
149 /**
150 * Handle the current kernel changing.
151 */
152 private _handleKernel;
153 /**
154 * retrieve the history from the kernel
155 *
156 * @param cell - The string to use when filtering the data.
157 */
158 private _retrieveHistory;
159 /**
160 * Set the filter data.
161 *
162 * @param filterStr - The string to use when filtering the data.
163 */
164 protected setFilter(filterStr?: string): void;
165 private _cursor;
166 private _hasSession;
167 private _history;
168 private _placeholder;
169 private _kernelSession;
170 private _setByHistory;
171 private _isDisposed;
172 private _editor;
173 private _filtered;
174 private _kernel;
175}
176/**
177 * A namespace for NotebookHistory statics.
178 */
179export declare namespace NotebookHistory {
180 /**
181 * The initialization options for a console history object.
182 */
183 interface IOptions {
184 /**
185 * The client session used by the foreign handler.
186 */
187 sessionContext: ISessionContext;
188 /**
189 * The application language translator.
190 */
191 translator?: ITranslator;
192 }
193}