1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-12-28 13:03:31 +03:00

allow saving terminal state for debugging

This commit is contained in:
Eugene Pankov 2020-02-06 14:47:21 +03:00
parent 1ac22ec563
commit 6132881b8a
2 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,69 @@
import * as fs from 'fs'
import { Injectable } from '@angular/core'
import { TerminalDecorator } from './api/decorator'
import { TerminalTabComponent } from './components/terminalTab.component'
import { ElectronService, HostAppService } from 'terminus-core'
/** @hidden */
@Injectable()
export class DebugDecorator extends TerminalDecorator {
constructor (
private electron: ElectronService,
private hostApp: HostAppService,
) {
super()
}
attach (terminal: TerminalTabComponent): void {
terminal.content.nativeElement.addEventListener('keyup', e => {
if (e.which === 49 && e.ctrlKey && e.shiftKey && e.altKey) {
this.doSaveOutput(terminal)
}
if (e.which === 50 && e.ctrlKey && e.shiftKey && e.altKey) {
this.doLoadInput(terminal)
}
if (e.which === 51 && e.ctrlKey && e.shiftKey && e.altKey) {
this.doCopyOutput(terminal)
}
if (e.which === 52 && e.ctrlKey && e.shiftKey && e.altKey) {
this.doPasteOutput(terminal)
}
})
}
async doSaveOutput (terminal: TerminalTabComponent) {
const result = await this.electron.dialog.showSaveDialog(
this.hostApp.getWindow(),
{
defaultPath: 'output.txt',
},
)
if (result.filePath) {
fs.writeFileSync(result.filePath, terminal.frontend.saveState())
}
}
async doCopyOutput (terminal: TerminalTabComponent) {
const data = '```' + JSON.stringify(terminal.frontend.saveState()) + '```'
this.electron.clipboard.writeText(data)
}
async doLoadInput (terminal: TerminalTabComponent) {
const result = await this.electron.dialog.showOpenDialog(
this.hostApp.getWindow(),
{
buttonLabel: 'Load',
properties: ['openFile', 'treatPackageAsDirectory'],
},
)
if (result.filePaths.length) {
const data = fs.readFileSync(result.filePaths[0])
terminal.frontend.restoreState(data)
}
}
async doPasteOutput (terminal: TerminalTabComponent) {
const data = JSON.parse(this.electron.clipboard.readText())
terminal.frontend.restoreState(data)
}
}

View File

@ -31,6 +31,7 @@ import { TerminalContextMenuItemProvider } from './api/contextMenuProvider'
import { TerminalColorSchemeProvider } from './api/colorSchemeProvider'
import { ShellProvider } from './api/shellProvider'
import { TerminalSettingsTabProvider, AppearanceSettingsTabProvider, ShellSettingsTabProvider } from './settings'
import { DebugDecorator } from './debug'
import { PathDropDecorator } from './pathDrop'
import { TerminalConfigProvider } from './config'
import { TerminalHotkeyProvider } from './hotkeys'
@ -77,6 +78,7 @@ import { XTermFrontend, XTermWebGLFrontend } from './frontends/xtermFrontend'
{ provide: TerminalColorSchemeProvider, useClass: HyperColorSchemes, multi: true },
{ provide: TerminalDecorator, useClass: PathDropDecorator, multi: true },
{ provide: TerminalDecorator, useClass: ZModemDecorator, multi: true },
{ provide: TerminalDecorator, useClass: DebugDecorator, multi: true },
{ provide: ShellProvider, useClass: WindowsDefaultShellProvider, multi: true },
{ provide: ShellProvider, useClass: MacOSDefaultShellProvider, multi: true },