1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Add comments, switched to new names

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-07-20 09:40:28 -04:00
parent 7375304029
commit baae06d350
2 changed files with 16 additions and 15 deletions

View File

@ -58,7 +58,7 @@ export class TerminalApi extends WebSocketApi {
public onReady = new EventEmitter<[]>(); public onReady = new EventEmitter<[]>();
@observable public isReady = false; @observable public isReady = false;
@observable public rcFinished = false; @observable public shellRunCommandsFinished = false;
public readonly url: string; public readonly url: string;
constructor(protected options: TerminalApiQuery) { constructor(protected options: TerminalApiQuery) {
@ -92,7 +92,7 @@ export class TerminalApi extends WebSocketApi {
connect() { connect() {
this.emitStatus("Connecting ..."); this.emitStatus("Connecting ...");
this.onData.addListener(this._onReady, { prepend: true }); this.onData.addListener(this._onReady, { prepend: true });
this.onData.addListener(this._onRcReady); this.onData.addListener(this._onShellRunCommandsFinished);
super.connect(this.url); super.connect(this.url);
} }
@ -109,14 +109,21 @@ export class TerminalApi extends WebSocketApi {
this.onReady.removeAllListeners(); this.onReady.removeAllListeners();
} }
_onRcReady = (data: string) => { _onShellRunCommandsFinished = (data: string) => {
if (!data) { if (!data) {
return; return;
} }
if (data.match(/\r?\n/) === null && data.endsWith(" ")) { /**
this.rcFinished = true; * This is a heuistic for ditermining when a shell has finished executing
this.onData.removeListener(this._onRcReady); * 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);
} }
}; };

View File

@ -117,21 +117,15 @@ export class TerminalStore extends Singleton {
await when(() => this.connections.has(tab.id)); await when(() => this.connections.has(tab.id));
const rcIsFinished = when(() => this.connections.get(tab.id).rcFinished); const rcIsFinished = when(() => this.connections.get(tab.id).shellRunCommandsFinished);
const notifyLong = setTimeout(() => {
Notifications.info("Terminal shell is taking a long time to complete startup. Please check your .rc file.", {
timeout: 4_000,
});
}, 2_500);
const notifyVeryLong = setTimeout(() => { const notifyVeryLong = setTimeout(() => {
rcIsFinished.cancel(); rcIsFinished.cancel();
Notifications.info("Bypassing shell completion check.", { Notifications.info("Terminal shell is taking a long time to complete startup. Please check your .rc file. Bypassing shell completion check.", {
timeout: 4_000, timeout: 4_000,
}); });
}, 7_500); }, 10_000);
await rcIsFinished.catch(noop); await rcIsFinished.catch(noop);
clearTimeout(notifyLong);
clearTimeout(notifyVeryLong); clearTimeout(notifyVeryLong);
} }