xterm binary input support

This commit is contained in:
Eugene Pankov 2019-12-06 12:26:19 +01:00
parent 09838197a2
commit 9fe82f2c0a
7 changed files with 20 additions and 14 deletions

View file

@ -30,8 +30,8 @@
"xterm": "4.3.0",
"xterm-addon-fit": "^0.4.0-beta2",
"xterm-addon-ligatures": "^0.2.1",
"xterm-addon-search": "^0.4.0-beta5",
"xterm-addon-webgl": "^0.4.0-beta.15"
"xterm-addon-search": "^0.4.0",
"xterm-addon-webgl": "^0.4.0"
},
"peerDependencies": {
"@angular/animations": "^7",

View file

@ -63,7 +63,7 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
private bellPlayer: HTMLAudioElement
private termContainerSubscriptions: Subscription[] = []
get input$ (): Observable<string> { return this.frontend.input$ }
get input$ (): Observable<Buffer> { return this.frontend.input$ }
get output$ (): Observable<string> { return this.output }
get resize$ (): Observable<ResizeEvent> { return this.frontend.resize$ }
get alternateScreenActive$ (): Observable<boolean> { return this.frontend.alternateScreenActive$ }
@ -229,7 +229,10 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
/**
* Feeds input into the active session
*/
sendInput (data: string) {
sendInput (data: string|Buffer) {
if (!(data instanceof Buffer)) {
data = Buffer.from(data, 'utf-8')
}
this.session.write(data)
if (this.config.store.terminal.scrollOnInput) {
this.frontend.scrollToBottom()

View file

@ -24,7 +24,7 @@ export abstract class Frontend {
protected mouseEvent = new Subject<MouseEvent>()
protected bell = new Subject<void>()
protected contentUpdated = new Subject<void>()
protected input = new Subject<string>()
protected input = new Subject<Buffer>()
protected resize = new ReplaySubject<ResizeEvent>(1)
protected dragOver = new Subject<DragEvent>()
protected drop = new Subject<DragEvent>()
@ -35,7 +35,7 @@ export abstract class Frontend {
get mouseEvent$ (): Observable<MouseEvent> { return this.mouseEvent }
get bell$ (): Observable<void> { return this.bell }
get contentUpdated$ (): Observable<void> { return this.contentUpdated }
get input$ (): Observable<string> { return this.input }
get input$ (): Observable<Buffer> { return this.input }
get resize$ (): Observable<ResizeEvent> { return this.resize }
get dragOver$ (): Observable<DragEvent> { return this.dragOver }
get drop$ (): Observable<DragEvent> { return this.drop }

View file

@ -182,7 +182,7 @@ export class HTermFrontend extends Frontend {
this.term.installKeyboard()
this.term.scrollPort_.setCtrlVPaste(true)
this.io = this.term.io.push()
this.io.onVTKeystroke = this.io.sendString = data => this.input.next(data)
this.io.onVTKeystroke = this.io.sendString = data => this.input.next(Buffer.from(data, 'utf-8'))
this.io.onTerminalResize = (columns, rows) => {
this.resize.next({ columns, rows })
}

View file

@ -39,8 +39,11 @@ export class XTermFrontend extends Frontend {
})
this.xtermCore = (this.xterm as any)._core
this.xterm.onBinary(data => {
this.input.next(Buffer.from(data, 'binary'))
})
this.xterm.onData(data => {
this.input.next(data)
this.input.next(Buffer.from(data, 'utf-8'))
})
this.xterm.onResize(({ cols, rows }) => {
this.resize.next({ rows, columns: cols })
@ -211,7 +214,7 @@ export class XTermFrontend extends Frontend {
const theme: ITheme = {
foreground: config.terminal.colorScheme.foreground,
background: config.terminal.background === 'colorScheme' ? config.terminal.colorScheme.background : config.appearance.vibrancy ? 'transparent' : this.themesService.findCurrentTheme().terminalBackground,
background: config.terminal.background === 'colorScheme' ? config.terminal.colorScheme.background : config.appearance.vibrancy ? '#00000000' : this.themesService.findCurrentTheme().terminalBackground,
cursor: config.terminal.colorScheme.cursor,
}

View file

@ -77,7 +77,7 @@ export abstract class BaseSession {
abstract start (options: SessionOptions): void
abstract resize (columns: number, rows: number): void
abstract write (data: string): void
abstract write (data: Buffer): void
abstract kill (signal?: string): void
abstract async getChildProcesses (): Promise<ChildProcess[]>
abstract async gracefullyKillProcess (): Promise<void>
@ -201,10 +201,10 @@ export class Session extends BaseSession {
}
}
write (data) {
write (data: Buffer) {
if (this.open) {
if (this.pty._writable) {
this.pty.write(Buffer.from(data, 'utf-8'))
this.pty.write(data)
} else {
this.destroy()
}

View file

@ -226,12 +226,12 @@ xterm-addon-ligatures@^0.2.1:
font-finder "^1.0.4"
font-ligatures "^1.3.2"
xterm-addon-search@^0.4.0-beta5:
xterm-addon-search@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/xterm-addon-search/-/xterm-addon-search-0.4.0.tgz#a7beadb3caa7330eb31fb1f17d92de25537684a1"
integrity sha512-g07qb/Z4aSfrQ25e6Z6rz6KiExm2DvesQXkx+eA715VABBr5VM/9Jf0INoCiDSYy/nn7rpna+kXiGVJejIffKg==
xterm-addon-webgl@^0.4.0-beta.15:
xterm-addon-webgl@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/xterm-addon-webgl/-/xterm-addon-webgl-0.4.0.tgz#7b7cdbdbf9b0d06189af20d468d8ea2798382e0f"
integrity sha512-2ExOKJQcyv4hUo/d41uMDe7fNZCi42kPtbvG/v+dVj1NwqGD7g1bhuoH2j1iA1vTP5O1fClc6pU9nLBpbwrdZQ==