Skip to content

Commit

Permalink
fixed #5862 - configurable Backspace behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Jul 15, 2023
1 parent 4736b11 commit fcac52a
Show file tree
Hide file tree
Showing 15 changed files with 109 additions and 9 deletions.
4 changes: 3 additions & 1 deletion tabby-serial/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SerialPortStream } from '@serialport/stream'
import { LogService, NotificationsService } from 'tabby-core'
import { Subject, Observable } from 'rxjs'
import { Injector, NgZone } from '@angular/core'
import { BaseSession, BaseTerminalProfile, LoginScriptsOptions, SessionMiddleware, StreamProcessingOptions, TerminalStreamProcessor, UTF8SplitterMiddleware } from 'tabby-terminal'
import { BaseSession, BaseTerminalProfile, InputProcessingOptions, InputProcessor, LoginScriptsOptions, SessionMiddleware, StreamProcessingOptions, TerminalStreamProcessor, UTF8SplitterMiddleware } from 'tabby-terminal'
import { SerialService } from './services/serial.service'

export interface SerialProfile extends BaseTerminalProfile {
Expand All @@ -21,6 +21,7 @@ export interface SerialProfileOptions extends StreamProcessingOptions, LoginScri
xoff?: boolean
xany?: boolean
slowSend?: boolean
input: InputProcessingOptions,
}

export const BAUD_RATES = [
Expand Down Expand Up @@ -65,6 +66,7 @@ export class SerialSession extends BaseSession {
}

this.middleware.push(new UTF8SplitterMiddleware())
this.middleware.push(new InputProcessor(profile.options.input))

this.setLoginScriptsOptions(profile.options)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,9 @@ ul.nav-tabs(ngbNav, #nav='ngbNav')
ng-template(ngbNavContent)
login-scripts-settings([options]='profile.options')

li(ngbNavItem)
a(ngbNavLink, translate) Input
ng-template(ngbNavContent)
input-processing-settings([options]='profile.options.input')

div([ngbNavOutlet]='nav')
1 change: 1 addition & 0 deletions tabby-serial/src/profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class SerialProfilesService extends ProfileProvider<SerialProfile> {
outputNewlines: null,
scripts: [],
slowSend: false,
input: { backspace: 'backspace' },
},
}

Expand Down
3 changes: 2 additions & 1 deletion tabby-ssh/src/api/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseTerminalProfile, LoginScriptsOptions } from 'tabby-terminal'
import { BaseTerminalProfile, InputProcessingOptions, LoginScriptsOptions } from 'tabby-terminal'

