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

Fix shell connection readiness heuristic (#3795)

This commit is contained in:
Sebastian Malton 2021-09-15 17:40:36 -04:00 committed by GitHub
parent 056b818ceb
commit be1a2ebe59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 26 deletions

View File

@ -58,7 +58,6 @@ export class TerminalApi extends WebSocketApi {
public onReady = new EventEmitter<[]>();
@observable public isReady = false;
@observable public shellRunCommandsFinished = false;
public readonly url: string;
constructor(protected options: TerminalApiQuery) {
@ -92,7 +91,6 @@ export class TerminalApi extends WebSocketApi {
connect() {
this.emitStatus("Connecting ...");
this.onData.addListener(this._onReady, { prepend: true });
this.onData.addListener(this._onShellRunCommandsFinished);
super.connect(this.url);
}
@ -109,24 +107,6 @@ export class TerminalApi extends WebSocketApi {
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
protected _onReady(data: string) {
if (!data) return true;

View File

@ -117,15 +117,18 @@ export class TerminalStore extends Singleton {
await when(() => this.connections.has(tab.id));
const rcIsFinished = when(() => this.connections.get(tab.id).shellRunCommandsFinished);
const shellIsReady = when(() => this.connections.get(tab.id).isReady);
const notifyVeryLong = setTimeout(() => {
rcIsFinished.cancel();
Notifications.info("Terminal shell is taking a long time to complete startup. Please check your .rc file. Bypassing shell completion check.", {
timeout: 4_000,
});
shellIsReady.cancel();
Notifications.info(
"If terminal shell is not ready please check your shell init files, if applicable.",
{
timeout: 4_000,
},
);
}, 10_000);
await rcIsFinished.catch(noop);
await shellIsReady.catch(noop);
clearTimeout(notifyVeryLong);
}