"Fossies" - the Fresh Open Source Software Archive  

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

About: Lens is a Kubernetes IDE.

terminal-api.ts  (lens-5.1.2):terminal-api.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 { stringify } from "querystring";
import { boundMethod, base64, EventEmitter } from "../utils"; import { boundMethod, base64, EventEmitter } from "../utils";
import { WebSocketApi } from "./websocket-api"; import { WebSocketApi } from "./websocket-api";
import isEqual from "lodash/isEqual"; import isEqual from "lodash/isEqual";
import { isDevelopment } from "../../common/vars"; import { isDevelopment } from "../../common/vars";
import url from "url";
import { makeObservable, observable } from "mobx";
import type { ParsedUrlQueryInput } from "querystring";
export enum TerminalChannels { export enum TerminalChannels {
STDIN = 0, STDIN = 0,
STDOUT = 1, STDOUT = 1,
STDERR = 2, STDERR = 2,
TERMINAL_SIZE = 4, TERMINAL_SIZE = 4,
TOKEN = 9, TOKEN = 9,
} }
enum TerminalColor { enum TerminalColor {
skipping to change at line 58 skipping to change at line 60
export type TerminalApiQuery = Record<string, string> & { export type TerminalApiQuery = Record<string, string> & {
id: string; id: string;
node?: string; node?: string;
type?: string | "node"; type?: string | "node";
}; };
export class TerminalApi extends WebSocketApi { export class TerminalApi extends WebSocketApi {
protected size: { Width: number; Height: number }; protected size: { Width: number; Height: number };
public onReady = new EventEmitter<[]>(); public onReady = new EventEmitter<[]>();
public isReady = false; @observable public isReady = false;
@observable public shellRunCommandsFinished = false;
public readonly url: string;
constructor(protected options: TerminalApiQuery) { constructor(protected options: TerminalApiQuery) {
super({ super({
logging: isDevelopment, logging: isDevelopment,
flushOnOpen: false, flushOnOpen: false,
pingIntervalSeconds: 30, pingIntervalSeconds: 30,
}); });
} makeObservable(this);
async getUrl() {
let { port } = location;
const { hostname, protocol } = location;
const { id, node } = this.options;
const wss = `ws${protocol === "https:" ? "s" : ""}://`;
const query: TerminalApiQuery = { id };
if (port) {
port = `:${port}`;
}
if (node) { const { hostname, protocol, port } = location;
query.node = node; const query: ParsedUrlQueryInput = {
query.type = "node"; id: options.id,
};
if (options.node) {
query.node = options.node;
query.type = options.type || "node";
} }
return `${wss}${hostname}${port}/api?${stringify(query)}`; this.url = url.format({
protocol: protocol.includes("https") ? "wss" : "ws",
hostname,
port,
pathname: "/api",
query,
slashes: true,
});
} }
async connect() { connect() {
const apiUrl = await this.getUrl();
this.emitStatus("Connecting ..."); this.emitStatus("Connecting ...");
this.onData.addListener(this._onReady, { prepend: true }); this.onData.addListener(this._onReady, { prepend: true });
this.onData.addListener(this._onShellRunCommandsFinished);
return super.connect(apiUrl); super.connect(this.url);
} }
destroy() { destroy() {
if (!this.socket) return; if (!this.socket) return;
const exitCode = String.fromCharCode(4); // ctrl+d const exitCode = String.fromCharCode(4); // ctrl+d
this.sendCommand(exitCode); this.sendCommand(exitCode);
setTimeout(() => super.destroy(), 2000); setTimeout(() => super.destroy(), 2000);
} }
removeAllListeners() { removeAllListeners() {
super.removeAllListeners(); super.removeAllListeners();
this.onReady.removeAllListeners(); this.onReady.removeAllListeners();
} }
_onShellRunCommandsFinished = (data: string) => {
if (!data) {
return;
}
/**
* This is a heuistic for ditermining when a shell has finished executing
* its own rc file (or RunCommands file) such as `.bashrc` or `.zshrc`.
*
* This heuistic assumes that the prompt line of a terminal is a single line
* and ends with a whitespace character.
*/
if (data.match(/\r?\n/) === null && data.match(/\s$/)) {
this.shellRunCommandsFinished = true;
this.onData.removeListener(this._onShellRunCommandsFinished);
}
};
@boundMethod @boundMethod
protected _onReady(data: string) { protected _onReady(data: string) {
if (!data) return true; if (!data) return true;
this.isReady = true; this.isReady = true;
this.onReady.emit(); this.onReady.emit();
this.onData.removeListener(this._onReady); this.onData.removeListener(this._onReady);
this.flush(); this.flush();
this.onData.emit(data); // re-emit data this.onData.emit(data); // re-emit data
return false; // prevent calling rest of listeners return false; // prevent calling rest of listeners
 End of changes. 9 change blocks. 
23 lines changed or deleted 44 lines changed or added

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