fix: some colors not readable in light mode (#264)

This commit is contained in:
三咲雅 · Misaki Masa 2023-10-13 18:49:24 +08:00 committed by GitHub
parent 4b71668742
commit 29e313640b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 209 additions and 256 deletions

View file

@ -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" }
[preview]
hovered = { underline = true }
syntect_theme = "~/.config/bat/themes/Catppuccin-macchiato.tmTheme"
# : Select {{{
[select]
border = { fg = "blue" }
active = { fg = "magenta" }
inactive = {}
# : }}}
# : Tasks {{{
[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" }
# : }}}

View file

@ -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<Pattern>,

View file

@ -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,
}

View file

@ -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,
}

View file

@ -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,
}

View file

@ -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::*;

View file

@ -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,
}

View file

@ -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,
}

View file

@ -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,
}

View file

@ -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)]
struct Status {
pub separator_open: String,
pub separator_close: String,
pub separator_style: Style,
// 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 Input {
pub border: Style,
pub title: Style,
pub value: Style,
pub selected: Style,
}
#[derive(Deserialize, Serialize)]
pub struct Select {
pub border: Style,
pub active: Style,
pub inactive: Style,
}
#[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,
}
#[derive(Deserialize, Serialize)]
pub struct Theme {
// Status
pub status: Status,
// Manager
pub tabs: Tabs,
pub files: Files,
pub marker: Marker,
pub preview: Preview,
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<Filetype>,
#[serde(deserialize_with = "Icon::deserialize", skip_serializing)]
pub icons: Vec<Icon>,
// Input
pub input: Input,
// Select
pub select: Select,
// Tasks
pub tasks: Tasks,
// Which
pub which: Which,
// Help
pub help: Help,
}
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
}

View file

@ -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,
}

View file

@ -14,7 +14,7 @@ pub fn highlighter() -> (&'static SyntaxSet, &'static Theme) {
let theme = SYNTECT_THEME.get_or_init(|| {
let from_file = || -> Result<Theme> {
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())

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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