From 03f70cbe520c4b82d64ee4e0796c5203ae4573a4 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Fri, 13 Oct 2023 08:16:45 +0800 Subject: [PATCH] fix: some colors not readable in light mode --- config/preset/theme.toml | 152 +++++++++++++++------------- config/src/theme/filetype.rs | 4 +- config/src/theme/help.rs | 13 --- config/src/theme/input.rs | 11 -- config/src/theme/manager.rs | 32 ------ config/src/theme/mod.rs | 14 --- config/src/theme/select.rs | 10 -- config/src/theme/status.rs | 32 ------ config/src/theme/tasks.rs | 10 -- config/src/theme/theme.rs | 132 +++++++++++++++++++----- config/src/theme/which.rs | 14 --- core/src/highlighter.rs | 2 +- plugin/preset/components/folder.lua | 15 +-- plugin/preset/components/header.lua | 10 +- plugin/preset/components/status.lua | 12 +-- plugin/preset/ui.lua | 2 +- 16 files changed, 209 insertions(+), 256 deletions(-) delete mode 100644 config/src/theme/help.rs delete mode 100644 config/src/theme/input.rs delete mode 100644 config/src/theme/manager.rs delete mode 100644 config/src/theme/select.rs delete mode 100644 config/src/theme/status.rs delete mode 100644 config/src/theme/tasks.rs delete mode 100644 config/src/theme/which.rs diff --git a/config/preset/theme.toml b/config/preset/theme.toml index 7d76ba648..b665fb211 100644 --- a/config/preset/theme.toml +++ b/config/preset/theme.toml @@ -1,10 +1,40 @@ # vim:fileencoding=utf-8:foldmethod=marker +# : Manager {{{ + +[manager] +cwd = { fg = "cyan" } + +# Hovered +hovered = { fg = "#000000", bg = "blue" } +preview_hovered = { underline = true } + +# Find +find_keyword = { fg = "yellow", italic = true } +find_position = { fg = "magenta", bg = "reset", italic = true } + +# Marker +marker_selected = { fg = "lightgreen", bg = "lightgreen" } +marker_copied = { fg = "lightyellow", bg = "lightyellow" } +marker_cut = { fg = "lightred", bg = "lightred" } + +# Tab +tab_active = { fg = "black", bg = "blue" } +tab_inactive = { bg = "darkgray" } +tab_width = 1 + +# Highlighting +syntect_theme = "" + +# : }}} + + # : Status {{{ [status] -fancy = { bg = "darkgray" } -separator = { opening = "", closing = "" } +separator_open = "" +separator_close = "" +separator_style = { fg = "darkgray", bg = "darkgray" } # Mode mode_normal = { fg = "black", bg = "blue", bold = true } @@ -26,24 +56,58 @@ permissions_s = { fg = "darkgray" } # : }}} -# : Manager {{{ +# : Input {{{ -[tabs] -active = { fg = "black", bg = "blue" } -inactive = { bg = "darkgray" } -max_width = 1 +[input] +border = { fg = "blue" } +title = {} +value = {} +selected = { fg = "black", bg = "white" } + +# : }}} -[files] -hovered = { fg = "#000000", bg = "blue" } -[marker] -selected = { fg = "lightgreen", bg = "lightgreen" } -copied = { fg = "lightyellow", bg = "lightyellow" } -cut = { fg = "lightred", bg = "lightred" } +# : Select {{{ + +[select] +border = { fg = "blue" } +active = { fg = "magenta" } +inactive = {} + +# : }}} + + +# : Tasks {{{ -[preview] -hovered = { underline = true } -syntect_theme = "~/.config/bat/themes/Catppuccin-macchiato.tmTheme" +[tasks] +border = { fg = "blue" } +title = {} +hovered = { underline = true } + +# : }}} + + +# : Which {{{ + +[which] +mask = { bg = "black" } +cand = { fg = "lightcyan" } +rest = { fg = "darkgray" } +desc = { fg = "magenta" } +separator = "  " +separator_style = { fg = "darkgray" } + +# : }}} + + +# : Help {{{ + +[help] +on = { fg = "magenta" } +exec = { fg = "cyan" } +desc = { fg = "gray" } +hovered = { bg = "darkgray", bold = true } +footer = { fg = "black", bg = "white" } # : }}} @@ -169,59 +233,3 @@ rules = [ "*/" = "" # : }}} - - -# : Input {{{ - -[input] -border = { fg = "blue" } -title = { fg = "white" } -value = { fg = "white" } -selected = { bg = "black" } - -# : }}} - - -# : Select {{{ - -[select] -border = { fg = "blue" } -active = { fg = "magenta" } -inactive = { fg = "white" } - -# : }}} - - -# : Tasks {{{ - -[tasks] -border = { fg = "blue" } -title = { fg = "white" } -hovered = { underline = true } - -# : }}} - - -# : Which {{{ - -[which] -mask = { bg = "black" } -cand = { fg = "lightcyan" } -rest = { fg = "darkgray" } -desc = { fg = "magenta" } -separator = "  " -separator_style = { fg = "darkgray" } - -# : }}} - - -# : Help {{{ - -[help] -on = { fg = "magenta" } -exec = { fg = "cyan" } -desc = { fg = "gray" } -hovered = { bg = "darkgray", bold = true } -footer = { fg = "black", bg = "white" } - -# : }}} diff --git a/config/src/theme/filetype.rs b/config/src/theme/filetype.rs index 2d5474c16..6662901ec 100644 --- a/config/src/theme/filetype.rs +++ b/config/src/theme/filetype.rs @@ -2,8 +2,8 @@ use std::path::Path; use serde::{Deserialize, Deserializer}; -use super::Style; -use crate::{theme::{Color, StyleShadow}, Pattern}; +use super::{Color, Style, StyleShadow}; +use crate::Pattern; pub struct Filetype { pub name: Option, diff --git a/config/src/theme/help.rs b/config/src/theme/help.rs deleted file mode 100644 index 2e6697aad..000000000 --- a/config/src/theme/help.rs +++ /dev/null @@ -1,13 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use super::Style; - -#[derive(Deserialize, Serialize)] -pub struct Help { - pub on: Style, - pub exec: Style, - pub desc: Style, - - pub hovered: Style, - pub footer: Style, -} diff --git a/config/src/theme/input.rs b/config/src/theme/input.rs deleted file mode 100644 index e252e2fee..000000000 --- a/config/src/theme/input.rs +++ /dev/null @@ -1,11 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use super::Style; - -#[derive(Deserialize, Serialize)] -pub struct Input { - pub border: Style, - pub title: Style, - pub value: Style, - pub selected: Style, -} diff --git a/config/src/theme/manager.rs b/config/src/theme/manager.rs deleted file mode 100644 index 15c582596..000000000 --- a/config/src/theme/manager.rs +++ /dev/null @@ -1,32 +0,0 @@ -use std::path::PathBuf; - -use serde::{Deserialize, Serialize}; -use validator::Validate; - -use super::Style; - -#[derive(Deserialize, Serialize, Validate)] -pub struct Tabs { - pub active: Style, - pub inactive: Style, - #[validate(range(min = 1, message = "Must be greater than 0"))] - pub max_width: u8, -} - -#[derive(Deserialize, Serialize)] -pub struct Files { - pub hovered: Style, -} - -#[derive(Deserialize, Serialize)] -pub struct Marker { - pub selected: Style, - pub copied: Style, - pub cut: Style, -} - -#[derive(Deserialize, Serialize)] -pub struct Preview { - pub hovered: Style, - pub syntect_theme: PathBuf, -} diff --git a/config/src/theme/mod.rs b/config/src/theme/mod.rs index 2e2a69671..ed9aa3dfa 100644 --- a/config/src/theme/mod.rs +++ b/config/src/theme/mod.rs @@ -1,25 +1,11 @@ mod color; mod filetype; -mod help; mod icon; -mod input; -mod manager; -mod select; -mod status; mod style; -mod tasks; mod theme; -mod which; pub use color::*; pub use filetype::*; -pub use help::*; pub use icon::*; -pub use input::*; -pub use manager::*; -pub use select::*; -pub use status::*; pub use style::*; -pub use tasks::*; pub use theme::*; -pub use which::*; diff --git a/config/src/theme/select.rs b/config/src/theme/select.rs deleted file mode 100644 index 856f239e5..000000000 --- a/config/src/theme/select.rs +++ /dev/null @@ -1,10 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use super::Style; - -#[derive(Deserialize, Serialize)] -pub struct Select { - pub border: Style, - pub active: Style, - pub inactive: Style, -} diff --git a/config/src/theme/status.rs b/config/src/theme/status.rs deleted file mode 100644 index c7e5dd102..000000000 --- a/config/src/theme/status.rs +++ /dev/null @@ -1,32 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use super::Style; - -#[derive(Deserialize, Serialize)] -pub struct Status { - pub fancy: Style, - pub separator: StatusSeparator, - - // Mode - pub mode_normal: Style, - pub mode_select: Style, - pub mode_unset: Style, - - // Progress - pub progress_label: Style, - pub progress_normal: Style, - pub progress_error: Style, - - // Permissions - pub permissions_t: Style, - pub permissions_r: Style, - pub permissions_w: Style, - pub permissions_x: Style, - pub permissions_s: Style, -} - -#[derive(Deserialize, Serialize)] -pub struct StatusSeparator { - pub opening: String, - pub closing: String, -} diff --git a/config/src/theme/tasks.rs b/config/src/theme/tasks.rs deleted file mode 100644 index 96198e798..000000000 --- a/config/src/theme/tasks.rs +++ /dev/null @@ -1,10 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use super::Style; - -#[derive(Deserialize, Serialize)] -pub struct Tasks { - pub border: Style, - pub title: Style, - pub hovered: Style, -} diff --git a/config/src/theme/theme.rs b/config/src/theme/theme.rs index ce912ff6b..74a2a3870 100644 --- a/config/src/theme/theme.rs +++ b/config/src/theme/theme.rs @@ -1,50 +1,130 @@ +use std::path::PathBuf; + use serde::{Deserialize, Serialize}; use shared::expand_path; use validator::Validate; -use super::{Files, Filetype, Help, Icon, Input, Marker, Preview, Select, Status, Tabs, Tasks, Which}; +use super::{Filetype, Icon, Style}; use crate::{validation::check_validation, MERGED_THEME}; +#[derive(Deserialize, Serialize, Validate)] +pub struct Manager { + cwd: Style, + + // Hovered + hovered: Style, + preview_hovered: Style, + + // Find + find_keyword: Style, + find_position: Style, + + // Marker + marker_selected: Style, + marker_copied: Style, + marker_cut: Style, + + // Tab + tab_active: Style, + tab_inactive: Style, + #[validate(range(min = 1, message = "Must be greater than 0"))] + tab_width: u8, + + // Highlighting + pub syntect_theme: PathBuf, +} + #[derive(Deserialize, Serialize)] -pub struct Theme { - // Status - pub status: Status, +struct Status { + pub separator_open: String, + pub separator_close: String, + pub separator_style: Style, - // Manager - pub tabs: Tabs, - pub files: Files, - pub marker: Marker, - pub preview: Preview, + // Mode + pub mode_normal: Style, + pub mode_select: Style, + pub mode_unset: Style, - // File-specific styles - #[serde(rename = "filetype", deserialize_with = "Filetype::deserialize", skip_serializing)] - pub filetypes: Vec, - #[serde(deserialize_with = "Icon::deserialize", skip_serializing)] - pub icons: Vec, + // Progress + pub progress_label: Style, + pub progress_normal: Style, + pub progress_error: Style, - // Input - pub input: Input, + // Permissions + pub permissions_t: Style, + pub permissions_r: Style, + pub permissions_w: Style, + pub permissions_x: Style, + pub permissions_s: Style, +} - // Select - pub select: Select, +#[derive(Deserialize, Serialize)] +pub struct Input { + pub border: Style, + pub title: Style, + pub value: Style, + pub selected: Style, +} - // Tasks - pub tasks: Tasks, +#[derive(Deserialize, Serialize)] +pub struct Select { + pub border: Style, + pub active: Style, + pub inactive: Style, +} - // Which - pub which: Which, +#[derive(Deserialize, Serialize)] +pub struct Tasks { + pub border: Style, + pub title: Style, + pub hovered: Style, +} + +#[derive(Deserialize, Serialize)] +pub struct Which { + pub mask: Style, + pub cand: Style, + pub rest: Style, + pub desc: Style, + + pub separator: String, + pub separator_style: Style, +} + +#[derive(Deserialize, Serialize)] +pub struct Help { + pub on: Style, + pub exec: Style, + pub desc: Style, + + pub hovered: Style, + pub footer: Style, +} - // Help - pub help: Help, +#[derive(Deserialize, Serialize)] +pub struct Theme { + pub manager: Manager, + status: Status, + pub input: Input, + pub select: Select, + pub tasks: Tasks, + pub which: Which, + pub help: Help, + + // File-specific styles + #[serde(rename = "filetype", deserialize_with = "Filetype::deserialize", skip_serializing)] + pub filetypes: Vec, + #[serde(deserialize_with = "Icon::deserialize", skip_serializing)] + pub icons: Vec, } impl Default for Theme { fn default() -> Self { let mut theme: Self = toml::from_str(&MERGED_THEME).unwrap(); - check_validation(theme.tabs.validate()); + check_validation(theme.manager.validate()); - theme.preview.syntect_theme = expand_path(&theme.preview.syntect_theme); + theme.manager.syntect_theme = expand_path(&theme.manager.syntect_theme); theme } diff --git a/config/src/theme/which.rs b/config/src/theme/which.rs deleted file mode 100644 index 1713f9dd5..000000000 --- a/config/src/theme/which.rs +++ /dev/null @@ -1,14 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use super::Style; - -#[derive(Deserialize, Serialize)] -pub struct Which { - pub mask: Style, - pub cand: Style, - pub rest: Style, - pub desc: Style, - - pub separator: String, - pub separator_style: Style, -} diff --git a/core/src/highlighter.rs b/core/src/highlighter.rs index 5ba036fcb..1b91fdfe4 100644 --- a/core/src/highlighter.rs +++ b/core/src/highlighter.rs @@ -14,7 +14,7 @@ pub fn highlighter() -> (&'static SyntaxSet, &'static Theme) { let theme = SYNTECT_THEME.get_or_init(|| { let from_file = || -> Result { - let file = File::open(&THEME.preview.syntect_theme)?; + let file = File::open(&THEME.manager.syntect_theme)?; Ok(ThemeSet::load_from_reader(&mut BufReader::new(file))?) }; from_file().unwrap_or_else(|_| ThemeSet::load_defaults().themes["base16-ocean.dark"].clone()) diff --git a/plugin/preset/components/folder.lua b/plugin/preset/components/folder.lua index 42606bb30..408692234 100644 --- a/plugin/preset/components/folder.lua +++ b/plugin/preset/components/folder.lua @@ -34,11 +34,11 @@ function Folder:markers(area, markers) ) if last[3] == 1 then - p = p:style(THEME.marker.copied) + p = p:style(THEME.manager.marker_copied) elseif last[3] == 2 then - p = p:style(THEME.marker.cut) + p = p:style(THEME.manager.marker_cut) elseif last[3] == 3 then - p = p:style(THEME.marker.selected) + p = p:style(THEME.manager.marker_selected) end elements[#elements + 1] = p end @@ -79,7 +79,8 @@ function Folder:highlighted_name(file) local found = file:found() if found ~= nil then - spans[#spans + 1] = ui.Span(string.format(" [%d/%d]", found[1] + 1, found[2])):fg("#ffff32"):italic() + spans[#spans + 1] = ui.Span(" ") + spans[#spans + 1] = ui.Span(string.format("[%d/%d]", found[1] + 1, found[2])):style(THEME.manager.find_position) end return spans end @@ -94,7 +95,7 @@ function Folder:parent(area) for _, f in ipairs(folder.window) do local item = ui.ListItem(" " .. f:icon() .. " " .. f.name .. " ") if f:is_hovered() then - item = item:style(THEME.files.hovered) + item = item:style(THEME.manager.hovered) else item = item:style(f:style()) end @@ -114,7 +115,7 @@ function Folder:current(area) -- Highlight hovered file local item = ui.ListItem(ui.Line { ui.Span(" " .. f:icon() .. " "), table.unpack(name) }) if f:is_hovered() then - item = item:style(THEME.files.hovered) + item = item:style(THEME.manager.hovered) else item = item:style(f:style()) end @@ -142,7 +143,7 @@ function Folder:preview(area) for _, f in ipairs(folder.window) do local item = ui.ListItem(" " .. f:icon() .. " " .. f.name .. " ") if f:is_hovered() then - item = item:style(THEME.preview.hovered) + item = item:style(THEME.manager.preview_hovered) else item = item:style(f:style()) end diff --git a/plugin/preset/components/header.lua b/plugin/preset/components/header.lua index 57dd59653..08342425b 100644 --- a/plugin/preset/components/header.lua +++ b/plugin/preset/components/header.lua @@ -9,20 +9,20 @@ function Header:cwd() else span = ui.Span(string.format("%s (search: %s)", utils.readable_path(tostring(cwd)), cwd.frag)) end - return span:fg("cyan") + return span:style(THEME.manager.cwd) end function Header:tabs() local spans = {} for i = 1, #cx.tabs do local text = i - if THEME.tabs.max_width > 2 then - text = utils.truncate(text .. " " .. cx.tabs[i]:name(), THEME.tabs.max_width) + if THEME.manager.tab_width > 2 then + text = utils.truncate(text .. " " .. cx.tabs[i]:name(), THEME.manager.tab_width) end if i == cx.tabs.idx + 1 then - spans[#spans + 1] = ui.Span(" " .. text .. " "):style(THEME.tabs.active) + spans[#spans + 1] = ui.Span(" " .. text .. " "):style(THEME.manager.tab_active) else - spans[#spans + 1] = ui.Span(" " .. text .. " "):style(THEME.tabs.inactive) + spans[#spans + 1] = ui.Span(" " .. text .. " "):style(THEME.manager.tab_inactive) end end return ui.Line(spans) diff --git a/plugin/preset/components/status.lua b/plugin/preset/components/status.lua index 04b3a964c..115ccb4ac 100644 --- a/plugin/preset/components/status.lua +++ b/plugin/preset/components/status.lua @@ -18,7 +18,7 @@ function Status:mode() local style = self.style() return ui.Line { - ui.Span(THEME.status.separator.opening):fg(style.bg), + ui.Span(THEME.status.separator_open):fg(style.bg), ui.Span(" " .. mode .. " "):style(style), } end @@ -31,8 +31,8 @@ function Status:size() local style = self.style() return ui.Line { - ui.Span(" " .. utils.readable_size(h.length) .. " "):fg(style.bg):bg(THEME.status.fancy.bg), - ui.Span(THEME.status.separator.closing):fg(THEME.status.fancy.bg), + ui.Span(" " .. utils.readable_size(h.length) .. " "):fg(style.bg):bg(THEME.status.separator_style.bg), + ui.Span(THEME.status.separator_close):fg(THEME.status.separator_style.fg), } end @@ -85,8 +85,8 @@ function Status:percentage() local style = self.style() return ui.Line { - ui.Span(" " .. THEME.status.separator.opening):fg(THEME.status.fancy.bg), - ui.Span(percent):fg(style.bg):bg(THEME.status.fancy.bg), + ui.Span(" " .. THEME.status.separator_open):fg(THEME.status.separator_style.fg), + ui.Span(percent):fg(style.bg):bg(THEME.status.separator_style.bg), } end @@ -97,7 +97,7 @@ function Status:position() local style = self.style() return ui.Line { ui.Span(string.format(" %2d/%-2d ", cursor + 1, length)):style(style), - ui.Span(THEME.status.separator.closing):fg(style.bg), + ui.Span(THEME.status.separator_close):fg(style.bg), } end diff --git a/plugin/preset/ui.lua b/plugin/preset/ui.lua index 5b4ccf7bb..6f208dce6 100644 --- a/plugin/preset/ui.lua +++ b/plugin/preset/ui.lua @@ -22,7 +22,7 @@ function ui.highlight_ranges(s, ranges) spans[#spans + 1] = ui.Span(s:sub(last + 1, r[1])) end -- TODO: use a customable style - spans[#spans + 1] = ui.Span(s:sub(r[1] + 1, r[2])):fg("yellow"):italic() + spans[#spans + 1] = ui.Span(s:sub(r[1] + 1, r[2])):style(THEME.manager.find_keyword) last = r[2] end if last < #s then