"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/renderer/components/dock/terminal.store.ts" between
lens-5.1.2.tar.gz and lens-5.1.3.tar.gz

About: Lens is a Kubernetes IDE.

terminal.store.ts  (lens-5.1.2):terminal.store.ts  (lens-5.1.3)
skipping to change at line 22 skipping to change at line 22
* copies or substantial portions of the Software. * copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITN ESS * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITN ESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS O R * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS O R
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHE R * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHE R
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
import { autorun, observable } from "mobx"; import { autorun, observable, when } from "mobx";
import { autoBind, Singleton } from "../../utils"; import { autoBind, noop, Singleton } from "../../utils";
import { Terminal } from "./terminal"; import { Terminal } from "./terminal";
import { TerminalApi } from "../../api/terminal-api"; import { TerminalApi } from "../../api/terminal-api";
import { dockStore, DockTab, DockTabCreateSpecific, TabId, TabKind } from "./doc k.store"; import { dockStore, DockTab, DockTabCreateSpecific, TabId, TabKind } from "./doc k.store";
import { WebSocketApiState } from "../../api/websocket-api"; import { WebSocketApiState } from "../../api/websocket-api";
import { Notifications } from "../notifications";
export interface ITerminalTab extends DockTab { export interface ITerminalTab extends DockTab {
node?: string; // activate node shell mode node?: string; // activate node shell mode
} }
export function createTerminalTab(tabParams: DockTabCreateSpecific = {}) { export function createTerminalTab(tabParams: DockTabCreateSpecific = {}) {
return dockStore.createTab({ return dockStore.createTab({
title: `Terminal`, title: `Terminal`,
...tabParams, ...tabParams,
kind: TabKind.TERMINAL, kind: TabKind.TERMINAL,
skipping to change at line 67 skipping to change at line 68
// disconnect closed tabs // disconnect closed tabs
autorun(() => { autorun(() => {
const currentTabs = dockStore.tabs.map(tab => tab.id); const currentTabs = dockStore.tabs.map(tab => tab.id);
for (const [tabId] of this.connections) { for (const [tabId] of this.connections) {
if (!currentTabs.includes(tabId)) this.disconnect(tabId); if (!currentTabs.includes(tabId)) this.disconnect(tabId);
} }
}); });
} }
async connect(tabId: TabId) { connect(tabId: TabId) {
if (this.isConnected(tabId)) { if (this.isConnected(tabId)) {
return; return;
} }
const tab: ITerminalTab = dockStore.getTabById(tabId); const tab: ITerminalTab = dockStore.getTabById(tabId);
const api = new TerminalApi({ const api = new TerminalApi({
id: tabId, id: tabId,
node: tab.node, node: tab.node,
}); });
const terminal = new Terminal(tabId, api); const terminal = new Terminal(tabId, api);
skipping to change at line 107 skipping to change at line 108
} }
isConnected(tabId: TabId) { isConnected(tabId: TabId) {
return Boolean(this.connections.get(tabId)); return Boolean(this.connections.get(tabId));
} }
isDisconnected(tabId: TabId) { isDisconnected(tabId: TabId) {
return this.connections.get(tabId)?.readyState === WebSocketApiState.CLOSED; return this.connections.get(tabId)?.readyState === WebSocketApiState.CLOSED;
} }
sendCommand(command: string, options: { enter?: boolean; newTab?: boolean; tab Id?: TabId } = {}) { async sendCommand(command: string, options: { enter?: boolean; newTab?: boolea n; tabId?: TabId } = {}) {
const { enter, newTab, tabId } = options; const { enter, newTab, tabId } = options;
const { selectTab, getTabById } = dockStore;
const tab = tabId && getTabById(tabId);
if (tab) selectTab(tabId); if (tabId) {
if (newTab) createTerminalTab(); dockStore.selectTab(tabId);
}
if (newTab) {
const tab = createTerminalTab();
await when(() => this.connections.has(tab.id));
const rcIsFinished = when(() => this.connections.get(tab.id).shellRunComma
ndsFinished);
const notifyVeryLong = setTimeout(() => {
rcIsFinished.cancel();
Notifications.info("Terminal shell is taking a long time to complete sta
rtup. Please check your .rc file. Bypassing shell completion check.", {
timeout: 4_000,
});
}, 10_000);
await rcIsFinished.catch(noop);
clearTimeout(notifyVeryLong);
}
const terminalApi = this.connections.get(dockStore.selectedTabId); const terminalApi = this.connections.get(dockStore.selectedTabId);
if (terminalApi) { if (terminalApi) {
terminalApi.sendCommand(command + (enter ? "\r" : "")); terminalApi.sendCommand(command + (enter ? "\r" : ""));
} else {
console.warn("The selected tab is does not have a connection. Cannot send
command.", { tabId: dockStore.selectedTabId, command });
} }
} }
getTerminal(tabId: TabId) { getTerminal(tabId: TabId) {
return this.terminals.get(tabId); return this.terminals.get(tabId);
} }
reset() { reset() {
[...this.connections].forEach(([tabId]) => { [...this.connections].forEach(([tabId]) => {
this.disconnect(tabId); this.disconnect(tabId);
 End of changes. 7 change blocks. 
8 lines changed or deleted 30 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)