1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-11-25 19:17:39 +03:00

resolves Eugeny/tabby#7751, Eugeny/tabby#8062, Eugeny/tabby#6617 add configurable behavior when session ends

This commit is contained in:
Clem 2023-04-12 23:20:06 +02:00
parent c5d79135ab
commit 268af8806c
7 changed files with 79 additions and 32 deletions

View File

@ -25,6 +25,7 @@ terminal:
paneResizeStep: 0.1
focusFollowsMouse: false
identification: null
behaviorOnSessionEnds: 'keep-open'
hotkeys:
profile:
__nonStructural: true

View File

@ -28,7 +28,6 @@ export class TerminalTabComponent extends BaseTerminalTabComponent<LocalProfile>
this.sessionOptions = this.profile.options
this.logger = this.log.create('terminalTab')
this.session = new Session(this.injector)
const isConPTY = isWindowsBuild(WIN_BUILD_CONPTY_SUPPORTED) && this.config.store.terminal.useConPTY
@ -56,6 +55,9 @@ export class TerminalTabComponent extends BaseTerminalTabComponent<LocalProfile>
}
initializeSession (columns: number, rows: number): void {
const session = new Session(this.injector)
if (this.profile.options.runAsAdministrator && this.uac?.isAvailable) {
this.profile = {
...this.profile,
@ -63,13 +65,13 @@ export class TerminalTabComponent extends BaseTerminalTabComponent<LocalProfile>
}
}
this.session!.start({
session.start({
...this.profile.options,
width: columns,
height: rows,
})
this.attachSessionHandlers(true)
this.setSession(session, this.config.store.terminal.behaviorOnSessionEnds.endsWith('close'))
this.recoveryStateChangedHint.next()
}

View File

@ -82,12 +82,25 @@ export class SerialTabComponent extends BaseTerminalTabComponent<SerialProfile>
this.session?.resize(this.size.columns, this.size.rows)
})
this.attachSessionHandler(this.session!.destroyed$, () => {
this.write(this.translate.instant(_('Press any key to reconnect')) + '\r\n')
this.input$.pipe(first()).subscribe(() => {
if (!this.session?.open) {
if (this.frontend) {
// Session was closed abruptly
if (this.config.store.terminal.behaviorOnSessionEnds == 'close') {
// Close the tab
this.destroy()
} else if (this.config.store.terminal.behaviorOnSessionEnds.startsWith('reconnect-or-')) {
// Automatically reconnect the session
this.reconnect()
} else {
// Reconnect Offer
this.write(this.translate.instant(_('Press any key to reconnect')) + '\r\n')
this.input$.pipe(first()).subscribe(() => {
if (!this.session?.open) {
this.reconnect()
}
})
}
})
}
})
super.attachSessionHandlers()
}

View File

@ -157,24 +157,27 @@ export class SSHTabComponent extends BaseTerminalTabComponent<SSHProfile> implem
protected attachSessionHandlers (): void {
const session = this.session!
this.attachSessionHandler(session.destroyed$, () => {
if (
// Ctrl-D
this.recentInputs.charCodeAt(this.recentInputs.length - 1) === 4 ||
this.recentInputs.endsWith('exit\r')
) {
// User closed the session
this.destroy()
} else if (this.frontend) {
// Session was closed abruptly
if (this.frontend) {
this.write('\r\n' + colors.black.bgWhite(' SSH ') + ` ${this.sshSession?.profile.options.host}: session closed\r\n`)
if (!this.reconnectOffered) {
this.reconnectOffered = true
this.write(this.translate.instant(_('Press any key to reconnect')) + '\r\n')
this.input$.pipe(first()).subscribe(() => {
if (!this.session?.open && this.reconnectOffered) {
this.reconnect()
}
})
if (this.config.store.terminal.behaviorOnSessionEnds == 'close') {
// Close the tab
this.destroy()
} else if (this.config.store.terminal.behaviorOnSessionEnds.startsWith('reconnect-or-')) {
// Automatically reconnect the session
this.reconnect()
} else {
// Reconnect Offer
if (!this.reconnectOffered) {
this.reconnectOffered = true
this.write(this.translate.instant(_('Press any key to reconnect')) + '\r\n')
this.input$.pipe(first()).subscribe(() => {
if (!this.session?.open && this.reconnectOffered) {
this.reconnect()
}
})
}
}
}
})

View File

@ -48,14 +48,23 @@ export class TelnetTabComponent extends BaseTerminalTabComponent<TelnetProfile>
this.attachSessionHandler(session.destroyed$, () => {
if (this.frontend) {
// Session was closed abruptly
if (!this.reconnectOffered) {
this.reconnectOffered = true
this.write(this.translate.instant(_('Press any key to reconnect')) + '\r\n')
this.input$.pipe(first()).subscribe(() => {
if (!this.session?.open && this.reconnectOffered) {
this.reconnect()
}
})
if (this.config.store.terminal.behaviorOnSessionEnds == 'close') {
// Close the tab
this.destroy()
} else if (this.config.store.terminal.behaviorOnSessionEnds.startsWith('reconnect-or-')) {
// Automatically reconnect the session
this.reconnect()
} else {
// Reconnect Offer
if (!this.reconnectOffered) {
this.reconnectOffered = true
this.write(this.translate.instant(_('Press any key to reconnect')) + '\r\n')
this.input$.pipe(first()).subscribe(() => {
if (!this.session?.open && this.reconnectOffered) {
this.reconnect()
}
})
}
}
}
})

View File

@ -225,6 +225,24 @@ div.mt-4
(ngModelChange)='config.save()',
)
.mt-4
h3(translate) Closing
.form-line
.header
.title(translate) Tab's behavior when session ends
.description(*ngIf='config.store.terminal.behaviorOnSessionEnds.startsWith("reconnect-or")', translate) Automatically reconnect the Serial, Telnet or SSH session
select.form-control(
[(ngModel)]='config.store.terminal.behaviorOnSessionEnds',
(ngModelChange)='config.save()'
)
option(ngValue='keep-open', translate) Keep open
option(ngValue='reconnect-or-keep-open', translate) Reconnect, otherwise keep open
option(ngValue='reconnect-or-close', translate) Reconnect, otherwise close
option(ngValue='close', translate) Close
div.mt-4(*ngIf='hostApp.platform === Platform.Windows')
h3(translate) Windows

View File

@ -24,6 +24,7 @@ export class TerminalConfigProvider extends ConfigProvider {
hideCloseButton: false,
hideTabOptionsButton: false,
rightClick: 'menu',
behaviorOnSessionEnds: 'keep-open',
pasteOnMiddleClick: true,
copyOnSelect: false,
copyAsHTML: true,