Terminal theming (#485)

* init

* use setStyleVar

* backend implementation. scrope level terminal theming.

* only invoke this.applyTermTheme for keys that are updated. command runner for global term theme

* invoke applyTermTheme for global terminal themes as well

* fix nil error

* fix issue were theme can't be found

* fix issue where selected termtheme is not set as default value

* term theme switcher for session

* do not force reload after setting css vars

* fix issues. screenview terminal theme switcher

* remove debugging code

* move getTermThemes to util

* fix global theme reset

* fix workspace theme reset

* fix screenview terminal theme reset issue

* cleanup

* do not apply theme if theme hasn't changed

* do not apply theme if theme hasn't changed in workspace view

* cleanup

* cleanup

* force reload terminal

* fix inconsistency

* fix reset issue

* add a mobx reaction so that theming working when switching sessions

* workig reset

* simplify and cleanup

* refactor

* working global and session terminal theming

* add check

* perf improvement

* more perf improvements

* put reaction componentDidUpdate to make sure ref is already associated to the element

* cleanup

* fix issue where session theme is overriden by global theme on reload

* reduce flickering on reload

* more on reducing flickering on reload

* cleanup

* more cleanup

* fix file not found when no global theme is set

* screen level terminal theming

* update comment

* re-render terminal in history view. cleanup.

* cleanup

* merge main
This commit is contained in:
Red J Adaya
2024-04-01 23:41:24 -07:00
committed by GitHub
parent f41ac1d5e3
commit ca5117cda0
16 changed files with 431 additions and 37 deletions
+52 -2
View File
@@ -123,8 +123,8 @@ var SetVarNameMap map[string]string = map[string]string{
var SetVarScopes = []SetVarScope{
{ScopeName: "global", VarNames: []string{}},
{ScopeName: "client", VarNames: []string{"telemetry"}},
{ScopeName: "session", VarNames: []string{"name", "pos"}},
{ScopeName: "screen", VarNames: []string{"name", "tabcolor", "tabicon", "pos", "pterm", "anchor", "focus", "line", "index"}},
{ScopeName: "session", VarNames: []string{"name", "pos", "theme"}},
{ScopeName: "screen", VarNames: []string{"name", "tabcolor", "tabicon", "pos", "pterm", "anchor", "focus", "line", "index", "theme"}},
{ScopeName: "line", VarNames: []string{}},
// connection = remote, remote = remoteinstance
{ScopeName: "connection", VarNames: []string{"alias", "connectmode", "key", "password", "autoinstall", "color"}},
@@ -190,6 +190,7 @@ func init() {
registerCmdFn("session:showall", SessionShowAllCommand)
registerCmdFn("session:show", SessionShowCommand)
registerCmdFn("session:openshared", SessionOpenSharedCommand)
registerCmdFn("session:termtheme", TermSetThemeCommand)
registerCmdFn("session:ensureone", SessionEnsureOneCommand)
registerCmdFn("screen", ScreenCommand)
@@ -203,6 +204,7 @@ func init() {
registerCmdFn("screen:webshare", ScreenWebShareCommand)
registerCmdFn("screen:reorder", ScreenReorderCommand)
registerCmdFn("screen:show", ScreenShowCommand)
registerCmdFn("screen:termtheme", TermSetThemeCommand)
registerCmdAlias("remote", RemoteCommand)
registerCmdFn("remote:show", RemoteShowCommand)
@@ -3604,6 +3606,38 @@ func ScreenShowCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (s
return update, nil
}
func TermSetThemeCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (scbus.UpdatePacket, error) {
clientData, err := sstore.EnsureClientData(ctx)
if err != nil {
return nil, fmt.Errorf("cannot retrieve client data: %v", err)
}
id, ok := pk.Kwargs["id"]
if !ok {
return nil, fmt.Errorf("id key not provided")
}
themeName, themeNameOk := pk.Kwargs["name"]
feOpts := clientData.FeOpts
if feOpts.TermTheme == nil {
feOpts.TermTheme = make(map[string]string)
}
if themeNameOk && themeName != "" {
feOpts.TermTheme[id] = themeName
} else {
delete(feOpts.TermTheme, id)
}
err = sstore.UpdateClientFeOpts(ctx, feOpts)
if err != nil {
return nil, fmt.Errorf("error updating client feopts: %v", err)
}
clientData, err = sstore.EnsureClientData(ctx)
if err != nil {
return nil, fmt.Errorf("cannot retrieve updated client data: %v", err)
}
update := scbus.MakeUpdatePacket()
update.AddUpdate(*clientData)
return update, nil
}
func SessionShowCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (scbus.UpdatePacket, error) {
ids, err := resolveUiIds(ctx, pk, R_Session)
if err != nil {
@@ -5762,6 +5796,22 @@ func ClientSetCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sc
}
varsUpdated = append(varsUpdated, "theme")
}
if termthemeStr, found := pk.Kwargs["termtheme"]; found {
feOpts := clientData.FeOpts
if feOpts.TermTheme == nil {
feOpts.TermTheme = make(map[string]string)
}
if termthemeStr == "" {
delete(feOpts.TermTheme, "global")
} else {
feOpts.TermTheme["global"] = termthemeStr
}
err = sstore.UpdateClientFeOpts(ctx, feOpts)
if err != nil {
return nil, fmt.Errorf("error updating client feopts: %v", err)
}
varsUpdated = append(varsUpdated, "termtheme")
}
if apiToken, found := pk.Kwargs["openaiapitoken"]; found {
err = validateOpenAIAPIToken(apiToken)
if err != nil {
+4 -3
View File
@@ -250,9 +250,10 @@ type ClientOptsType struct {
}
type FeOptsType struct {
TermFontSize int `json:"termfontsize,omitempty"`
TermFontFamily string `json:"termfontfamily,omitempty"`
Theme string `json:"theme,omitempty"`
TermFontSize int `json:"termfontsize,omitempty"`
TermFontFamily string `json:"termfontfamily,omitempty"`
Theme string `json:"theme,omitempty"`
TermTheme map[string]string `json:"termtheme"`
}
type ReleaseInfoType struct {