aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe <rbo@gmx.us>2024-05-16 20:20:20 +0200
committerJoe <rbo@gmx.us>2024-05-16 20:20:20 +0200
commitbdf8e0b2e16de39a7fb7f3bf8f51605d542e19c9 (patch)
tree003492335c1b93c7fae588c75f6117c7840b86fc
parentcoool (diff)
downloadhardflip-bdf8e0b2e16de39a7fb7f3bf8f51605d542e19c9.tar.gz
hardflip-bdf8e0b2e16de39a7fb7f3bf8f51605d542e19c9.tar.bz2
hardflip-bdf8e0b2e16de39a7fb7f3bf8f51605d542e19c9.tar.xz
hardflip-bdf8e0b2e16de39a7fb7f3bf8f51605d542e19c9.tar.zst
hardflip-bdf8e0b2e16de39a7fb7f3bf8f51605d542e19c9.zip
fucking great
-rw-r--r--src/c_defs.go1
-rw-r--r--src/c_init.go27
-rw-r--r--src/c_parse.go12
-rw-r--r--src/e_events.go6
-rw-r--r--src/i_ui.go28
5 files changed, 44 insertions, 30 deletions
diff --git a/src/c_defs.go b/src/c_defs.go
index 9d542fa..b2e7320 100644
--- a/src/c_defs.go
+++ b/src/c_defs.go
@@ -53,6 +53,7 @@ package main
const (
CONF_FILE_NAME = "config.yml"
+ STYLE_FILE_NAME = "colors.yml"
CONF_DIR_NAME = "hf"
DATA_DIR_NAME = "hf"
VERSION = "v0.7"
diff --git a/src/c_init.go b/src/c_init.go
index 0bc37be..58b71c5 100644
--- a/src/c_init.go
+++ b/src/c_init.go
@@ -166,6 +166,18 @@ func c_write_options(file string, opts HardOpts, load_err *[]error) {
}
}
+func c_write_styles(file string, opts HardStyle, load_err *[]error) {
+ data, err := yaml.Marshal(opts)
+ if err != nil {
+ *load_err = append(*load_err, err)
+ return
+ }
+ err = os.WriteFile(file, data, 0644)
+ if err != nil {
+ *load_err = append(*load_err, err)
+ }
+}
+
func c_get_options(dir string, load_err *[]error) HardOpts {
opts := HardOpts{}
file := dir + "/" + CONF_FILE_NAME
@@ -184,6 +196,17 @@ func c_get_options(dir string, load_err *[]error) HardOpts {
}
func c_get_styles(dir string, load_err *[]error) HardStyle {
- // TODO: here
- return DEFAULT_STYLE
+ styles := HardStyle{}
+ file := dir + "/" + STYLE_FILE_NAME
+
+ if _, err := os.Stat(file); os.IsNotExist(err) {
+ c_write_styles(file, DEFAULT_STYLE, load_err)
+ return DEFAULT_STYLE
+ }
+ styles, err := c_parse_styles(file)
+ if err != nil {
+ *load_err = append(*load_err, err)
+ return DEFAULT_STYLE
+ }
+ return styles
}
diff --git a/src/c_parse.go b/src/c_parse.go
index ce7803e..2c8cddd 100644
--- a/src/c_parse.go
+++ b/src/c_parse.go
@@ -70,6 +70,18 @@ func c_parse_opts(file string) (HardOpts, error) {
return opts, err
}
+func c_parse_styles(file string) (HardStyle, error) {
+ var styles HardStyle
+
+ yaml_file, err := os.ReadFile(file)
+ if err != nil {
+ return styles, err
+ }
+ err = yaml.Unmarshal(yaml_file, &styles)
+ return styles, err
+}
+
+
func c_read_yaml_file(file string) (*HostNode, error) {
var host HostNode
yaml_file, err := os.ReadFile(file)
diff --git a/src/e_events.go b/src/e_events.go
index 342b871..2889053 100644
--- a/src/e_events.go
+++ b/src/e_events.go
@@ -183,6 +183,12 @@ func e_reload_data(data *HardData) {
} else {
data.opts = c_get_options(conf_dir, &data.load_err)
}
+ if conf_dir == "" {
+ data.colors = DEFAULT_STYLE
+ } else {
+ data.colors = c_get_styles(conf_dir, &data.load_err)
+ }
+ i_init_styles(&data.ui, data.colors)
data.data_dir = c_get_data_dir(&data.ui)
if len(data.data_dir) == 0 {
return
diff --git a/src/i_ui.go b/src/i_ui.go
index f34d9ad..c639e39 100644
--- a/src/i_ui.go
+++ b/src/i_ui.go
@@ -756,34 +756,6 @@ func i_init_styles(ui *HardUI, styles HardStyle) {
ui.style[i] = tmp.Foreground(tcell.ColorReset)
}
}
-
- // ui.style[DEF_STYLE] = tcell.StyleDefault.
- // Background(tcell.ColorReset).
- // Foreground(tcell.ColorReset)
- // ui.style[DIR_STYLE] = tcell.StyleDefault.
- // Background(tcell.ColorReset).
- // Foreground(tcell.ColorBlue).Dim(true).Bold(true)
- // ui.style[BOX_STYLE] = tcell.StyleDefault.
- // Background(tcell.ColorReset).
- // Foreground(tcell.ColorReset)
- // ui.style[HEAD_STYLE] = tcell.StyleDefault.
- // Background(tcell.ColorReset).
- // Foreground(tcell.ColorReset)
- // ui.style[ERR_STYLE] = tcell.StyleDefault.
- // Background(tcell.ColorReset).
- // Foreground(tcell.ColorRed).Dim(true)
- // ui.style[TITLE_STYLE] = tcell.StyleDefault.
- // Background(tcell.ColorReset).
- // Foreground(tcell.ColorBlue).Dim(true).Bold(true)
- // ui.style[BOT_STYLE] = tcell.StyleDefault.
- // Background(tcell.ColorReset).
- // Foreground(tcell.ColorBlue).Dim(true)
- // ui.style[YANK_STYLE] = tcell.StyleDefault.
- // Background(tcell.ColorReset).
- // Foreground(tcell.ColorYellow).Dim(true).Bold(true)
- // ui.style[MOVE_STYLE] = tcell.StyleDefault.
- // Background(tcell.ColorReset).
- // Foreground(tcell.ColorRed).Dim(true).Bold(true)
}
type key_event_mode_func func(*HardData, *HardUI, tcell.EventKey) bool