2024-06-22 09:41:49 +02:00
|
|
|
// Copyright 2024, Command Line Inc.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2024-06-20 08:59:41 +02:00
|
|
|
package wconfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"github.com/wavetermdev/thenextwave/pkg/wavebase"
|
|
|
|
"github.com/wavetermdev/thenextwave/pkg/wstore"
|
|
|
|
)
|
|
|
|
|
2024-07-25 05:34:22 +02:00
|
|
|
const termThemesDir = "terminal-themes"
|
2024-06-20 08:59:41 +02:00
|
|
|
const settingsFile = "settings.json"
|
|
|
|
|
|
|
|
var settingsAbsPath = filepath.Join(configDirAbsPath, settingsFile)
|
|
|
|
|
|
|
|
type WidgetsConfigType struct {
|
2024-06-20 22:03:50 +02:00
|
|
|
Icon string `json:"icon"`
|
|
|
|
Color string `json:"color,omitempty"`
|
|
|
|
Label string `json:"label,omitempty"`
|
|
|
|
Description string `json:"description,omitempty"`
|
|
|
|
BlockDef wstore.BlockDef `json:"blockdef"`
|
2024-06-20 08:59:41 +02:00
|
|
|
}
|
|
|
|
|
2024-06-21 22:23:07 +02:00
|
|
|
type TerminalConfigType struct {
|
|
|
|
FontSize int `json:"fontsize,omitempty"`
|
|
|
|
FontFamily string `json:"fontfamily,omitempty"`
|
|
|
|
}
|
|
|
|
|
2024-06-22 09:41:49 +02:00
|
|
|
type MimeTypeConfigType struct {
|
2024-06-26 21:14:59 +02:00
|
|
|
Icon string `json:"icon"`
|
|
|
|
Color string `json:"color"`
|
2024-06-22 09:41:49 +02:00
|
|
|
}
|
|
|
|
|
2024-06-25 01:25:53 +02:00
|
|
|
type BlockHeaderOpts struct {
|
|
|
|
ShowBlockIds bool `json:"showblockids"`
|
|
|
|
}
|
|
|
|
|
2024-07-19 01:55:04 +02:00
|
|
|
type AutoUpdateOpts struct {
|
|
|
|
Enabled bool `json:"enabled"`
|
|
|
|
IntervalMs uint32 `json:"intervalms"`
|
|
|
|
}
|
|
|
|
|
2024-07-25 05:34:22 +02:00
|
|
|
type TermThemeType struct {
|
|
|
|
Black string `json:"black"`
|
|
|
|
Red string `json:"red"`
|
|
|
|
Green string `json:"green"`
|
|
|
|
Yellow string `json:"yellow"`
|
|
|
|
Blue string `json:"blue"`
|
|
|
|
Magenta string `json:"magenta"`
|
|
|
|
Cyan string `json:"cyan"`
|
|
|
|
White string `json:"white"`
|
|
|
|
BrightBlack string `json:"brightBlack"`
|
|
|
|
BrightRed string `json:"brightRed"`
|
|
|
|
BrightGreen string `json:"brightGreen"`
|
|
|
|
BrightYellow string `json:"brightYellow"`
|
|
|
|
BrightBlue string `json:"brightBlue"`
|
|
|
|
BrightMagenta string `json:"brightMagenta"`
|
|
|
|
BrightCyan string `json:"brightCyan"`
|
|
|
|
BrightWhite string `json:"brightWhite"`
|
|
|
|
Gray string `json:"gray"`
|
|
|
|
CmdText string `json:"cmdtext"`
|
|
|
|
Foreground string `json:"foreground"`
|
|
|
|
SelectionBackground string `json:"selectionBackground"`
|
|
|
|
Background string `json:"background"`
|
|
|
|
CursorAccent string `json:"cursorAccent"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type TermThemesConfigType map[string]TermThemeType
|
|
|
|
|
|
|
|
// TODO add default term theme settings
|
|
|
|
|
2024-06-20 08:59:41 +02:00
|
|
|
type SettingsConfigType struct {
|
2024-06-25 01:25:53 +02:00
|
|
|
MimeTypes map[string]MimeTypeConfigType `json:"mimetypes"`
|
|
|
|
Term TerminalConfigType `json:"term"`
|
|
|
|
Widgets []WidgetsConfigType `json:"widgets"`
|
|
|
|
BlockHeader BlockHeaderOpts `json:"blockheader"`
|
2024-07-25 05:34:22 +02:00
|
|
|
AutoUpdate *AutoUpdateOpts `json:"autoupdate"`
|
|
|
|
TermThemes TermThemesConfigType `json:"termthemes"`
|
2024-06-20 08:59:41 +02:00
|
|
|
}
|
|
|
|
|
2024-07-25 05:34:22 +02:00
|
|
|
var DefaultTermDarkTheme = TermThemeType{
|
|
|
|
Black: "#757575",
|
|
|
|
Red: "#cc685c",
|
|
|
|
Green: "#76c266",
|
|
|
|
Yellow: "#cbca9b",
|
|
|
|
Blue: "#85aacb",
|
|
|
|
Magenta: "#cc72ca",
|
|
|
|
Cyan: "#74a7cb",
|
|
|
|
White: "#c1c1c1",
|
|
|
|
BrightBlack: "#727272",
|
|
|
|
BrightRed: "#cc9d97",
|
|
|
|
BrightGreen: "#a3dd97",
|
|
|
|
BrightYellow: "#cbcaaa",
|
|
|
|
BrightBlue: "#9ab6cb",
|
|
|
|
BrightMagenta: "#cc8ecb",
|
|
|
|
BrightCyan: "#b7b8cb",
|
|
|
|
BrightWhite: "#f0f0f0",
|
|
|
|
Gray: "#8b918a",
|
|
|
|
CmdText: "#f0f0f0",
|
|
|
|
Foreground: "#c1c1c1",
|
|
|
|
SelectionBackground: "",
|
|
|
|
Background: "#00000000",
|
|
|
|
CursorAccent: "",
|
|
|
|
}
|
|
|
|
|
|
|
|
func applyDefaultSettings(settings *SettingsConfigType) {
|
|
|
|
defaultMimeTypes := map[string]MimeTypeConfigType{
|
|
|
|
"audio": {Icon: "file-audio"},
|
|
|
|
"application/pdf": {Icon: "file-pdf"},
|
|
|
|
"application/json": {Icon: "file-lines"},
|
|
|
|
"directory": {Icon: "folder", Color: "var(--term-bright-blue)"},
|
|
|
|
"font": {Icon: "book-font"},
|
|
|
|
"image": {Icon: "file-image"},
|
|
|
|
"text": {Icon: "file-lines"},
|
|
|
|
"text/css": {Icon: "css3-alt fa-brands"},
|
|
|
|
"text/javascript": {Icon: "js fa-brands"},
|
|
|
|
"text/typescript": {Icon: "js fa-brands"},
|
|
|
|
"text/golang": {Icon: "golang fa-brands"},
|
|
|
|
"text/html": {Icon: "html5 fa-brands"},
|
|
|
|
"text/less": {Icon: "less fa-brands"},
|
|
|
|
"text/markdown": {Icon: "markdown fa-brands"},
|
|
|
|
"text/rust": {Icon: "rust fa-brands"},
|
|
|
|
"text/scss": {Icon: "sass fa-brands"},
|
|
|
|
"video": {Icon: "file-video"},
|
|
|
|
"text/csv": {Icon: "file-csv"},
|
|
|
|
}
|
|
|
|
if settings.MimeTypes == nil {
|
|
|
|
settings.MimeTypes = defaultMimeTypes
|
|
|
|
} else {
|
|
|
|
for k, v := range defaultMimeTypes {
|
|
|
|
if _, found := settings.MimeTypes[k]; !found {
|
|
|
|
settings.MimeTypes[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if settings.AutoUpdate == nil {
|
|
|
|
settings.AutoUpdate = &AutoUpdateOpts{
|
|
|
|
Enabled: true,
|
|
|
|
IntervalMs: 3600000,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
defaultWidgets := []WidgetsConfigType{
|
|
|
|
{
|
|
|
|
Icon: "files",
|
|
|
|
Label: "files",
|
|
|
|
BlockDef: wstore.BlockDef{
|
|
|
|
View: "preview",
|
|
|
|
Meta: map[string]any{"file": wavebase.GetHomeDir()},
|
2024-06-20 08:59:41 +02:00
|
|
|
},
|
2024-07-25 05:34:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Icon: "chart-simple",
|
|
|
|
Label: "chart",
|
|
|
|
BlockDef: wstore.BlockDef{
|
|
|
|
View: "plot",
|
2024-06-26 18:39:41 +02:00
|
|
|
},
|
2024-07-25 05:34:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Icon: "globe",
|
|
|
|
Label: "web",
|
|
|
|
BlockDef: wstore.BlockDef{
|
|
|
|
View: "web",
|
|
|
|
Meta: map[string]any{"url": "https://waveterm.dev/"},
|
2024-07-03 23:32:55 +02:00
|
|
|
},
|
2024-06-20 08:59:41 +02:00
|
|
|
},
|
2024-07-25 05:34:22 +02:00
|
|
|
{
|
|
|
|
Icon: "sparkles",
|
|
|
|
Label: "waveai",
|
|
|
|
BlockDef: wstore.BlockDef{
|
|
|
|
View: "waveai",
|
|
|
|
},
|
2024-07-19 01:55:04 +02:00
|
|
|
},
|
2024-06-20 08:59:41 +02:00
|
|
|
}
|
2024-07-25 05:34:22 +02:00
|
|
|
if settings.Widgets == nil {
|
|
|
|
settings.Widgets = defaultWidgets
|
|
|
|
}
|
|
|
|
if settings.TermThemes == nil {
|
|
|
|
settings.TermThemes = make(map[string]TermThemeType)
|
|
|
|
}
|
|
|
|
if _, found := settings.TermThemes["default-dark"]; !found {
|
|
|
|
settings.TermThemes["default-dark"] = DefaultTermDarkTheme
|
|
|
|
}
|
2024-06-20 08:59:41 +02:00
|
|
|
}
|