Skip to content

Commit

Permalink
fixed #9894 - incorrect background color for profiles with custom col…
Browse files Browse the repository at this point in the history
…or schemes
  • Loading branch information
Eugeny committed Aug 23, 2024
1 parent ccb59c3 commit 3740166
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
10 changes: 2 additions & 8 deletions tabby-terminal/src/api/baseTerminalTab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ResizeEvent, BaseTerminalProfile } from './interfaces'
import { TerminalDecorator } from './decorator'
import { SearchPanelComponent } from '../components/searchPanel.component'
import { MultifocusService } from '../services/multifocus.service'
import { getTerminalBackgroundColor } from '../helpers'


const INACTIVE_TAB_UNLOAD_DELAY = 1000 * 30
Expand Down Expand Up @@ -575,14 +576,7 @@ export class BaseTerminalTabComponent<P extends BaseTerminalProfile> extends Bas
configure (): void {
this.frontend?.configure(this.profile)

if (!this.themes.findCurrentTheme().followsColorScheme && this.config.store.terminal.background === 'colorScheme') {
const scheme = this.profile.terminalColorScheme ?? this.config.store.terminal.colorScheme
if (scheme.background) {
this.backgroundColor = scheme.background
}
} else {
this.backgroundColor = null
}
this.backgroundColor = getTerminalBackgroundColor(this.config, this.themes, this.profile.terminalColorScheme)
}

zoomIn (): void {
Expand Down
23 changes: 12 additions & 11 deletions tabby-terminal/src/frontends/xtermFrontend.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import deepEqual from 'deep-equal'
import { BehaviorSubject, filter, firstValueFrom, takeUntil } from 'rxjs'
import { Injector } from '@angular/core'
import { ConfigService, getCSSFontFamily, getWindows10Build, HostAppService, HotkeysService, Platform, PlatformService, ThemesService } from 'tabby-core'
Expand All @@ -11,9 +12,9 @@ import { Unicode11Addon } from '@xterm/addon-unicode11'
import { SerializeAddon } from '@xterm/addon-serialize'
import { ImageAddon } from '@xterm/addon-image'
import { CanvasAddon } from '@xterm/addon-canvas'
import './xterm.css'
import deepEqual from 'deep-equal'
import { BaseTerminalProfile, TerminalColorScheme } from '../api/interfaces'
import { getTerminalBackgroundColor } from '../helpers'
import './xterm.css'

const COLOR_NAMES = [
'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white',
Expand Down Expand Up @@ -361,21 +362,21 @@ export class XTermFrontend extends Frontend {
}

private configureColors (scheme: TerminalColorScheme|undefined): void {
const config = this.configService.store
const appColorScheme = this.themes._getActiveColorScheme() as TerminalColorScheme

scheme = scheme ?? this.themes._getActiveColorScheme()
scheme = scheme ?? appColorScheme

const theme: ITheme = {
foreground: scheme!.foreground,
selectionBackground: scheme!.selection ?? '#88888888',
selectionForeground: scheme!.selectionForeground ?? undefined,
background: !this.themes.findCurrentTheme().followsColorScheme && config.terminal.background === 'colorScheme' ? scheme!.background : '#00000000',
cursor: scheme!.cursor,
cursorAccent: scheme!.cursorAccent,
foreground: scheme.foreground,
selectionBackground: scheme.selection ?? '#88888888',
selectionForeground: scheme.selectionForeground ?? undefined,
background: getTerminalBackgroundColor(this.configService, this.themes, scheme) ?? '#00000000',
cursor: scheme.cursor,
cursorAccent: scheme.cursorAccent,
}

for (let i = 0; i < COLOR_NAMES.length; i++) {
theme[COLOR_NAMES[i]] = scheme!.colors[i]
theme[COLOR_NAMES[i]] = scheme.colors[i]
}

if (!deepEqual(this.configuredTheme, theme)) {
Expand Down
21 changes: 21 additions & 0 deletions tabby-terminal/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { TerminalColorScheme } from './api/interfaces'
import { ConfigService, ThemesService } from 'tabby-core'

export function getTerminalBackgroundColor (
config: ConfigService,
themes: ThemesService,
scheme?: TerminalColorScheme,
): string|null {
const appTheme = themes.findCurrentTheme()
const appColorScheme = themes._getActiveColorScheme() as TerminalColorScheme

// Use non transparent background when:
// - legacy theme and user choses colorScheme based BG
// - or new theme but profile-specific scheme is used
const shouldUseCSBackground =
!appTheme.followsColorScheme && config.store.terminal.background === 'colorScheme'
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|| appTheme.followsColorScheme && scheme?.name !== appColorScheme.name

return shouldUseCSBackground && scheme ? scheme.background : null
}

0 comments on commit 3740166

Please sign in to comment.