export enum SSHAlgorithmType {
HMAC = 'hmac',
Expand Down Expand Up @@ -34,6 +34,7 @@ export interface SSHProfileOptions extends LoginScriptsOptions {
httpProxyHost?: string
httpProxyPort?: number
reuseSession?: boolean
input: InputProcessingOptions,
}

export enum PortForwardType {
Expand Down
5 changes: 5 additions & 0 deletions tabby-ssh/src/components/sshProfileSettings.component.pug
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,9 @@ ul.nav-tabs(ngbNav, #nav='ngbNav')
ng-template(ngbNavContent)
login-scripts-settings([options]='profile.options', #loginScriptsSettings)

li(ngbNavItem)
a(ngbNavLink, translate) Input
ng-template(ngbNavContent)
input-processing-settings([options]='profile.options.input')

div([ngbNavOutlet]='nav')
1 change: 1 addition & 0 deletions tabby-ssh/src/profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class SSHProfilesService extends ProfileProvider<SSHProfile> {
httpProxyHost: null,
httpProxyPort: null,
reuseSession: true,
input: { backspace: 'backspace' },
},
}

Expand Down
3 changes: 2 additions & 1 deletion tabby-ssh/src/session/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import stripAnsi from 'strip-ansi'
import { ClientChannel } from 'ssh2'
import { Injector } from '@angular/core'
import { LogService } from 'tabby-core'
import { BaseSession, UTF8SplitterMiddleware } from 'tabby-terminal'
import { BaseSession, UTF8SplitterMiddleware, InputProcessor } from 'tabby-terminal'
import { SSHSession } from './ssh'
import { SSHProfile } from '../api'

Expand All @@ -24,6 +24,7 @@ export class SSHShellSession extends BaseSession {
this.setLoginScriptsOptions(this.profile.options)
this.ssh.serviceMessage$.subscribe(m => this.serviceMessage.next(m))
this.middleware.push(new UTF8SplitterMiddleware())
this.middleware.push(new InputProcessor(profile.options.input))
}

async start (): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ ul.nav-tabs(ngbNav, #nav='ngbNav')
ng-template(ngbNavContent)
login-scripts-settings([options]='profile.options')

li(ngbNavItem)
a(ngbNavLink, translate) Input
ng-template(ngbNavContent)
input-processing-settings([options]='profile.options.input')

div([ngbNavOutlet]='nav')
1 change: 1 addition & 0 deletions tabby-telnet/src/profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class TelnetProfilesService extends ProfileProvider<TelnetProfile> {
inputNewlines: null,
outputNewlines: 'crlf',
scripts: [],
input: { backspace: 'backspace' },
},
}

Expand Down
4 changes: 3 additions & 1 deletion tabby-telnet/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import colors from 'ansi-colors'
import stripAnsi from 'strip-ansi'
import { Injector } from '@angular/core'
import { LogService } from 'tabby-core'
import { BaseSession, BaseTerminalProfile, LoginScriptsOptions, SessionMiddleware, StreamProcessingOptions, TerminalStreamProcessor } from 'tabby-terminal'
import { BaseSession, BaseTerminalProfile, InputProcessingOptions, InputProcessor, LoginScriptsOptions, SessionMiddleware, StreamProcessingOptions, TerminalStreamProcessor } from 'tabby-terminal'
import { Subject, Observable } from 'rxjs'


Expand All @@ -14,6 +14,7 @@ export interface TelnetProfile extends BaseTerminalProfile {
export interface TelnetProfileOptions extends StreamProcessingOptions, LoginScriptsOptions {
host: string
port?: number
input: InputProcessingOptions,
}

enum TelnetCommands {
Expand Down Expand Up @@ -75,6 +76,7 @@ export class TelnetSession extends BaseSession {
super(injector.get(LogService).create(`telnet-${profile.options.host}-${profile.options.port}`))
this.streamProcessor = new TerminalStreamProcessor(profile.options)
this.middleware.push(this.streamProcessor)
this.middleware.push(new InputProcessor(profile.options.input))
this.setLoginScriptsOptions(profile.options)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.form-line
.header
.title(translate) Backspace key mode

select.form-control([(ngModel)]='options.backspace')
option(
*ngFor='let mode of backspaceModes',
[value]='mode.key',
) {{mode.name|translate}}
40 changes: 40 additions & 0 deletions tabby-terminal/src/components/inputProcessingSettings.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'
import { Component, Input } from '@angular/core'
import { InputProcessingOptions } from '../middleware/inputProcessing'

/** @hidden */
@Component({
selector: 'input-processing-settings',
templateUrl: './inputProcessingSettings.component.pug',
})
export class InputProcessingSettingsComponent {
@Input() options: InputProcessingOptions

backspaceModes = [
{
key: 'backspace',
name: _('Pass-through'),
},
{
key: 'ctrl-h',
name: 'Ctrl-H',
},
{
key: 'ctrl-?',
name: 'Ctrl-?',
},
{
key: 'delete',
name: 'Delete (CSI 3~)',
},
]

getBackspaceModeName (key) {
return this.backspaceModes.find(x => x.key === key)?.name
}

setBackspaceMode (mode) {
this.options.backspace = mode
}
}
4 changes: 4 additions & 0 deletions tabby-terminal/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { StreamProcessingSettingsComponent } from './components/streamProcessing
import { LoginScriptsSettingsComponent } from './components/loginScriptsSettings.component'
import { TerminalToolbarComponent } from './components/terminalToolbar.component'
import { ColorSchemeSelectorComponent } from './components/colorSchemeSelector.component'
import { InputProcessingSettingsComponent } from './components/inputProcessingSettings.component'

import { TerminalDecorator } from './api/decorator'
import { TerminalContextMenuItemProvider } from './api/contextMenuProvider'
Expand Down Expand Up @@ -76,6 +77,7 @@ import { DefaultColorSchemes } from './colorSchemes'
StreamProcessingSettingsComponent,
LoginScriptsSettingsComponent,
TerminalToolbarComponent,
InputProcessingSettingsComponent,
],
exports: [
ColorPickerComponent,
Expand All @@ -84,6 +86,7 @@ import { DefaultColorSchemes } from './colorSchemes'
StreamProcessingSettingsComponent,
LoginScriptsSettingsComponent,
TerminalToolbarComponent,
InputProcessingSettingsComponent,
],
})
export default class TerminalModule { } // eslint-disable-line @typescript-eslint/no-extraneous-class
Expand All @@ -97,6 +100,7 @@ export * from './middleware/streamProcessing'
export * from './middleware/loginScriptProcessing'
export * from './middleware/oscProcessing'
export * from './middleware/utf8Splitter'
export * from './middleware/inputProcessing'
export * from './api/middleware'
export * from './session'
export { LoginScriptsSettingsComponent, StreamProcessingSettingsComponent }
Expand Down
28 changes: 28 additions & 0 deletions tabby-terminal/src/middleware/inputProcessing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { SessionMiddleware } from '../api/middleware'

export interface InputProcessingOptions {
backspace: 'ctrl-h'|'ctrl-?'|'delete'|'backspace'
}

export class InputProcessor extends SessionMiddleware {
constructor (
private options: InputProcessingOptions,
) {
super()
}

feedFromTerminal (data: Buffer): void {
if (data.length === 1 && data[0] === 0x7f) {
if (this.options.backspace === 'ctrl-h') {
data = Buffer.from('\x08')
} else if (this.options.backspace === 'ctrl-?') {
data = Buffer.from('\x7f')
} else if (this.options.backspace === 'delete') {
data = Buffer.from('\x1b[3~')
} else {
data = Buffer.from('\x7f')
}
}
this.outputToSession.next(data)
}
}
5 changes: 0 additions & 5 deletions tabby-terminal/src/middleware/loginScriptProcessing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ export class LoginScriptProcessor extends SessionMiddleware {
super.feedFromSession(data)
}

close (): void {
this.outputToSession.complete()
super.close()
}

executeUnconditionalScripts (): void {
for (const script of this.remainingScripts) {
if (!script.expect) {
Expand Down

0 comments on commit fcac52a

Please sign in to comment.