mirror of
https://github.com/Eugeny/tabby.git
synced 2024-12-09 06:20:22 +08:00
move terminal-tab to use .profile
This commit is contained in:
parent
9d224cbce2
commit
ca9f11484c
@ -8,7 +8,7 @@ export interface Profile {
|
||||
type: string
|
||||
name: string
|
||||
group?: string
|
||||
options?: Record<string, any>
|
||||
options: Record<string, any>
|
||||
|
||||
icon?: string
|
||||
color?: string
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { Component, Input, Injector } from '@angular/core'
|
||||
import { BaseTabProcess, WIN_BUILD_CONPTY_SUPPORTED, isWindowsBuild } from 'tabby-core'
|
||||
import { BaseTerminalTabComponent } from 'tabby-terminal'
|
||||
import { SessionOptions } from '../api'
|
||||
import { LocalProfile } from '../api'
|
||||
import { Session } from '../session'
|
||||
import { UACService } from '../services/uac.service'
|
||||
import { SessionOptions } from 'http2'
|
||||
|
||||
/** @hidden */
|
||||
@Component({
|
||||
@ -13,7 +14,8 @@ import { UACService } from '../services/uac.service'
|
||||
animations: BaseTerminalTabComponent.animations,
|
||||
})
|
||||
export class TerminalTabComponent extends BaseTerminalTabComponent {
|
||||
@Input() sessionOptions: SessionOptions
|
||||
@Input() sessionOptions: SessionOptions // Deprecated
|
||||
@Input() profile: LocalProfile
|
||||
session: Session|null = null
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
|
||||
@ -25,6 +27,8 @@ export class TerminalTabComponent extends BaseTerminalTabComponent {
|
||||
}
|
||||
|
||||
ngOnInit (): void {
|
||||
this.sessionOptions = this.profile.options
|
||||
|
||||
this.logger = this.log.create('terminalTab')
|
||||
this.session = new Session(this.injector)
|
||||
|
||||
@ -49,17 +53,17 @@ export class TerminalTabComponent extends BaseTerminalTabComponent {
|
||||
|
||||
protected onFrontendReady (): void {
|
||||
this.initializeSession(this.size.columns, this.size.rows)
|
||||
this.savedStateIsLive = this.sessionOptions.restoreFromPTYID === this.session?.getPTYID()
|
||||
this.savedStateIsLive = this.profile.options.restoreFromPTYID === this.session?.getPTYID()
|
||||
super.onFrontendReady()
|
||||
}
|
||||
|
||||
initializeSession (columns: number, rows: number): void {
|
||||
if (this.sessionOptions.runAsAdministrator && this.uac.isAvailable) {
|
||||
this.sessionOptions = this.uac.patchSessionOptionsForUAC(this.sessionOptions)
|
||||
if (this.profile.options.runAsAdministrator && this.uac.isAvailable) {
|
||||
this.profile.options = this.uac.patchSessionOptionsForUAC(this.profile.options)
|
||||
}
|
||||
|
||||
this.session!.start({
|
||||
...this.sessionOptions,
|
||||
...this.profile.options,
|
||||
width: columns,
|
||||
height: rows,
|
||||
})
|
||||
@ -72,10 +76,13 @@ export class TerminalTabComponent extends BaseTerminalTabComponent {
|
||||
const cwd = this.session ? await this.session.getWorkingDirectory() : null
|
||||
return {
|
||||
type: 'app:terminal-tab',
|
||||
sessionOptions: {
|
||||
...this.sessionOptions,
|
||||
cwd: cwd ?? this.sessionOptions.cwd,
|
||||
restoreFromPTYID: this.session?.getPTYID(),
|
||||
profile: {
|
||||
...this.profile,
|
||||
options: {
|
||||
...this.profile.options,
|
||||
cwd: cwd ?? this.profile.options.cwd,
|
||||
restoreFromPTYID: this.session?.getPTYID(),
|
||||
},
|
||||
},
|
||||
savedState: this.frontend?.saveState(),
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import deepClone from 'clone-deep'
|
||||
import { Injectable, Inject } from '@angular/core'
|
||||
import { ProfileProvider, Profile, NewTabParameters, ConfigService, SplitTabComponent, AppService } from 'tabby-core'
|
||||
import { TerminalTabComponent } from './components/terminalTab.component'
|
||||
@ -9,6 +10,21 @@ export class LocalProfilesService extends ProfileProvider {
|
||||
id = 'local'
|
||||
name = 'Local'
|
||||
settingsComponent = LocalProfileSettingsComponent
|
||||
configDefaults = {
|
||||
options: {
|
||||
restoreFromPTYID: null,
|
||||
command: '',
|
||||
args: [],
|
||||
cwd: null,
|
||||
env: {
|
||||
__nonStructural: true,
|
||||
},
|
||||
width: null,
|
||||
height: null,
|
||||
pauseAfterExit: false,
|
||||
runAsAdministrator: false,
|
||||
},
|
||||
}
|
||||
|
||||
constructor (
|
||||
private app: AppService,
|
||||
@ -30,17 +46,19 @@ export class LocalProfilesService extends ProfileProvider {
|
||||
}
|
||||
|
||||
async getNewTabParameters (profile: Profile): Promise<NewTabParameters<TerminalTabComponent>> {
|
||||
const options = { ...profile.options }
|
||||
profile = deepClone(profile)
|
||||
|
||||
if (!options.cwd) {
|
||||
if (!profile.options?.cwd) {
|
||||
if (this.app.activeTab instanceof TerminalTabComponent && this.app.activeTab.session) {
|
||||
options.cwd = await this.app.activeTab.session.getWorkingDirectory()
|
||||
profile.options ??= {}
|
||||
profile.options.cwd = await this.app.activeTab.session.getWorkingDirectory()
|
||||
}
|
||||
if (this.app.activeTab instanceof SplitTabComponent) {
|
||||
const focusedTab = this.app.activeTab.getFocusedTab()
|
||||
|
||||
if (focusedTab instanceof TerminalTabComponent && focusedTab.session) {
|
||||
options.cwd = await focusedTab.session.getWorkingDirectory()
|
||||
profile.options ??= {}
|
||||
profile.options.cwd = await focusedTab.session.getWorkingDirectory()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -48,7 +66,7 @@ export class LocalProfilesService extends ProfileProvider {
|
||||
return {
|
||||
type: TerminalTabComponent,
|
||||
inputs: {
|
||||
sessionOptions: options,
|
||||
profile,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -7,14 +7,14 @@ import { TerminalTabComponent } from './components/terminalTab.component'
|
||||
@Injectable()
|
||||
export class RecoveryProvider extends TabRecoveryProvider<TerminalTabComponent> {
|
||||
async applicableTo (recoveryToken: RecoveryToken): Promise<boolean> {
|
||||
return recoveryToken.type === 'app:terminal-tab'
|
||||
return recoveryToken.type === 'app:local-tab'
|
||||
}
|
||||
|
||||
async recover (recoveryToken: RecoveryToken): Promise<NewTabParameters<TerminalTabComponent>> {
|
||||
return {
|
||||
type: TerminalTabComponent,
|
||||
inputs: {
|
||||
sessionOptions: recoveryToken.sessionOptions,
|
||||
profile: recoveryToken.profile,
|
||||
savedState: recoveryToken.savedState,
|
||||
},
|
||||
}
|
||||
@ -23,9 +23,12 @@ export class RecoveryProvider extends TabRecoveryProvider<TerminalTabComponent>
|
||||
duplicate (recoveryToken: RecoveryToken): RecoveryToken {
|
||||
return {
|
||||
...recoveryToken,
|
||||
sessionOptions: {
|
||||
...recoveryToken.sessionOptions,
|
||||
restoreFromPTYID: null,
|
||||
profile: {
|
||||
...recoveryToken.profile,
|
||||
options: {
|
||||
...recoveryToken.profile.options,
|
||||
restoreFromPTYID: null,
|
||||
},
|
||||
},
|
||||
savedState: null,
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ import * as fs from 'mz/fs'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { Logger, LogService, ConfigService, AppService, ProfilesService } from 'tabby-core'
|
||||
import { TerminalTabComponent } from '../components/terminalTab.component'
|
||||
import { SessionOptions, LocalProfile } from '../api'
|
||||
import { LocalProfile } from '../api'
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class TerminalService {
|
||||
@ -55,15 +55,4 @@ export class TerminalService {
|
||||
options,
|
||||
})) as TerminalTabComponent
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a terminal with custom session options
|
||||
*/
|
||||
openTabWithOptions (sessionOptions: SessionOptions): TerminalTabComponent {
|
||||
this.logger.info('Using session options:', sessionOptions)
|
||||
return this.app.openNewTab({
|
||||
type: TerminalTabComponent,
|
||||
inputs: { sessionOptions },
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -104,8 +104,6 @@ export class Session extends BaseSession {
|
||||
}
|
||||
|
||||
start (options: SessionOptions): void {
|
||||
this.name = options.name ?? ''
|
||||
|
||||
let pty: PTYProxy|null = null
|
||||
|
||||
if (options.restoreFromPTYID) {
|
||||
|
@ -33,8 +33,8 @@ export class SaveAsProfileContextMenu extends TabContextMenuItemProvider {
|
||||
}
|
||||
const profile = {
|
||||
options: {
|
||||
...tab.sessionOptions,
|
||||
cwd: await tab.session?.getWorkingDirectory() ?? tab.sessionOptions.cwd,
|
||||
...tab.profile.options,
|
||||
cwd: await tab.session?.getWorkingDirectory() ?? tab.profile.options.cwd,
|
||||
},
|
||||
name,
|
||||
type: 'local',
|
||||
@ -74,7 +74,11 @@ export class NewTabContextMenu extends TabContextMenuItemProvider {
|
||||
{
|
||||
label: 'New terminal',
|
||||
click: () => {
|
||||
this.terminalService.openTabWithOptions((tab as any).sessionOptions)
|
||||
if (tab instanceof TerminalTabComponent) {
|
||||
this.profilesService.openNewTabForProfile(tab.profile)
|
||||
} else {
|
||||
this.terminalService.openTab()
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -98,9 +102,12 @@ export class NewTabContextMenu extends TabContextMenuItemProvider {
|
||||
submenu: profiles.map(profile => ({
|
||||
label: profile.name,
|
||||
click: () => {
|
||||
this.terminalService.openTabWithOptions({
|
||||
...profile.options,
|
||||
runAsAdministrator: true,
|
||||
this.profilesService.openNewTabForProfile({
|
||||
...profile,
|
||||
options: {
|
||||
...profile.options,
|
||||
runAsAdministrator: true,
|
||||
},
|
||||
})
|
||||
},
|
||||
})),
|
||||
@ -111,9 +118,12 @@ export class NewTabContextMenu extends TabContextMenuItemProvider {
|
||||
items.push({
|
||||
label: 'Duplicate as administrator',
|
||||
click: () => {
|
||||
this.terminalService.openTabWithOptions({
|
||||
...tab.sessionOptions,
|
||||
runAsAdministrator: true,
|
||||
this.profilesService.openNewTabForProfile({
|
||||
...tab.profile,
|
||||
options: {
|
||||
...tab.profile.options,
|
||||
runAsAdministrator: true,
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
|
@ -8,7 +8,6 @@ import { LoginScriptProcessor, LoginScriptsOptions } from './api/loginScriptProc
|
||||
*/
|
||||
export abstract class BaseSession {
|
||||
open: boolean
|
||||
name: string
|
||||
truePID: number
|
||||
protected output = new Subject<string>()
|
||||
protected binaryOutput = new Subject<Buffer>()
|
||||
|
Loading…
Reference in New Issue
Block a user