diff --git a/tabby-serial/package.json b/tabby-serial/package.json index 62014bf1..a5bb362c 100644 --- a/tabby-serial/package.json +++ b/tabby-serial/package.json @@ -18,8 +18,7 @@ "license": "MIT", "devDependencies": { "@types/node": "14.14.14", - "ansi-colors": "^4.1.1", - "cli-spinner": "^0.2.10" + "ansi-colors": "^4.1.1" }, "peerDependencies": { "@angular/animations": "^9.1.9", diff --git a/tabby-serial/src/components/serialTab.component.ts b/tabby-serial/src/components/serialTab.component.ts index b68670ea..971868dc 100644 --- a/tabby-serial/src/components/serialTab.component.ts +++ b/tabby-serial/src/components/serialTab.component.ts @@ -1,6 +1,5 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import colors from 'ansi-colors' -import { Spinner } from 'cli-spinner' import { Component, Injector } from '@angular/core' import { first } from 'rxjs/operators' import { SelectorService } from 'tabby-core' @@ -68,21 +67,14 @@ export class SerialTabComponent extends BaseTerminalTabComponent { this.setSession(session) this.write(`Connecting to `) - const spinner = new Spinner({ - text: 'Connecting', - stream: { - write: x => this.write(x), - }, - }) - spinner.setSpinnerString(6) - spinner.start() + this.startSpinner('Connecting') try { await this.session!.start() - spinner.stop(true) + this.stopSpinner() session.emitServiceMessage('Port opened') } catch (e) { - spinner.stop(true) + this.stopSpinner() this.write(colors.black.bgRed(' X ') + ' ' + colors.red(e.message) + '\r\n') return } diff --git a/tabby-ssh/package.json b/tabby-ssh/package.json index 2ba320e9..fa1c6ee0 100644 --- a/tabby-ssh/package.json +++ b/tabby-ssh/package.json @@ -24,7 +24,6 @@ "@types/node": "14.14.31", "@types/ssh2": "^0.5.46", "ansi-colors": "^4.1.1", - "cli-spinner": "^0.2.10", "ssh2": "^1.1.0", "sshpk": "Eugeny/node-sshpk#89ed17dfae425a8b629873c8337e77d26838c04f", "strip-ansi": "^7.0.0" diff --git a/tabby-ssh/src/components/sshTab.component.ts b/tabby-ssh/src/components/sshTab.component.ts index 8f5c07c7..15f04738 100644 --- a/tabby-ssh/src/components/sshTab.component.ts +++ b/tabby-ssh/src/components/sshTab.component.ts @@ -1,5 +1,4 @@ import colors from 'ansi-colors' -import { Spinner } from 'cli-spinner' import { Component, Injector, HostListener } from '@angular/core' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' import { first } from 'rxjs/operators' @@ -26,13 +25,6 @@ export class SSHTabComponent extends BaseTerminalTabComponent { private sessionStack: SSHSession[] = [] private recentInputs = '' private reconnectOffered = false - private spinner = new Spinner({ - text: 'Connecting', - stream: { - write: x => this.write(x), - }, - }) - private spinnerActive = false constructor ( injector: Injector, @@ -120,13 +112,11 @@ export class SSHTabComponent extends BaseTerminalTabComponent { this.write('\r\n' + colors.black.bgWhite(' SSH ') + ` Connecting to ${session.profile.options.host}\r\n`) - this.startSpinner() + this.startSpinner('Connecting') this.attachSessionHandler(session.serviceMessage$, msg => { - this.pauseSpinner(() => { - this.write(`\r${colors.black.bgWhite(' SSH ')} ${msg}\r\n`) - session.resize(this.size.columns, this.size.rows) - }) + this.write(`\r${colors.black.bgWhite(' SSH ')} ${msg}\r\n`) + session.resize(this.size.columns, this.size.rows) }) try { @@ -232,24 +222,4 @@ export class SSHTabComponent extends BaseTerminalTabComponent { onClick (): void { this.sftpPanelVisible = false } - - private startSpinner () { - this.spinner.setSpinnerString(6) - this.spinner.start() - this.spinnerActive = true - } - - private stopSpinner () { - this.spinner.stop(true) - this.spinnerActive = false - } - - private pauseSpinner (work: () => void) { - const wasActive = this.spinnerActive - this.stopSpinner() - work() - if (wasActive) { - this.startSpinner() - } - } } diff --git a/tabby-ssh/src/services/ssh.service.ts b/tabby-ssh/src/services/ssh.service.ts index 368ba70b..e3afa5e0 100644 --- a/tabby-ssh/src/services/ssh.service.ts +++ b/tabby-ssh/src/services/ssh.service.ts @@ -1,6 +1,6 @@ import colors from 'ansi-colors' import { Duplex } from 'stream' -import { Injectable, Injector, NgZone } from '@angular/core' +import { Injectable, NgZone } from '@angular/core' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' import { Client } from 'ssh2' import { exec } from 'child_process' @@ -16,8 +16,7 @@ export class SSHService { private detectedWinSCPPath: string | null private constructor ( - private injector: Injector, - private log: LogService, + log: LogService, private zone: NgZone, private ngbModal: NgbModal, private passwordStorage: PasswordStorageService, diff --git a/tabby-ssh/yarn.lock b/tabby-ssh/yarn.lock index 4aaa884e..fa5c792c 100644 --- a/tabby-ssh/yarn.lock +++ b/tabby-ssh/yarn.lock @@ -74,11 +74,6 @@ brace-expansion@^1.1.7: balanced-match "^1.0.0" concat-map "0.0.1" -cli-spinner@^0.2.10: - version "0.2.10" - resolved "https://registry.yarnpkg.com/cli-spinner/-/cli-spinner-0.2.10.tgz#f7d617a36f5c47a7bc6353c697fc9338ff782a47" - integrity sha512-U0sSQ+JJvSLi1pAYuJykwiA8Dsr15uHEy85iCJ6A+0DjVxivr3d+N2Wjvodeg89uP5K6TswFkKBfAD7B3YSn/Q== - cli@0.4.x: version "0.4.5" resolved "https://registry.yarnpkg.com/cli/-/cli-0.4.5.tgz#78f9485cd161b566e9a6c72d7170c4270e81db61" diff --git a/tabby-telnet/package.json b/tabby-telnet/package.json index b623c903..3e47b2ba 100644 --- a/tabby-telnet/package.json +++ b/tabby-telnet/package.json @@ -17,8 +17,7 @@ "author": "Eugene Pankov", "license": "MIT", "devDependencies": { - "@types/node": "14.14.31", - "cli-spinner": "^0.2.10" + "@types/node": "14.14.31" }, "peerDependencies": { "@angular/animations": "^9.1.9", diff --git a/tabby-telnet/src/components/telnetTab.component.ts b/tabby-telnet/src/components/telnetTab.component.ts index 9938dac2..31902b35 100644 --- a/tabby-telnet/src/components/telnetTab.component.ts +++ b/tabby-telnet/src/components/telnetTab.component.ts @@ -1,5 +1,4 @@ import colors from 'ansi-colors' -import { Spinner } from 'cli-spinner' import { Component, Injector } from '@angular/core' import { first } from 'rxjs/operators' import { Platform, RecoveryToken } from 'tabby-core' @@ -19,13 +18,6 @@ export class TelnetTabComponent extends BaseTerminalTabComponent { profile?: TelnetProfile session: TelnetSession|null = null private reconnectOffered = false - private spinner = new Spinner({ - text: 'Connecting', - stream: { - write: x => this.write(x), - }, - }) - private spinnerActive = false // eslint-disable-next-line @typescript-eslint/no-useless-constructor constructor ( @@ -84,13 +76,11 @@ export class TelnetTabComponent extends BaseTerminalTabComponent { this.setSession(session) try { - this.startSpinner() + this.startSpinner('Connecting') this.attachSessionHandler(session.serviceMessage$, msg => { - this.pauseSpinner(() => { - this.write(`\r${colors.black.bgWhite(' Telnet ')} ${msg}\r\n`) - session.resize(this.size.columns, this.size.rows) - }) + this.write(`\r${colors.black.bgWhite(' Telnet ')} ${msg}\r\n`) + session.resize(this.size.columns, this.size.rows) }) try { @@ -133,24 +123,4 @@ export class TelnetTabComponent extends BaseTerminalTabComponent { } )).response === 1 } - - private startSpinner () { - this.spinner.setSpinnerString(6) - this.spinner.start() - this.spinnerActive = true - } - - private stopSpinner () { - this.spinner.stop(true) - this.spinnerActive = false - } - - private pauseSpinner (work: () => void) { - const wasActive = this.spinnerActive - this.stopSpinner() - work() - if (wasActive) { - this.startSpinner() - } - } } diff --git a/tabby-terminal/package.json b/tabby-terminal/package.json index 96011bb0..6ba212ce 100644 --- a/tabby-terminal/package.json +++ b/tabby-terminal/package.json @@ -27,6 +27,7 @@ "dataurl": "0.1.0", "deep-equal": "2.0.5", "ps-node": "^0.1.6", + "cli-spinner": "^0.2.10", "runes": "^0.4.2", "shell-escape": "^0.2.0", "utils-decorators": "^1.8.1", diff --git a/tabby-terminal/src/api/baseTerminalTab.component.ts b/tabby-terminal/src/api/baseTerminalTab.component.ts index cbfafcea..42af78d8 100644 --- a/tabby-terminal/src/api/baseTerminalTab.component.ts +++ b/tabby-terminal/src/api/baseTerminalTab.component.ts @@ -1,5 +1,6 @@ import { Observable, Subject, Subscription } from 'rxjs' import { first } from 'rxjs/operators' +import { Spinner } from 'cli-spinner' import colors from 'ansi-colors' import { NgZone, OnInit, OnDestroy, Injector, ViewChild, HostBinding, Input, ElementRef, InjectFlags } from '@angular/core' import { trigger, transition, style, animate, AnimationTriggerMetadata } from '@angular/animations' @@ -119,6 +120,12 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit private allFocusModeSubscription: Subscription|null = null private sessionHandlers = new SubscriptionContainer() private sessionSupportsBracketedPaste = false + private spinner = new Spinner({ + stream: { + write: x => this.writeRaw(x), + }, + }) + private spinnerActive = false get input$ (): Observable { if (!this.frontend) { @@ -369,6 +376,12 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit * Feeds input into the terminal frontend */ write (data: string): void { + this.withSpinnerPaused(() => { + this.writeRaw(data) + }) + } + + protected writeRaw (data: string): void { if (!this.frontend) { throw new Error('Frontend not ready') } @@ -666,4 +679,33 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit protected detachSessionHandlers (): void { this.sessionHandlers.cancelAll() } + + protected startSpinner (text?: string): void { + if (this.spinnerActive) { + return + } + if (text) { + this.spinner.text = text + } + this.spinner.setSpinnerString(6) + this.spinner.start() + this.spinnerActive = true + } + + protected stopSpinner (): void { + if (!this.spinnerActive) { + return + } + this.spinner.stop(true) + this.spinnerActive = false + } + + protected withSpinnerPaused (work: () => void): void { + const wasActive = this.spinnerActive + this.stopSpinner() + work() + if (wasActive) { + this.startSpinner() + } + } } diff --git a/tabby-terminal/src/session.ts b/tabby-terminal/src/session.ts index 1b8bab93..5473ddc4 100644 --- a/tabby-terminal/src/session.ts +++ b/tabby-terminal/src/session.ts @@ -1,6 +1,5 @@ import { Observable, Subject } from 'rxjs' - /** * A session object for a [[BaseTerminalTabComponent]] * Extend this to implement custom I/O and process management for your terminal tab diff --git a/tabby-terminal/yarn.lock b/tabby-terminal/yarn.lock index a1216a35..ca947be1 100644 --- a/tabby-terminal/yarn.lock +++ b/tabby-terminal/yarn.lock @@ -52,6 +52,11 @@ call-bind@^1.0.0, call-bind@^1.0.2: function-bind "^1.1.1" get-intrinsic "^1.0.2" +cli-spinner@^0.2.10: + version "0.2.10" + resolved "https://registry.yarnpkg.com/cli-spinner/-/cli-spinner-0.2.10.tgz#f7d617a36f5c47a7bc6353c697fc9338ff782a47" + integrity sha512-U0sSQ+JJvSLi1pAYuJykwiA8Dsr15uHEy85iCJ6A+0DjVxivr3d+N2Wjvodeg89uP5K6TswFkKBfAD7B3YSn/Q== + connected-domain@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/connected-domain/-/connected-domain-1.0.0.tgz#bfe77238c74be453a79f0cb6058deeb4f2358e93"