diff --git a/tabby-electron/src/index.ts b/tabby-electron/src/index.ts index c443298c..3764ccc5 100644 --- a/tabby-electron/src/index.ts +++ b/tabby-electron/src/index.ts @@ -1,6 +1,6 @@ import { NgModule } from '@angular/core' import { PlatformService, LogService, UpdaterService, DockingService, HostAppService, ThemesService, Platform, AppService, ConfigService, WIN_BUILD_FLUENT_BG_SUPPORTED, isWindowsBuild, HostWindowService, HotkeyProvider, ConfigProvider, FileProvider } from 'tabby-core' -import { TerminalColorSchemeProvider, TerminalDecorator } from 'tabby-terminal' +import { TerminalColorSchemeProvider, TerminalContextMenuItemProvider, TerminalDecorator } from 'tabby-terminal' import { SFTPContextMenuItemProvider, SSHProfileImporter, AutoPrivateKeyLocator } from 'tabby-ssh' import { PTYInterface, ShellProvider, UACService } from 'tabby-local' import { auditTime } from 'rxjs' @@ -21,6 +21,7 @@ import { ElectronUACService } from './services/uac.service' import { ElectronHotkeyProvider } from './hotkeys' import { ElectronConfigProvider } from './config' import { EditSFTPContextMenu } from './sftpContextMenu' +import { ExportTerminalContextMenu } from './terminalContextMenu' import { OpenSSHImporter, PrivateKeyLocator, StaticFileImporter } from './sshImporters' import { ElectronPTYInterface } from './pty' import { PathDropDecorator } from './pathDrop' @@ -76,6 +77,8 @@ import { VSDevToolsProvider } from './shells/vs' { provide: TerminalDecorator, useClass: PathDropDecorator, multi: true }, + { provide: TerminalContextMenuItemProvider, useClass: ExportTerminalContextMenu, multi: true }, + // For WindowsDefaultShellProvider PowerShellCoreShellProvider, WSLShellProvider, diff --git a/tabby-electron/src/terminalContextMenu.ts b/tabby-electron/src/terminalContextMenu.ts new file mode 100644 index 00000000..f36832fc --- /dev/null +++ b/tabby-electron/src/terminalContextMenu.ts @@ -0,0 +1,44 @@ +import * as fs from 'fs' +import { Injectable } from '@angular/core' +import { MenuItemOptions, NotificationsService, TranslateService } from 'tabby-core' +import { BaseTerminalTabComponent, TerminalContextMenuItemProvider } from 'tabby-terminal' +import { ElectronService } from './services/electron.service' + +/** @hidden */ +@Injectable() +export class ExportTerminalContextMenu extends TerminalContextMenuItemProvider { + weight = 0 + + constructor ( + private electron: ElectronService, + private notifications: NotificationsService, + private translate: TranslateService, + ) { + super() + } + + async getItems (tab: BaseTerminalTabComponent): Promise { + return [ + { + label: this.translate.instant('Export to file'), + click: async () => { + const frontend = tab.frontend + if (!frontend) { + return + } + const result = await this.electron.dialog.showSaveDialog({ + defaultPath: 'terminal.txt', + }) + if (!result.filePath) { + return + } + frontend.selectAll() + const content = frontend.getSelection() + frontend.clearSelection() + await fs.promises.writeFile(result.filePath, content) + this.notifications.info(this.translate.instant('Saved to {path}', { path: result.filePath })) + }, + }, + ] + } +} diff --git a/tabby-terminal/src/tabContextMenu.ts b/tabby-terminal/src/tabContextMenu.ts index 5b0f4ad4..d4a4b19a 100644 --- a/tabby-terminal/src/tabContextMenu.ts +++ b/tabby-terminal/src/tabContextMenu.ts @@ -214,3 +214,4 @@ export class SaveAsProfileContextMenu extends TabContextMenuItemProvider { return [] } } +