@@ -11,14 +11,16 @@ import { DefaultRouter, TabRpcClient } from "@/app/store/wshrpcutil";
1111import { TermWshClient } from "@/app/view/term/term-wsh" ;
1212import { VDomModel } from "@/app/view/vdom/vdom-model" ;
1313import {
14- WOS ,
1514 atoms ,
1615 getBlockComponentModel ,
16+ getBlockMetaKeyAtom ,
1717 getConnStatusAtom ,
18+ getOverrideConfigAtom ,
1819 getSettingsKeyAtom ,
1920 globalStore ,
2021 useBlockAtom ,
2122 useSettingsPrefixAtom ,
23+ WOS ,
2224} from "@/store/global" ;
2325import * as services from "@/store/services" ;
2426import * as keyutil from "@/util/keyutil" ;
@@ -28,7 +30,7 @@ import * as jotai from "jotai";
2830import * as React from "react" ;
2931import { TermStickers } from "./termsticker" ;
3032import { TermThemeUpdater } from "./termtheme" ;
31- import { computeTheme } from "./termutil" ;
33+ import { computeTheme , DefaultTermTheme } from "./termutil" ;
3234import { TermWrap } from "./termwrap" ;
3335import "./xterm.css" ;
3436
@@ -138,16 +140,17 @@ class TermViewModel {
138140 }
139141 return true ;
140142 } ) ;
143+ this . termThemeNameAtom = useBlockAtom ( blockId , "termthemeatom" , ( ) => {
144+ return jotai . atom < string > ( ( get ) => {
145+ return get ( getOverrideConfigAtom ( this . blockId , "term:theme" ) ) ?? DefaultTermTheme ;
146+ } ) ;
147+ } ) ;
141148 this . blockBg = jotai . atom ( ( get ) => {
142- const blockData = get ( this . blockAtom ) ;
143149 const fullConfig = get ( atoms . fullConfigAtom ) ;
144- let themeName : string = get ( getSettingsKeyAtom ( "term:theme" ) ) ;
145- if ( blockData ?. meta ?. [ "term:theme" ] ) {
146- themeName = blockData . meta [ "term:theme" ] ;
147- }
148- const theme = computeTheme ( fullConfig , themeName ) ;
149- if ( theme != null && theme . background != null ) {
150- return { bg : theme . background } ;
150+ const themeName = get ( this . termThemeNameAtom ) ;
151+ const [ _ , bgcolor ] = computeTheme ( fullConfig , themeName ) ;
152+ if ( bgcolor != null ) {
153+ return { bg : bgcolor } ;
151154 }
152155 return null ;
153156 } ) ;
@@ -169,13 +172,6 @@ class TermViewModel {
169172 return rtnFontSize ;
170173 } ) ;
171174 } ) ;
172- this . termThemeNameAtom = useBlockAtom ( blockId , "termthemeatom" , ( ) => {
173- return jotai . atom < string > ( ( get ) => {
174- const blockData = get ( this . blockAtom ) ;
175- const settingsKeyAtom = getSettingsKeyAtom ( "term:theme" ) ;
176- return blockData ?. meta ?. [ "term:theme" ] ?? get ( settingsKeyAtom ) ?? "default-dark" ;
177- } ) ;
178- } ) ;
179175 this . noPadding = jotai . atom ( true ) ;
180176 this . endIconButtons = jotai . atom ( ( get ) => {
181177 const blockData = get ( this . blockAtom ) ;
@@ -329,7 +325,7 @@ class TermViewModel {
329325 const fullConfig = globalStore . get ( atoms . fullConfigAtom ) ;
330326 const termThemes = fullConfig ?. termthemes ?? { } ;
331327 const termThemeKeys = Object . keys ( termThemes ) ;
332- const curThemeName = globalStore . get ( this . termThemeNameAtom ) ;
328+ const curThemeName = globalStore . get ( getBlockMetaKeyAtom ( this . blockId , "term:theme" ) ) ;
333329 const defaultFontSize = globalStore . get ( getSettingsKeyAtom ( "term:fontsize" ) ) ?? 12 ;
334330 const blockData = globalStore . get ( this . blockAtom ) ;
335331 const overrideFontSize = blockData ?. meta ?. [ "term:fontsize" ] ;
@@ -346,6 +342,12 @@ class TermViewModel {
346342 click : ( ) => this . setTerminalTheme ( themeName ) ,
347343 } ;
348344 } ) ;
345+ submenu . unshift ( {
346+ label : "Default" ,
347+ type : "checkbox" ,
348+ checked : curThemeName == null ,
349+ click : ( ) => this . setTerminalTheme ( null ) ,
350+ } ) ;
349351 const fontSizeSubMenu : ContextMenuItem [ ] = [ 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 ] . map (
350352 ( fontSize : number ) => {
351353 return {
@@ -551,9 +553,8 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
551553
552554 React . useEffect ( ( ) => {
553555 const fullConfig = globalStore . get ( atoms . fullConfigAtom ) ;
554- const termTheme = computeTheme ( fullConfig , blockData ?. meta ?. [ "term:theme" ] ) ;
555- const themeCopy = { ...termTheme } ;
556- themeCopy . background = "#00000000" ;
556+ const termThemeName = globalStore . get ( model . termThemeNameAtom ) ;
557+ const [ termTheme , _ ] = computeTheme ( fullConfig , termThemeName ) ;
557558 let termScrollback = 1000 ;
558559 if ( termSettings ?. [ "term:scrollback" ] ) {
559560 termScrollback = Math . floor ( termSettings [ "term:scrollback" ] ) ;
@@ -572,7 +573,7 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
572573 blockId ,
573574 connectElemRef . current ,
574575 {
575- theme : themeCopy ,
576+ theme : termTheme ,
576577 fontSize : termFontSize ,
577578 fontFamily : termSettings ?. [ "term:fontfamily" ] ?? "Hack" ,
578579 drawBoldTextInBrightColors : false ,
@@ -650,7 +651,7 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
650651 return (
651652 < div className = { clsx ( "view-term" , "term-mode-" + termMode ) } ref = { viewRef } >
652653 < TermResyncHandler blockId = { blockId } model = { model } />
653- < TermThemeUpdater blockId = { blockId } termRef = { termRef } />
654+ < TermThemeUpdater blockId = { blockId } model = { model } termRef = { termRef } />
654655 < TermStickers config = { stickerConfig } />
655656 < TermToolbarVDomNode key = "vdom-toolbar" blockId = { blockId } model = { model } />
656657 < TermVDomNode key = "vdom" blockId = { blockId } model = { model } />
@@ -659,4 +660,4 @@ const TerminalView = ({ blockId, model }: TerminalViewProps) => {
659660 ) ;
660661} ;
661662
662- export { TermViewModel , TerminalView , makeTerminalModel } ;
663+ export { makeTerminalModel , TerminalView , TermViewModel } ;
0 commit comments