Skip to content

Commit ca9f114

Browse files
committed
move terminal-tab to use .profile
1 parent 9d224cb commit ca9f114

8 files changed

Lines changed: 69 additions & 45 deletions

File tree

tabby-core/src/api/profileProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface Profile {
88
type: string
99
name: string
1010
group?: string
11-
options?: Record<string, any>
11+
options: Record<string, any>
1212

1313
icon?: string
1414
color?: string

tabby-local/src/components/terminalTab.component.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Component, Input, Injector } from '@angular/core'
22
import { BaseTabProcess, WIN_BUILD_CONPTY_SUPPORTED, isWindowsBuild } from 'tabby-core'
33
import { BaseTerminalTabComponent } from 'tabby-terminal'
4-
import { SessionOptions } from '../api'
4+
import { LocalProfile } from '../api'
55
import { Session } from '../session'
66
import { UACService } from '../services/uac.service'
7+
import { SessionOptions } from 'http2'
78

89
/** @hidden */
910
@Component({
@@ -13,7 +14,8 @@ import { UACService } from '../services/uac.service'
1314
animations: BaseTerminalTabComponent.animations,
1415
})
1516
export class TerminalTabComponent extends BaseTerminalTabComponent {
16-
@Input() sessionOptions: SessionOptions
17+
@Input() sessionOptions: SessionOptions // Deprecated
18+
@Input() profile: LocalProfile
1719
session: Session|null = null
1820

1921
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
@@ -25,6 +27,8 @@ export class TerminalTabComponent extends BaseTerminalTabComponent {
2527
}
2628

2729
ngOnInit (): void {
30+
this.sessionOptions = this.profile.options
31+
2832
this.logger = this.log.create('terminalTab')
2933
this.session = new Session(this.injector)
3034

@@ -49,17 +53,17 @@ export class TerminalTabComponent extends BaseTerminalTabComponent {
4953

5054
protected onFrontendReady (): void {
5155
this.initializeSession(this.size.columns, this.size.rows)
52-
this.savedStateIsLive = this.sessionOptions.restoreFromPTYID === this.session?.getPTYID()
56+
this.savedStateIsLive = this.profile.options.restoreFromPTYID === this.session?.getPTYID()
5357
super.onFrontendReady()
5458
}
5559

5660
initializeSession (columns: number, rows: number): void {
57-
if (this.sessionOptions.runAsAdministrator && this.uac.isAvailable) {
58-
this.sessionOptions = this.uac.patchSessionOptionsForUAC(this.sessionOptions)
61+
if (this.profile.options.runAsAdministrator && this.uac.isAvailable) {
62+
this.profile.options = this.uac.patchSessionOptionsForUAC(this.profile.options)
5963
}
6064

6165
this.session!.start({
62-
...this.sessionOptions,
66+
...this.profile.options,
6367
width: columns,
6468
height: rows,
6569
})
@@ -72,10 +76,13 @@ export class TerminalTabComponent extends BaseTerminalTabComponent {
7276
const cwd = this.session ? await this.session.getWorkingDirectory() : null
7377
return {
7478
type: 'app:terminal-tab',
75-
sessionOptions: {
76-
...this.sessionOptions,
77-
cwd: cwd ?? this.sessionOptions.cwd,
78-
restoreFromPTYID: this.session?.getPTYID(),
79+
profile: {
80+
...this.profile,
81+
options: {
82+
...this.profile.options,
83+
cwd: cwd ?? this.profile.options.cwd,
84+
restoreFromPTYID: this.session?.getPTYID(),
85+
},
7986
},
8087
savedState: this.frontend?.saveState(),
8188
}

tabby-local/src/profiles.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import deepClone from 'clone-deep'
12
import { Injectable, Inject } from '@angular/core'
23
import { ProfileProvider, Profile, NewTabParameters, ConfigService, SplitTabComponent, AppService } from 'tabby-core'
34
import { TerminalTabComponent } from './components/terminalTab.component'
@@ -9,6 +10,21 @@ export class LocalProfilesService extends ProfileProvider {
910
id = 'local'
1011
name = 'Local'
1112
settingsComponent = LocalProfileSettingsComponent
13+
configDefaults = {
14+
options: {
15+
restoreFromPTYID: null,
16+
command: '',
17+
args: [],
18+
cwd: null,
19+
env: {
20+
__nonStructural: true,
21+
},
22+
width: null,
23+
height: null,
24+
pauseAfterExit: false,
25+
runAsAdministrator: false,
26+
},
27+
}
1228

1329
constructor (
1430
private app: AppService,
@@ -30,25 +46,27 @@ export class LocalProfilesService extends ProfileProvider {
3046
}
3147

3248
async getNewTabParameters (profile: Profile): Promise<NewTabParameters<TerminalTabComponent>> {
33-
const options = { ...profile.options }
49+
profile = deepClone(profile)
3450

35-
if (!options.cwd) {
51+
if (!profile.options?.cwd) {
3652
if (this.app.activeTab instanceof TerminalTabComponent && this.app.activeTab.session) {
37-
options.cwd = await this.app.activeTab.session.getWorkingDirectory()
53+
profile.options ??= {}
54+
profile.options.cwd = await this.app.activeTab.session.getWorkingDirectory()
3855
}
3956
if (this.app.activeTab instanceof SplitTabComponent) {
4057
const focusedTab = this.app.activeTab.getFocusedTab()
4158

4259
if (focusedTab instanceof TerminalTabComponent && focusedTab.session) {
43-
options.cwd = await focusedTab.session.getWorkingDirectory()
60+
profile.options ??= {}
61+
profile.options.cwd = await focusedTab.session.getWorkingDirectory()
4462
}
4563
}
4664
}
4765

4866
return {
4967
type: TerminalTabComponent,
5068
inputs: {
51-
sessionOptions: options,
69+
profile,
5270
},
5371
}
5472
}

tabby-local/src/recoveryProvider.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import { TerminalTabComponent } from './components/terminalTab.component'
77
@Injectable()
88
export class RecoveryProvider extends TabRecoveryProvider<TerminalTabComponent> {
99
async applicableTo (recoveryToken: RecoveryToken): Promise<boolean> {
10-
return recoveryToken.type === 'app:terminal-tab'
10+
return recoveryToken.type === 'app:local-tab'
1111
}
1212

1313
async recover (recoveryToken: RecoveryToken): Promise<NewTabParameters<TerminalTabComponent>> {
1414
return {
1515
type: TerminalTabComponent,
1616
inputs: {
17-
sessionOptions: recoveryToken.sessionOptions,
17+
profile: recoveryToken.profile,
1818
savedState: recoveryToken.savedState,
1919
},
2020
}
@@ -23,9 +23,12 @@ export class RecoveryProvider extends TabRecoveryProvider<TerminalTabComponent>
2323
duplicate (recoveryToken: RecoveryToken): RecoveryToken {
2424
return {
2525
...recoveryToken,
26-
sessionOptions: {
27-
...recoveryToken.sessionOptions,
28-
restoreFromPTYID: null,
26+
profile: {
27+
...recoveryToken.profile,
28+
options: {
29+
...recoveryToken.profile.options,
30+
restoreFromPTYID: null,
31+
},
2932
},
3033
savedState: null,
3134
}

tabby-local/src/services/terminal.service.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from 'mz/fs'
22
import { Injectable } from '@angular/core'
33
import { Logger, LogService, ConfigService, AppService, ProfilesService } from 'tabby-core'
44
import { TerminalTabComponent } from '../components/terminalTab.component'
5-
import { SessionOptions, LocalProfile } from '../api'
5+
import { LocalProfile } from '../api'
66

77
@Injectable({ providedIn: 'root' })
88
export class TerminalService {
@@ -55,15 +55,4 @@ export class TerminalService {
5555
options,
5656
})) as TerminalTabComponent
5757
}
58-
59-
/**
60-
* Open a terminal with custom session options
61-
*/
62-
openTabWithOptions (sessionOptions: SessionOptions): TerminalTabComponent {
63-
this.logger.info('Using session options:', sessionOptions)
64-
return this.app.openNewTab({
65-
type: TerminalTabComponent,
66-
inputs: { sessionOptions },
67-
})
68-
}
6958
}

tabby-local/src/session.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ export class Session extends BaseSession {
104104
}
105105

106106
start (options: SessionOptions): void {
107-
this.name = options.name ?? ''
108-
109107
let pty: PTYProxy|null = null
110108

111109
if (options.restoreFromPTYID) {

tabby-local/src/tabContextMenu.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export class SaveAsProfileContextMenu extends TabContextMenuItemProvider {
3333
}
3434
const profile = {
3535
options: {
36-
...tab.sessionOptions,
37-
cwd: await tab.session?.getWorkingDirectory() ?? tab.sessionOptions.cwd,
36+
...tab.profile.options,
37+
cwd: await tab.session?.getWorkingDirectory() ?? tab.profile.options.cwd,
3838
},
3939
name,
4040
type: 'local',
@@ -74,7 +74,11 @@ export class NewTabContextMenu extends TabContextMenuItemProvider {
7474
{
7575
label: 'New terminal',
7676
click: () => {
77-
this.terminalService.openTabWithOptions((tab as any).sessionOptions)
77+
if (tab instanceof TerminalTabComponent) {
78+
this.profilesService.openNewTabForProfile(tab.profile)
79+
} else {
80+
this.terminalService.openTab()
81+
}
7882
},
7983
},
8084
{
@@ -98,9 +102,12 @@ export class NewTabContextMenu extends TabContextMenuItemProvider {
98102
submenu: profiles.map(profile => ({
99103
label: profile.name,
100104
click: () => {
101-
this.terminalService.openTabWithOptions({
102-
...profile.options,
103-
runAsAdministrator: true,
105+
this.profilesService.openNewTabForProfile({
106+
...profile,
107+
options: {
108+
...profile.options,
109+
runAsAdministrator: true,
110+
},
104111
})
105112
},
106113
})),
@@ -111,9 +118,12 @@ export class NewTabContextMenu extends TabContextMenuItemProvider {
111118
items.push({
112119
label: 'Duplicate as administrator',
113120
click: () => {
114-
this.terminalService.openTabWithOptions({
115-
...tab.sessionOptions,
116-
runAsAdministrator: true,
121+
this.profilesService.openNewTabForProfile({
122+
...tab.profile,
123+
options: {
124+
...tab.profile.options,
125+
runAsAdministrator: true,
126+
},
117127
})
118128
},
119129
})

tabby-terminal/src/session.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { LoginScriptProcessor, LoginScriptsOptions } from './api/loginScriptProc
88
*/
99
export abstract class BaseSession {
1010
open: boolean
11-
name: string
1211
truePID: number
1312
protected output = new Subject<string>()
1413
protected binaryOutput = new Subject<Buffer>()

0 commit comments

Comments
 (0)