mirror of
https://github.com/Eugeny/tabby.git
synced 2025-10-04 05:54:57 +00:00
added scrollback saving
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Observable, Subject, Subscription } from 'rxjs'
|
||||
import { first } from 'rxjs/operators'
|
||||
import { ToastrService } from 'ngx-toastr'
|
||||
import colors from 'ansi-colors'
|
||||
import { NgZone, OnInit, OnDestroy, Inject, Injector, Optional, ViewChild, HostBinding, Input, ElementRef } from '@angular/core'
|
||||
import { trigger, transition, style, animate, AnimationTriggerMetadata } from '@angular/animations'
|
||||
import { AppService, ConfigService, BaseTabComponent, ElectronService, HostAppService, HotkeysService, Platform, LogService, Logger, TabContextMenuItemProvider } from 'terminus-core'
|
||||
@@ -34,6 +35,8 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
|
||||
])]
|
||||
|
||||
session: BaseSession
|
||||
savedState: any
|
||||
|
||||
@Input() zoom = 0
|
||||
|
||||
@Input() showSearchPanel = false
|
||||
@@ -178,6 +181,13 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
|
||||
this.session.releaseInitialDataBuffer()
|
||||
})
|
||||
|
||||
if (this.savedState) {
|
||||
this.frontend.restoreState(this.savedState)
|
||||
this.frontend.write('\r\n\r\n')
|
||||
this.frontend.write(colors.bgWhite.black(' * ') + colors.bgBlackBright.white(' History restored '))
|
||||
this.frontend.write('\r\n\r\n')
|
||||
}
|
||||
|
||||
setImmediate(() => {
|
||||
if (this.hasFocus) {
|
||||
this.frontend.attach(this.content.nativeElement)
|
||||
|
@@ -65,6 +65,7 @@ export class TerminalTabComponent extends BaseTerminalTabComponent {
|
||||
...this.sessionOptions,
|
||||
cwd: cwd || this.sessionOptions.cwd,
|
||||
},
|
||||
savedState: this.frontend.saveState(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -74,4 +74,7 @@ export abstract class Frontend {
|
||||
|
||||
abstract findNext (term: string, searchOptions?: SearchOptions): boolean
|
||||
abstract findPrevious (term: string, searchOptions?: SearchOptions): boolean
|
||||
|
||||
abstract saveState (): any
|
||||
abstract restoreState (state: any): void
|
||||
}
|
||||
|
@@ -164,6 +164,12 @@ export class HTermFrontend extends Frontend {
|
||||
return false
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
saveState (): any { }
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
restoreState (_state: any): void { }
|
||||
|
||||
private setFontSize () {
|
||||
const size = this.configuredFontSize * Math.pow(1.1, this.zoom)
|
||||
preferenceManager.set('font-size', size)
|
||||
|
@@ -5,6 +5,8 @@ import { FitAddon } from 'xterm-addon-fit'
|
||||
import { LigaturesAddon } from 'xterm-addon-ligatures'
|
||||
import { SearchAddon } from 'xterm-addon-search'
|
||||
import { WebglAddon } from 'xterm-addon-webgl'
|
||||
import { Unicode11Addon } from 'xterm-addon-unicode11'
|
||||
import { SerializeAddon } from 'xterm-addon-serialize'
|
||||
import './xterm.css'
|
||||
import deepEqual from 'deep-equal'
|
||||
import { Attributes } from 'xterm/src/common/buffer/Constants'
|
||||
@@ -30,6 +32,7 @@ export class XTermFrontend extends Frontend {
|
||||
private copyOnSelect = false
|
||||
private search = new SearchAddon()
|
||||
private fitAddon = new FitAddon()
|
||||
private serializeAddon = new SerializeAddon()
|
||||
private ligaturesAddon: LigaturesAddon
|
||||
private opened = false
|
||||
|
||||
@@ -57,7 +60,11 @@ export class XTermFrontend extends Frontend {
|
||||
this.copySelection()
|
||||
}
|
||||
})
|
||||
|
||||
this.xterm.loadAddon(this.fitAddon)
|
||||
this.xterm.loadAddon(this.serializeAddon)
|
||||
this.xterm.loadAddon(new Unicode11Addon())
|
||||
this.xterm.unicode.activeVersion = '11'
|
||||
|
||||
const keyboardEventHandler = (name: string, event: KeyboardEvent) => {
|
||||
this.hotkeysService.pushKeystroke(name, event)
|
||||
@@ -248,6 +255,14 @@ export class XTermFrontend extends Frontend {
|
||||
return this.search.findPrevious(term, searchOptions)
|
||||
}
|
||||
|
||||
saveState (): any {
|
||||
return this.serializeAddon.serialize()
|
||||
}
|
||||
|
||||
restoreState (state: any): void {
|
||||
this.xterm.write(state)
|
||||
}
|
||||
|
||||
private setFontSize () {
|
||||
const scale = Math.pow(1.1, this.zoom)
|
||||
this.xterm.setOption('fontSize', this.configuredFontSize * scale)
|
||||
|
@@ -10,7 +10,10 @@ export class RecoveryProvider extends TabRecoveryProvider {
|
||||
if (recoveryToken && recoveryToken.type === 'app:terminal-tab') {
|
||||
return {
|
||||
type: TerminalTabComponent,
|
||||
options: { sessionOptions: recoveryToken.sessionOptions },
|
||||
options: {
|
||||
sessionOptions: recoveryToken.sessionOptions,
|
||||
savedState: recoveryToken.savedState,
|
||||
},
|
||||
}
|
||||
}
|
||||
return null
|
||||
|
Reference in New Issue
Block a user