mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-02-21 02:33:34 +01:00
tab colors
This commit is contained in:
parent
1997b9ea44
commit
aff174fa80
@ -25,6 +25,8 @@ import (
|
||||
const DefaultUserId = "sawka"
|
||||
const MaxNameLen = 50
|
||||
|
||||
var ColorNames = []string{"black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "orange"}
|
||||
|
||||
var genericNameRe = regexp.MustCompile("^[a-zA-Z][a-zA-Z0-9_ .()<>,/\"'\\[\\]{}=+$@!*-]*$")
|
||||
var positionRe = regexp.MustCompile("^((\\+|-)?[0-9]+|(\\+|-))$")
|
||||
var wsRe = regexp.MustCompile("\\s+")
|
||||
@ -251,8 +253,29 @@ func ScreenSetCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (ss
|
||||
}
|
||||
varsUpdated = append(varsUpdated, "name")
|
||||
}
|
||||
if pk.Kwargs["tabcolor"] != "" {
|
||||
color := pk.Kwargs["tabcolor"]
|
||||
err = validateColor(color, "screen tabcolor")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
screenObj, err := sstore.GetScreenById(ctx, ids.SessionId, ids.ScreenId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
opts := screenObj.ScreenOpts
|
||||
if opts == nil {
|
||||
opts = &sstore.ScreenOptsType{}
|
||||
}
|
||||
opts.TabColor = color
|
||||
err = sstore.SetScreenOpts(ctx, ids.SessionId, ids.ScreenId, opts)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("setting screen opts: %v", err)
|
||||
}
|
||||
varsUpdated = append(varsUpdated, "tabcolor")
|
||||
}
|
||||
if len(varsUpdated) == 0 {
|
||||
return nil, fmt.Errorf("/screen:set no updates, can set %s", formatStrs([]string{"name", "pos"}, "or", false))
|
||||
return nil, fmt.Errorf("/screen:set no updates, can set %s", formatStrs([]string{"name", "pos", "tabcolor"}, "or", false))
|
||||
}
|
||||
screenObj, err := sstore.GetScreenById(ctx, ids.SessionId, ids.ScreenId)
|
||||
if err != nil {
|
||||
@ -779,6 +802,15 @@ func validateName(name string, typeStr string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateColor(color string, typeStr string) error {
|
||||
for _, c := range ColorNames {
|
||||
if color == c {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("invalid %s, valid colors are: %s", typeStr, formatStrs(ColorNames, "or", false))
|
||||
}
|
||||
|
||||
func SessionOpenCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) {
|
||||
activate := resolveBool(pk.Kwargs["activate"], true)
|
||||
newName := pk.Kwargs["name"]
|
||||
|
@ -756,3 +756,19 @@ func SetScreenName(ctx context.Context, sessionId string, screenId string, name
|
||||
})
|
||||
return txErr
|
||||
}
|
||||
|
||||
func SetScreenOpts(ctx context.Context, sessionId string, screenId string, opts *ScreenOptsType) error {
|
||||
if opts == nil {
|
||||
return fmt.Errorf("invalid screen opts cannot be nil")
|
||||
}
|
||||
txErr := WithTx(ctx, func(tx *TxWrap) error {
|
||||
query := `SELECT screenid FROM screen WHERE sessionid = ? AND screenid = ?`
|
||||
if !tx.Exists(query, sessionId, screenId) {
|
||||
return fmt.Errorf("screen does not exist")
|
||||
}
|
||||
query = `UPDATE screen SET screenopts = ? WHERE sessionid = ? AND screenid = ?`
|
||||
tx.ExecWrap(query, opts, sessionId, screenId)
|
||||
return nil
|
||||
})
|
||||
return txErr
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ func WindowFromMap(m map[string]interface{}) *WindowType {
|
||||
}
|
||||
|
||||
type ScreenOptsType struct {
|
||||
TabColor string `json:"tabcolor"`
|
||||
TabColor string `json:"tabcolor,omitempty"`
|
||||
}
|
||||
|
||||
func (opts *ScreenOptsType) Scan(val interface{}) error {
|
||||
|
Loading…
Reference in New Issue
Block a user