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