mirror of
https://github.com/eugeny/tabby
synced 2026-07-08 08:01:17 +00:00
feat: add 'Export to file' option to terminal context menu (#11109)
Package-Build / Lint (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Docs / build (push) Has been cancelled
Package-Build / macOS-Build (arm64, aarch64-apple-darwin) (push) Has been cancelled
Package-Build / macOS-Build (x86_64, x86_64-apple-darwin) (push) Has been cancelled
Package-Build / Linux-Build (amd64, x64, ubuntu-24.04, x86_64-unknown-linux-gnu) (push) Has been cancelled
Package-Build / Linux-Build (arm64, arm64, ubuntu-24.04-arm, aarch64-unknown-linux-gnu, aarch64-linux-gnu-) (push) Has been cancelled
Package-Build / Linux-Build (armhf, arm, ubuntu-24.04, arm-unknown-linux-gnueabihf, arm-linux-gnueabihf-) (push) Has been cancelled
Package-Build / Windows-Build (arm64, aarch64-pc-windows-msvc) (push) Has been cancelled
Package-Build / Windows-Build (x64, x86_64-pc-windows-msvc) (push) Has been cancelled
Package-Build / Lint (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Docs / build (push) Has been cancelled
Package-Build / macOS-Build (arm64, aarch64-apple-darwin) (push) Has been cancelled
Package-Build / macOS-Build (x86_64, x86_64-apple-darwin) (push) Has been cancelled
Package-Build / Linux-Build (amd64, x64, ubuntu-24.04, x86_64-unknown-linux-gnu) (push) Has been cancelled
Package-Build / Linux-Build (arm64, arm64, ubuntu-24.04-arm, aarch64-unknown-linux-gnu, aarch64-linux-gnu-) (push) Has been cancelled
Package-Build / Linux-Build (armhf, arm, ubuntu-24.04, arm-unknown-linux-gnueabihf, arm-linux-gnueabihf-) (push) Has been cancelled
Package-Build / Windows-Build (arm64, aarch64-pc-windows-msvc) (push) Has been cancelled
Package-Build / Windows-Build (x64, x86_64-pc-windows-msvc) (push) Has been cancelled
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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<any>): Promise<MenuItemOptions[]> {
|
||||
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 }))
|
||||
},
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -214,3 +214,4 @@ export class SaveAsProfileContextMenu extends TabContextMenuItemProvider {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user