From 178e4a6527ad421e631abea1f97d2e03a409596d Mon Sep 17 00:00:00 2001 From: Clem Date: Mon, 10 Apr 2023 19:48:27 +0200 Subject: [PATCH 1/3] resolve Eugeny/tabby#7723 reconnect command palette --- .../src/components/serialTab.component.ts | 4 +-- tabby-ssh/src/components/sshTab.component.ts | 4 +-- .../src/components/telnetTab.component.ts | 4 +-- tabby-terminal/src/api/interfaces.ts | 8 +++++ tabby-terminal/src/index.ts | 3 +- tabby-terminal/src/tabContextMenu.ts | 31 +++++++++++++++++++ 6 files changed, 47 insertions(+), 7 deletions(-) diff --git a/tabby-serial/src/components/serialTab.component.ts b/tabby-serial/src/components/serialTab.component.ts index 58884d07..d648dac4 100644 --- a/tabby-serial/src/components/serialTab.component.ts +++ b/tabby-serial/src/components/serialTab.component.ts @@ -4,7 +4,7 @@ import colors from 'ansi-colors' import { Component, Injector } from '@angular/core' import { first } from 'rxjs' import { GetRecoveryTokenOptions, Platform, SelectorService } from 'tabby-core' -import { BaseTerminalTabComponent } from 'tabby-terminal' +import { BaseTerminalTabComponent, Reconnectable } from 'tabby-terminal' import { SerialSession, BAUD_RATES, SerialProfile } from '../api' /** @hidden */ @@ -14,7 +14,7 @@ import { SerialSession, BAUD_RATES, SerialProfile } from '../api' styleUrls: ['./serialTab.component.scss', ...BaseTerminalTabComponent.styles], animations: BaseTerminalTabComponent.animations, }) -export class SerialTabComponent extends BaseTerminalTabComponent { +export class SerialTabComponent extends BaseTerminalTabComponent implements Reconnectable { session: SerialSession|null = null Platform = Platform diff --git a/tabby-ssh/src/components/sshTab.component.ts b/tabby-ssh/src/components/sshTab.component.ts index 1694813a..11af1368 100644 --- a/tabby-ssh/src/components/sshTab.component.ts +++ b/tabby-ssh/src/components/sshTab.component.ts @@ -4,7 +4,7 @@ import { Component, Injector, HostListener } from '@angular/core' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' import { first } from 'rxjs' import { GetRecoveryTokenOptions, Platform, ProfilesService, RecoveryToken } from 'tabby-core' -import { BaseTerminalTabComponent } from 'tabby-terminal' +import { BaseTerminalTabComponent, Reconnectable } from 'tabby-terminal' import { SSHService } from '../services/ssh.service' import { KeyboardInteractivePrompt, SSHSession } from '../session/ssh' import { SSHPortForwardingModalComponent } from './sshPortForwardingModal.component' @@ -22,7 +22,7 @@ import { SSHMultiplexerService } from '../services/sshMultiplexer.service' ], animations: BaseTerminalTabComponent.animations, }) -export class SSHTabComponent extends BaseTerminalTabComponent { +export class SSHTabComponent extends BaseTerminalTabComponent implements Reconnectable { Platform = Platform sshSession: SSHSession|null = null session: SSHShellSession|null = null diff --git a/tabby-telnet/src/components/telnetTab.component.ts b/tabby-telnet/src/components/telnetTab.component.ts index 48458b61..440e3432 100644 --- a/tabby-telnet/src/components/telnetTab.component.ts +++ b/tabby-telnet/src/components/telnetTab.component.ts @@ -3,7 +3,7 @@ import colors from 'ansi-colors' import { Component, Injector } from '@angular/core' import { first } from 'rxjs' import { GetRecoveryTokenOptions, Platform, RecoveryToken } from 'tabby-core' -import { BaseTerminalTabComponent } from 'tabby-terminal' +import { BaseTerminalTabComponent, Reconnectable } from 'tabby-terminal' import { TelnetProfile, TelnetSession } from '../session' @@ -14,7 +14,7 @@ import { TelnetProfile, TelnetSession } from '../session' styleUrls: ['./telnetTab.component.scss', ...BaseTerminalTabComponent.styles], animations: BaseTerminalTabComponent.animations, }) -export class TelnetTabComponent extends BaseTerminalTabComponent { +export class TelnetTabComponent extends BaseTerminalTabComponent implements Reconnectable { Platform = Platform session: TelnetSession|null = null private reconnectOffered = false diff --git a/tabby-terminal/src/api/interfaces.ts b/tabby-terminal/src/api/interfaces.ts index 74143339..76d6acf2 100644 --- a/tabby-terminal/src/api/interfaces.ts +++ b/tabby-terminal/src/api/interfaces.ts @@ -19,3 +19,11 @@ export interface TerminalColorScheme { export interface BaseTerminalProfile extends Profile { terminalColorScheme?: TerminalColorScheme } + +export interface Reconnectable { + reconnect: () => Promise; +} + +export function tabIsReconnectable (object: any): object is Reconnectable { + return 'reconnect' in object +} diff --git a/tabby-terminal/src/index.ts b/tabby-terminal/src/index.ts index 99f3e225..01405dbb 100644 --- a/tabby-terminal/src/index.ts +++ b/tabby-terminal/src/index.ts @@ -28,7 +28,7 @@ import { PathDropDecorator } from './features/pathDrop' import { ZModemDecorator } from './features/zmodem' import { TerminalConfigProvider } from './config' import { TerminalHotkeyProvider } from './hotkeys' -import { CopyPasteContextMenu, MiscContextMenu, LegacyContextMenu } from './tabContextMenu' +import { CopyPasteContextMenu, MiscContextMenu, LegacyContextMenu, ReconnectContextMenu } from './tabContextMenu' import { Frontend } from './frontends/frontend' import { XTermFrontend, XTermWebGLFrontend } from './frontends/xtermFrontend' @@ -58,6 +58,7 @@ import { TerminalCLIHandler } from './cli' { provide: TabContextMenuItemProvider, useClass: CopyPasteContextMenu, multi: true }, { provide: TabContextMenuItemProvider, useClass: MiscContextMenu, multi: true }, { provide: TabContextMenuItemProvider, useClass: LegacyContextMenu, multi: true }, + { provide: TabContextMenuItemProvider, useClass: ReconnectContextMenu, multi: true }, { provide: CLIHandler, useClass: TerminalCLIHandler, multi: true }, ], diff --git a/tabby-terminal/src/tabContextMenu.ts b/tabby-terminal/src/tabContextMenu.ts index fab843a1..a4ee56f6 100644 --- a/tabby-terminal/src/tabContextMenu.ts +++ b/tabby-terminal/src/tabContextMenu.ts @@ -1,6 +1,7 @@ import { Injectable, Optional, Inject } from '@angular/core' import { BaseTabComponent, TabContextMenuItemProvider, NotificationsService, MenuItemOptions, TranslateService, SplitTabComponent } from 'tabby-core' import { BaseTerminalTabComponent } from './api/baseTerminalTab.component' +import { tabIsReconnectable } from './api/interfaces' import { TerminalContextMenuItemProvider } from './api/contextMenuProvider' import { MultifocusService } from './services/multifocus.service' @@ -85,6 +86,35 @@ export class MiscContextMenu extends TabContextMenuItemProvider { } } +/** @hidden */ +@Injectable() +export class ReconnectContextMenu extends TabContextMenuItemProvider { + weight = 1 + + constructor ( + private translate: TranslateService, + private notifications: NotificationsService, + ) { super() } + + async getItems (tab: BaseTabComponent): Promise { + if (tabIsReconnectable(tab)) { + return [ + { + label: this.translate.instant('Reconnect'), + click: (): void => { + setTimeout(() => { + tab.reconnect() + this.notifications.notice(this.translate.instant('Reconnect')) + }) + }, + }, + ] + } + return [] + } + +} + /** @hidden */ @Injectable() export class LegacyContextMenu extends TabContextMenuItemProvider { @@ -109,4 +139,5 @@ export class LegacyContextMenu extends TabContextMenuItemProvider { } return [] } + } From d1b45812d5df86ebbe7352bda63fe2a07832428a Mon Sep 17 00:00:00 2001 From: Clem Date: Tue, 11 Apr 2023 22:53:05 +0200 Subject: [PATCH 2/3] lint + refactor --- tabby-terminal/src/api/interfaces.ts | 3 ++- tabby-terminal/src/tabContextMenu.ts | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tabby-terminal/src/api/interfaces.ts b/tabby-terminal/src/api/interfaces.ts index 76d6acf2..8e7d54c3 100644 --- a/tabby-terminal/src/api/interfaces.ts +++ b/tabby-terminal/src/api/interfaces.ts @@ -24,6 +24,7 @@ export interface Reconnectable { reconnect: () => Promise; } -export function tabIsReconnectable (object: any): object is Reconnectable { +// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types +export function isReconnectable (object: any): object is Reconnectable { return 'reconnect' in object } diff --git a/tabby-terminal/src/tabContextMenu.ts b/tabby-terminal/src/tabContextMenu.ts index a4ee56f6..962c12e4 100644 --- a/tabby-terminal/src/tabContextMenu.ts +++ b/tabby-terminal/src/tabContextMenu.ts @@ -1,7 +1,7 @@ import { Injectable, Optional, Inject } from '@angular/core' import { BaseTabComponent, TabContextMenuItemProvider, NotificationsService, MenuItemOptions, TranslateService, SplitTabComponent } from 'tabby-core' import { BaseTerminalTabComponent } from './api/baseTerminalTab.component' -import { tabIsReconnectable } from './api/interfaces' +import { isReconnectable } from './api/interfaces' import { TerminalContextMenuItemProvider } from './api/contextMenuProvider' import { MultifocusService } from './services/multifocus.service' @@ -97,7 +97,7 @@ export class ReconnectContextMenu extends TabContextMenuItemProvider { ) { super() } async getItems (tab: BaseTabComponent): Promise { - if (tabIsReconnectable(tab)) { + if (isReconnectable(tab)) { return [ { label: this.translate.instant('Reconnect'), From bbca7a6a84ba8f06d367dbc976fe7386f8757d77 Mon Sep 17 00:00:00 2001 From: Clem Date: Tue, 11 Apr 2023 23:47:24 +0200 Subject: [PATCH 3/3] feat: reconnect current tab hotkey --- tabby-core/src/configDefaults.linux.yaml | 1 + tabby-core/src/configDefaults.macos.yaml | 1 + tabby-core/src/configDefaults.windows.yaml | 1 + tabby-terminal/src/api/baseTerminalTab.component.ts | 7 ++++++- tabby-terminal/src/hotkeys.ts | 4 ++++ 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tabby-core/src/configDefaults.linux.yaml b/tabby-core/src/configDefaults.linux.yaml index 11a2fed1..1d213e10 100644 --- a/tabby-core/src/configDefaults.linux.yaml +++ b/tabby-core/src/configDefaults.linux.yaml @@ -22,6 +22,7 @@ hotkeys: - 'Ctrl-Shift' duplicate-tab: [] restart-tab: [] + reconnect-tab: [] explode-tab: - 'Ctrl-Shift-.' combine-tabs: diff --git a/tabby-core/src/configDefaults.macos.yaml b/tabby-core/src/configDefaults.macos.yaml index 7228a242..d47050c4 100644 --- a/tabby-core/src/configDefaults.macos.yaml +++ b/tabby-core/src/configDefaults.macos.yaml @@ -39,6 +39,7 @@ hotkeys: tab-10: [] duplicate-tab: [] restart-tab: [] + reconnect-tab: [] explode-tab: - '⌘-Shift-.' combine-tabs: diff --git a/tabby-core/src/configDefaults.windows.yaml b/tabby-core/src/configDefaults.windows.yaml index 340f93d7..58870f8e 100644 --- a/tabby-core/src/configDefaults.windows.yaml +++ b/tabby-core/src/configDefaults.windows.yaml @@ -23,6 +23,7 @@ hotkeys: - 'Ctrl-Shift' duplicate-tab: [] restart-tab: [] + reconnect-tab: [] explode-tab: - 'Ctrl-Shift-.' combine-tabs: diff --git a/tabby-terminal/src/api/baseTerminalTab.component.ts b/tabby-terminal/src/api/baseTerminalTab.component.ts index a23f1f07..f781afd6 100644 --- a/tabby-terminal/src/api/baseTerminalTab.component.ts +++ b/tabby-terminal/src/api/baseTerminalTab.component.ts @@ -9,7 +9,7 @@ import { BaseSession } from '../session' import { Frontend } from '../frontends/frontend' import { XTermFrontend, XTermWebGLFrontend } from '../frontends/xtermFrontend' -import { ResizeEvent, BaseTerminalProfile } from './interfaces' +import { ResizeEvent, BaseTerminalProfile, isReconnectable } from './interfaces' import { TerminalDecorator } from './decorator' import { SearchPanelComponent } from '../components/searchPanel.component' import { MultifocusService } from '../services/multifocus.service' @@ -306,6 +306,11 @@ export class BaseTerminalTabComponent

extends Bas case 'scroll-to-bottom': this.frontend?.scrollToBottom() break + case 'reconnect-tab': + if (isReconnectable(this)) { + this.reconnect() + } + break } }) diff --git a/tabby-terminal/src/hotkeys.ts b/tabby-terminal/src/hotkeys.ts index 808c17ef..08c69798 100644 --- a/tabby-terminal/src/hotkeys.ts +++ b/tabby-terminal/src/hotkeys.ts @@ -97,6 +97,10 @@ export class TerminalHotkeyProvider extends HotkeyProvider { id: 'scroll-to-bottom', name: this.translate.instant('Scroll terminal to bottom'), }, + { + id: 'reconnect-tab', + name: this.translate.instant('Reconnect current tab (Serial/Telnet/SSH)'), + }, ] constructor (private translate: TranslateService) { super() }