diff --git a/colors.v b/colors.v index f4bd249d..d5c3d441 100644 --- a/colors.v +++ b/colors.v @@ -5,7 +5,6 @@ import tauraamui.bobatea as tea // TODO(tauraamui): consolidate all used colors into a core palette/swatch set // and alias reference off of that only in the places/models they are used with // alternative names, instead of here. This file is getting messy and out of hand. -pub const theme_bg_color = matte_black_bg_color pub const matte_black_bg_color = tea.Color{ 20, 20, 20 } pub const petal_pink_color = tea.Color{ 245, 191, 243 } @@ -21,11 +20,11 @@ pub const status_purple = tea.Color{ 130, 144, 250 } pub const error_color = petal_red_color +// pub const matte_black_fg_color = tea.Color.ansi(232) pub const matte_white_fg_color = tea.Color{ 230, 230, 230 } pub const bright_off_white_fg_color = tea.Color{ 255, 255, 255 } -// pub const bright_red_fg_color = tea.Color{ 245, 42, 42 } pub const subtle_text_fg_color = tea.Color.ansi(249) pub const help_fg_color = tea.Color.ansi(241) @@ -34,7 +33,6 @@ pub const selected_highlight_bg_color = tea.Color.ansi(239) pub const subtle_border_fg_color = petal_pink_color - pub const status_bar_bg_color = tea.Color.ansi(234) pub const status_file_name_bg_color = tea.Color{ 86, 86, 86 } pub const status_branch_name_bg_color = tea.Color{ 154, 119, 209 } diff --git a/config.v b/config.v new file mode 100644 index 00000000..a72d0a06 --- /dev/null +++ b/config.v @@ -0,0 +1,39 @@ +module cfg + +import theme + +pub const light_theme_name = theme.light_theme_name +pub const dark_theme_name = theme.dark_theme_name + +pub struct Config{ +pub: + theme theme.Theme + leader_key string +} + +@[params] +pub struct ConfigOptions { +pub: + load_from_path ?string = "~/.config/petal/petal.cfg" +} + +pub fn Config.new(opts ConfigOptions) Config { + if path_to_load := opts.load_from_path { + assert path_to_load.len > 0 + // do some loading from file here + // return Config{} + } + + return Config{ + theme: theme.dark_theme + leader_key: ";" + } +} + +pub fn (c Config) set_theme(name string) Config { + return Config{ + ...c + theme: if name == "dark" { theme.dark_theme } else { theme.light_theme } + } +} + diff --git a/main.v b/main.v index 5e50dd90..314eee5f 100644 --- a/main.v +++ b/main.v @@ -1,10 +1,13 @@ module main import tauraamui.bobatea as tea -import palette +import cfg fn main() { - mut petal_model := PetalModel.new(palette.theme_bg_color, palette.fg_color(palette.theme_bg_color)) + // config := cfg.Config.new(load_from_path: none).set_theme(cfg.light_theme_name) + config := cfg.Config.new(load_from_path: none) + + mut petal_model := PetalModel.new(config) mut app := tea.new_program(mut petal_model) petal_model.app_send = app.send app.run() or { panic('something went wrong! ${err}') } diff --git a/petal.v b/petal.v index 3581d5b3..a972e59d 100644 --- a/petal.v +++ b/petal.v @@ -2,14 +2,17 @@ module main import os import tauraamui.bobatea as tea +import cfg +import theme +import palette const dot = '•' struct PetalModel { mut: app_send ?fn (tea.Msg) - theme_fg_color ?tea.Color - theme_bg_color ?tea.Color + config cfg.Config @[required] + theme theme.Theme first_frame bool active_screen DebuggableModel // all screens are debuggable to help with live, well... debugging clear_screen_next_frame bool @@ -18,10 +21,10 @@ mut: last_resize_height int } -fn PetalModel.new(theme_bg_color ?tea.Color, theme_fg_color ?tea.Color) PetalModel { +fn PetalModel.new(config cfg.Config) PetalModel { return PetalModel{ - theme_bg_color: theme_bg_color - theme_fg_color: theme_fg_color + config: config + theme: config.theme first_frame: true active_screen: SplashScreenModel.new() } @@ -99,13 +102,9 @@ fn (mut m PetalModel) update(msg tea.Msg) (tea.Model, ?tea.Cmd) { fn (mut m PetalModel) view(mut ctx tea.Context) { if m.first_frame { - if fg_color := m.theme_fg_color { - ctx.set_default_fg_color(fg_color) - } - - if bg_color := m.theme_bg_color { - ctx.set_default_bg_color(bg_color) - } + bg_color := m.theme.bg_color + ctx.set_default_fg_color(palette.fg_color(bg_color)) + ctx.set_default_bg_color(bg_color) m.first_frame = false } mut screen := m.active_screen diff --git a/theme.v b/theme.v new file mode 100644 index 00000000..a6d2cd4c --- /dev/null +++ b/theme.v @@ -0,0 +1,31 @@ +module theme + +import tauraamui.bobatea as tea +import palette + +pub const dark_theme_name = "dark" +pub const light_theme_name = "light" + +pub struct Theme{ +pub: + name string @[required] + bg_color tea.Color @[required] + fg_color tea.Color + active_split_divider_color tea.Color @[required] + inactive_split_divider_color tea.Color @[required] +} + +pub const dark_theme = Theme{ + name: "dark" + bg_color: palette.matte_black_bg_color + active_split_divider_color: palette.petal_pink_color + inactive_split_divider_color: palette.status_bar_bg_color +} + +pub const light_theme = Theme{ + name: "light" + bg_color: palette.matte_white_fg_color + active_split_divider_color: palette.petal_pink_color + inactive_split_divider_color: palette.status_bar_bg_color +} +