From 2b5f623b50cdbaafa4d4c07f0acfdfc550b926e9 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Wed, 1 Jan 2020 01:04:41 +0100 Subject: [PATCH] profile and SSH connection colors (fixes #954) --- terminus-core/src/services/app.service.ts | 11 +++++++++++ terminus-ssh/src/api.ts | 1 + .../src/components/editConnectionModal.component.pug | 11 +++++++++++ terminus-ssh/src/services/ssh.service.ts | 6 +++++- terminus-terminal/src/api/interfaces.ts | 5 +++-- .../src/components/editProfileModal.component.pug | 9 +++++++++ terminus-terminal/src/services/terminal.service.ts | 6 +++++- 7 files changed, 45 insertions(+), 4 deletions(-) diff --git a/terminus-core/src/services/app.service.ts b/terminus-core/src/services/app.service.ts index d4bed1a0..b7d8b74a 100644 --- a/terminus-core/src/services/app.service.ts +++ b/terminus-core/src/services/app.service.ts @@ -173,6 +173,17 @@ export class AppService { } } + getParentTab (tab: BaseTabComponent): SplitTabComponent|null { + for (const topLevelTab of this.tabs) { + if (topLevelTab instanceof SplitTabComponent) { + if (topLevelTab.getAllTabs().includes(tab)) { + return topLevelTab + } + } + } + return null + } + /** Switches between the current tab and the previously active one */ toggleLastTab () { if (!this.lastTabIndex || this.lastTabIndex >= this.tabs.length) { diff --git a/terminus-ssh/src/api.ts b/terminus-ssh/src/api.ts index 62abba41..23e0737a 100644 --- a/terminus-ssh/src/api.ts +++ b/terminus-ssh/src/api.ts @@ -30,6 +30,7 @@ export interface SSHConnection { keepaliveInterval?: number keepaliveCountMax?: number readyTimeout?: number + color?: string algorithms?: {[t: string]: string[]} } diff --git a/terminus-ssh/src/components/editConnectionModal.component.pug b/terminus-ssh/src/components/editConnectionModal.component.pug index b82bdcea..1d847077 100644 --- a/terminus-ssh/src/components/editConnectionModal.component.pug +++ b/terminus-ssh/src/components/editConnectionModal.component.pug @@ -67,6 +67,17 @@ button.btn.btn-secondary((click)='selectPrivateKey()') i.fas.fa-folder-open + .form-line + .header + .title Tab color + input.form-control( + type='text', + autofocus, + [(ngModel)]='connection.color', + placeholder='#000000' + ) + + ngb-tab(id='advanced') ng-template(ngbTabTitle) Advanced ng-template(ngbTabContent) diff --git a/terminus-ssh/src/services/ssh.service.ts b/terminus-ssh/src/services/ssh.service.ts index 86f10d28..37cf81ab 100644 --- a/terminus-ssh/src/services/ssh.service.ts +++ b/terminus-ssh/src/services/ssh.service.ts @@ -32,10 +32,14 @@ export class SSHService { } async openTab (connection: SSHConnection): Promise { - return this.zone.run(() => this.app.openNewTab( + const tab = this.zone.run(() => this.app.openNewTab( SSHTabComponent, { connection } ) as SSHTabComponent) + if (connection.color) { + (this.app.getParentTab(tab) || tab).color = connection.color + } + return tab } createSession (connection: SSHConnection): SSHSession { diff --git a/terminus-terminal/src/api/interfaces.ts b/terminus-terminal/src/api/interfaces.ts index 2160c23f..4fa98fa3 100644 --- a/terminus-terminal/src/api/interfaces.ts +++ b/terminus-terminal/src/api/interfaces.ts @@ -16,8 +16,9 @@ export interface SessionOptions { } export interface Profile { - name: string, - sessionOptions: SessionOptions, + name: string + color?: string + sessionOptions: SessionOptions isBuiltin?: boolean icon?: string } diff --git a/terminus-terminal/src/components/editProfileModal.component.pug b/terminus-terminal/src/components/editProfileModal.component.pug index 73d59511..40338a5c 100644 --- a/terminus-terminal/src/components/editProfileModal.component.pug +++ b/terminus-terminal/src/components/editProfileModal.component.pug @@ -53,6 +53,15 @@ [(model)]='profile.sessionOptions.env', ) + .form-group + label Tab color + input.form-control( + type='text', + autofocus, + [(ngModel)]='profile.color', + placeholder='#000000' + ) + .modal-footer button.btn.btn-outline-primary((click)='save()') Save button.btn.btn-outline-danger((click)='cancel()') Cancel diff --git a/terminus-terminal/src/services/terminal.service.ts b/terminus-terminal/src/services/terminal.service.ts index 4dc08d67..85184a33 100644 --- a/terminus-terminal/src/services/terminal.service.ts +++ b/terminus-terminal/src/services/terminal.service.ts @@ -88,7 +88,11 @@ export class TerminalService { cwd: cwd || undefined, } - return this.openTabWithOptions(sessionOptions) + const tab = this.openTabWithOptions(sessionOptions) + if (profile?.color) { + (this.app.getParentTab(tab) || tab).color = profile.color + } + return tab } optionsFromShell (shell: Shell): SessionOptions {