Skip to content

Commit

Permalink
separate color schemes per profile - fixes #5885, fixes #4593, fixes #…
Browse files Browse the repository at this point in the history
…3516, fixes #7457, fixes #765
  • Loading branch information
Eugeny committed Feb 4, 2023
1 parent e018197 commit 69d884e
Show file tree
Hide file tree
Showing 32 changed files with 192 additions and 106 deletions.
1 change: 1 addition & 0 deletions tabby-core/src/services/profiles.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class ProfilesService {
weight: 0,
isBuiltin: false,
isTemplate: false,
terminalColorScheme: null,
}

constructor (
Expand Down
6 changes: 3 additions & 3 deletions tabby-linkifier/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ export abstract class LinkHandler {
regex: RegExp
priority = 1

convert (uri: string, _tab?: BaseTerminalTabComponent): Promise<string>|string {
convert (uri: string, _tab?: BaseTerminalTabComponent<any>): Promise<string>|string {
return uri
}

verify (_uri: string, _tab?: BaseTerminalTabComponent): Promise<boolean>|boolean {
verify (_uri: string, _tab?: BaseTerminalTabComponent<any>): Promise<boolean>|boolean {
return true
}

abstract handle (uri: string, tab?: BaseTerminalTabComponent): void
abstract handle (uri: string, tab?: BaseTerminalTabComponent<any>): void
}
2 changes: 1 addition & 1 deletion tabby-linkifier/src/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class LinkHighlighterDecorator extends TerminalDecorator {
super()
}

attach (tab: BaseTerminalTabComponent): void {
attach (tab: BaseTerminalTabComponent<any>): void {
if (!(tab.frontend instanceof XTermFrontend)) {
// not xterm
return
Expand Down
4 changes: 2 additions & 2 deletions tabby-linkifier/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class BaseFileHandler extends LinkHandler {
}
}

async convert (uri: string, tab?: BaseTerminalTabComponent): Promise<string> {
async convert (uri: string, tab?: BaseTerminalTabComponent<any>): Promise<string> {
let p = untildify(uri)
if (!path.isAbsolute(p) && tab) {
const cwd = await tab.session?.getWorkingDirectory()
Expand Down Expand Up @@ -102,7 +102,7 @@ export class WindowsFileHandler extends BaseFileHandler {
super(toastr, platform)
}

convert (uri: string, tab?: BaseTerminalTabComponent): Promise<string> {
convert (uri: string, tab?: BaseTerminalTabComponent<any>): Promise<string> {
const sanitizedUri = uri.replace(/"/g, '')
return super.convert(sanitizedUri, tab)
}
Expand Down
4 changes: 2 additions & 2 deletions tabby-local/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Profile } from 'tabby-core'
import { BaseTerminalProfile } from 'tabby-terminal'

export interface Shell {
id: string
Expand Down Expand Up @@ -44,7 +44,7 @@ export interface SessionOptions {
runAsAdministrator?: boolean
}

export interface LocalProfile extends Profile {
export interface LocalProfile extends BaseTerminalProfile {
options: SessionOptions
}

Expand Down
3 changes: 1 addition & 2 deletions tabby-local/src/components/terminalTab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import { UACService } from '../services/uac.service'
styles: BaseTerminalTabComponent.styles,
animations: BaseTerminalTabComponent.animations,
})
export class TerminalTabComponent extends BaseTerminalTabComponent {
export class TerminalTabComponent extends BaseTerminalTabComponent<LocalProfile> {
@Input() sessionOptions: SessionOptions // Deprecated
@Input() profile: LocalProfile
session: Session|null = null

// eslint-disable-next-line @typescript-eslint/no-useless-constructor
Expand Down
4 changes: 2 additions & 2 deletions tabby-local/src/services/terminal.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class TerminalService {
* Launches a new terminal with a specific shell and CWD
* @param pause Wait for a keypress when the shell exits
*/
async openTab (profile?: PartialProfile<LocalProfile>|null, cwd?: string|null, pause?: boolean): Promise<TerminalTabComponent> {
async openTab (profile?: PartialProfile<LocalProfile>|null, cwd?: string|null, pause?: boolean): Promise<TerminalTabComponent|null> {
if (!profile) {
profile = await this.getDefaultProfile()
}
Expand All @@ -55,6 +55,6 @@ export class TerminalService {
return (await this.profilesService.openNewTabForProfile({
...fullProfile,
options,
})) as TerminalTabComponent
})) as TerminalTabComponent|null
}
}
10 changes: 6 additions & 4 deletions tabby-local/src/tabContextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class SaveAsProfileContextMenu extends TabContextMenuItemProvider {
if (!(tab instanceof TerminalTabComponent)) {
return []
}
const terminalTab = tab
const items: MenuItemOptions[] = [
{
label: this.translate.instant('Save as profile'),
Expand All @@ -34,8 +35,8 @@ export class SaveAsProfileContextMenu extends TabContextMenuItemProvider {
}
const profile = {
options: {
...tab.profile.options,
cwd: await tab.session?.getWorkingDirectory() ?? tab.profile.options.cwd,
...terminalTab.profile.options,
cwd: await terminalTab.session?.getWorkingDirectory() ?? terminalTab.profile.options.cwd,
},
name,
type: 'local',
Expand Down Expand Up @@ -117,13 +118,14 @@ export class NewTabContextMenu extends TabContextMenuItemProvider {
}

if (tab instanceof TerminalTabComponent && tabHeader && this.uac.isAvailable) {
const terminalTab = tab
items.push({
label: this.translate.instant('Duplicate as administrator'),
click: () => {
this.profilesService.openNewTabForProfile({
...tab.profile,
...terminalTab.profile,
options: {
...tab.profile.options,
...terminalTab.profile.options,
runAsAdministrator: true,
},
})
Expand Down
6 changes: 3 additions & 3 deletions tabby-serial/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import stripAnsi from 'strip-ansi'
import { SerialPortStream } from '@serialport/stream'
import { LogService, NotificationsService, Profile } from 'tabby-core'
import { LogService, NotificationsService } from 'tabby-core'
import { Subject, Observable } from 'rxjs'
import { Injector, NgZone } from '@angular/core'
import { BaseSession, LoginScriptsOptions, SessionMiddleware, StreamProcessingOptions, TerminalStreamProcessor } from 'tabby-terminal'
import { BaseSession, BaseTerminalProfile, LoginScriptsOptions, SessionMiddleware, StreamProcessingOptions, TerminalStreamProcessor } from 'tabby-terminal'
import { SerialService } from './services/serial.service'

export interface SerialProfile extends Profile {
export interface SerialProfile extends BaseTerminalProfile {
options: SerialProfileOptions
}

Expand Down
12 changes: 3 additions & 9 deletions tabby-serial/src/components/serialTab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import { SerialSession, BAUD_RATES, SerialProfile } from '../api'
styles: [require('./serialTab.component.scss'), ...BaseTerminalTabComponent.styles],
animations: BaseTerminalTabComponent.animations,
})
export class SerialTabComponent extends BaseTerminalTabComponent {
profile?: SerialProfile
export class SerialTabComponent extends BaseTerminalTabComponent<SerialProfile> {
session: SerialSession|null = null
serialPort: any
Platform = Platform
Expand Down Expand Up @@ -56,16 +55,11 @@ export class SerialTabComponent extends BaseTerminalTabComponent {
super.ngOnInit()

setImmediate(() => {
this.setTitle(this.profile!.name)
this.setTitle(this.profile.name)
})
}

async initializeSession () {
if (!this.profile) {
this.logger.error('No serial profile info supplied')
return
}

const session = new SerialSession(this.injector, this.profile)
this.setSession(session)

Expand Down Expand Up @@ -121,6 +115,6 @@ export class SerialTabComponent extends BaseTerminalTabComponent {
})),
)
this.serialPort.update({ baudRate: rate })
this.profile!.options.baudrate = rate
this.profile.options.baudrate = rate
}
}
5 changes: 2 additions & 3 deletions tabby-ssh/src/api/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Profile } from 'tabby-core'
import { LoginScriptsOptions } from 'tabby-terminal'
import { BaseTerminalProfile, LoginScriptsOptions } from 'tabby-terminal'

export enum SSHAlgorithmType {
HMAC = 'hmac',
Expand All @@ -8,7 +7,7 @@ export enum SSHAlgorithmType {
HOSTKEY = 'serverHostKey',
}

export interface SSHProfile extends Profile {
export interface SSHProfile extends BaseTerminalProfile {
options: SSHProfileOptions
}

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 @@ -248,6 +248,11 @@ ul.nav-tabs(ngbNav, #nav='ngbNav')
div(*ngFor='let alg of supportedAlgorithms.serverHostKey')
checkbox([text]='alg', [(ngModel)]='algorithms.serverHostKey[alg]')

li(ngbNavItem)
a(ngbNavLink, translate) Color scheme
ng-template(ngbNavContent)
color-scheme-selector([(model)]='profile.terminalColorScheme')

li(ngbNavItem)
a(ngbNavLink, translate) Login scripts
ng-template(ngbNavContent)
Expand Down
15 changes: 3 additions & 12 deletions tabby-ssh/src/components/sshTab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import { SSHMultiplexerService } from '../services/sshMultiplexer.service'
styles: [require('./sshTab.component.scss'), ...BaseTerminalTabComponent.styles],
animations: BaseTerminalTabComponent.animations,
})
export class SSHTabComponent extends BaseTerminalTabComponent {
export class SSHTabComponent extends BaseTerminalTabComponent<SSHProfile> {
Platform = Platform
profile?: SSHProfile
sshSession: SSHSession|null = null
session: SSHShellSession|null = null
sftpPanelVisible = false
Expand All @@ -45,10 +44,6 @@ export class SSHTabComponent extends BaseTerminalTabComponent {
}

ngOnInit (): void {
if (!this.profile) {
throw new Error('Profile not set')
}

this.logger = this.log.create('terminalTab')

this.subscribeUntilDestroyed(this.hotkeys.hotkey$, hotkey => {
Expand Down Expand Up @@ -184,10 +179,6 @@ export class SSHTabComponent extends BaseTerminalTabComponent {
}

private async initializeSessionMaybeMultiplex (multiplex = true): Promise<void> {
if (!this.profile) {
throw new Error('No SSH connection info supplied')
}

this.sshSession = await this.setupOneSession(this.injector, this.profile, multiplex)
const session = new SSHShellSession(this.injector, this.sshSession, this.profile)

Expand Down Expand Up @@ -244,13 +235,13 @@ export class SSHTabComponent extends BaseTerminalTabComponent {
if (!this.session?.open) {
return true
}
if (!(this.profile?.options.warnOnClose ?? this.config.store.ssh.warnOnClose)) {
if (!(this.profile.options.warnOnClose ?? this.config.store.ssh.warnOnClose)) {
return true
}
return (await this.platform.showMessageBox(
{
type: 'warning',
message: this.translate.instant(_('Disconnect from {host}?'), this.profile?.options),
message: this.translate.instant(_('Disconnect from {host}?'), this.profile.options),
buttons: [
this.translate.instant(_('Disconnect')),
this.translate.instant(_('Do not close')),
Expand Down
2 changes: 1 addition & 1 deletion tabby-ssh/src/tabContextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class SFTPContextMenu extends TabContextMenuItemProvider {
}

async getItems (tab: BaseTabComponent): Promise<MenuItemOptions[]> {
if (!(tab instanceof SSHTabComponent) || !tab.profile) {
if (!(tab instanceof SSHTabComponent)) {
return []
}
const items = [{
Expand Down
13 changes: 2 additions & 11 deletions tabby-telnet/src/components/telnetTab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import { TelnetProfile, TelnetSession } from '../session'
styles: [require('./telnetTab.component.scss'), ...BaseTerminalTabComponent.styles],
animations: BaseTerminalTabComponent.animations,
})
export class TelnetTabComponent extends BaseTerminalTabComponent {
export class TelnetTabComponent extends BaseTerminalTabComponent<TelnetProfile> {
Platform = Platform
profile?: TelnetProfile
session: TelnetSession|null = null
private reconnectOffered = false

Expand All @@ -29,10 +28,6 @@ export class TelnetTabComponent extends BaseTerminalTabComponent {
}

ngOnInit (): void {
if (!this.profile) {
throw new Error('Profile not set')
}

this.logger = this.log.create('telnetTab')

this.subscribeUntilDestroyed(this.hotkeys.hotkey$, hotkey => {
Expand Down Expand Up @@ -69,10 +64,6 @@ export class TelnetTabComponent extends BaseTerminalTabComponent {

async initializeSession (): Promise<void> {
this.reconnectOffered = false
if (!this.profile) {
this.logger.error('No Telnet connection info supplied')
return
}

const session = new TelnetSession(this.injector, this.profile)
this.setSession(session)
Expand Down Expand Up @@ -119,7 +110,7 @@ export class TelnetTabComponent extends BaseTerminalTabComponent {
return (await this.platform.showMessageBox(
{
type: 'warning',
message: this.translate.instant(_('Disconnect from {host}?'), this.profile?.options),
message: this.translate.instant(_('Disconnect from {host}?'), this.profile.options),
buttons: [
this.translate.instant(_('Disconnect')),
this.translate.instant(_('Do not close')),
Expand Down
6 changes: 3 additions & 3 deletions tabby-telnet/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { Socket } from 'net'
import colors from 'ansi-colors'
import stripAnsi from 'strip-ansi'
import { Injector } from '@angular/core'
import { Profile, LogService } from 'tabby-core'
import { BaseSession, LoginScriptsOptions, SessionMiddleware, StreamProcessingOptions, TerminalStreamProcessor } from 'tabby-terminal'
import { LogService } from 'tabby-core'
import { BaseSession, BaseTerminalProfile, LoginScriptsOptions, SessionMiddleware, StreamProcessingOptions, TerminalStreamProcessor } from 'tabby-terminal'
import { Subject, Observable } from 'rxjs'


export interface TelnetProfile extends Profile {
export interface TelnetProfile extends BaseTerminalProfile {
options: TelnetProfileOptions
}

Expand Down
2 changes: 1 addition & 1 deletion tabby-terminal/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tabby-terminal",
"version": "1.0.189-nightly.0",
"version": "1.0.189-nightly.2",
"description": "Tabby's terminal emulation core",
"keywords": [
"tabby-builtin-plugin"
Expand Down

0 comments on commit 69d884e

Please sign in to comment.