Skip to content

Commit

Permalink
fix: collect and fix all hard coded themes and color (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Song-Nop authored Oct 12, 2023
1 parent 774f8bc commit d032b68
Show file tree
Hide file tree
Showing 19 changed files with 274 additions and 103 deletions.
14 changes: 9 additions & 5 deletions app/src/help/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::Ctx;

use ratatui::{layout::{self, Constraint}, prelude::{Buffer, Direction, Rect}, style::{Color, Style, Stylize}, widgets::{List, ListItem, Widget}};
use config::THEME;
use ratatui::{layout::{self, Constraint}, prelude::{Buffer, Direction, Rect}, widgets::{List, ListItem, Widget}};

pub(super) struct Bindings<'a> {
cx: &'a Ctx,
Expand All @@ -17,19 +18,22 @@ impl Widget for Bindings<'_> {
return;
}

// On
let col1 = bindings
.iter()
.map(|c| ListItem::new(c.on()).style(Style::new().fg(Color::Yellow)))
.map(|c| ListItem::new(c.on()).style(THEME.help.on.into()))
.collect::<Vec<_>>();

// Exec
let col2 = bindings
.iter()
.map(|c| ListItem::new(c.exec()).style(Style::new().fg(Color::Cyan)))
.map(|c| ListItem::new(c.exec()).style(THEME.help.exec.into()))
.collect::<Vec<_>>();

// Desc
let col3 = bindings
.iter()
.map(|c| ListItem::new(if let Some(ref desc) = c.desc { desc } else { "-" }))
.map(|c| ListItem::new(c.desc.as_deref().unwrap_or("-")).style(THEME.help.desc.into()))
.collect::<Vec<_>>();

let chunks = layout::Layout::new()
Expand All @@ -40,7 +44,7 @@ impl Widget for Bindings<'_> {
let cursor = self.cx.help.rel_cursor() as u16;
buf.set_style(
Rect { x: area.x, y: area.y + cursor, width: area.width, height: 1 },
Style::new().bg(Color::Black).bold(),
THEME.help.hovered.into(),
);

List::new(col1).render(chunks[0], buf);
Expand Down
5 changes: 3 additions & 2 deletions app/src/help/layout.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::Ctx;

use ratatui::{buffer::Buffer, layout::{self, Rect}, prelude::{Constraint, Direction}, style::{Color, Style}, widgets::{Clear, Paragraph, Widget}};
use config::THEME;
use ratatui::{buffer::Buffer, layout::{self, Rect}, prelude::{Constraint, Direction}, widgets::{Clear, Paragraph, Widget}};

use super::Bindings;

Expand All @@ -23,7 +24,7 @@ impl<'a> Widget for Layout<'a> {

let help = &self.cx.help;
Paragraph::new(help.keyword().unwrap_or_else(|| format!("{}.help", help.layer())))
.style(Style::new().fg(Color::Black).bg(Color::White))
.style(THEME.help.footer.into())
.render(chunks[1], buf);

Bindings::new(self.cx).render(chunks[0], buf);
Expand Down
11 changes: 6 additions & 5 deletions app/src/input/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use core::{input::InputMode, Ctx};
use std::ops::Range;

use ansi_to_tui::IntoText;
use ratatui::{buffer::Buffer, layout::Rect, style::{Color, Style}, text::{Line, Text}, widgets::{Block, BorderType, Borders, Clear, Paragraph, Widget}};
use config::THEME;
use ratatui::{buffer::Buffer, layout::Rect, text::{Line, Text}, widgets::{Block, BorderType, Borders, Clear, Paragraph, Widget}};
use shared::Term;

pub(crate) struct Input<'a> {
Expand Down Expand Up @@ -30,14 +31,14 @@ impl<'a> Widget for Input<'a> {
Block::new()
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::new().fg(Color::Blue))
.border_style(THEME.input.border.into())
.title({
let mut line = Line::from(input.title());
line.patch_style(Style::new().fg(Color::White));
line.patch_style(THEME.input.title.into());
line
}),
)
.style(Style::new().fg(Color::White))
.style(THEME.input.value.into())
.render(area, buf);

if let Some(Range { start, end }) = input.selected() {
Expand All @@ -46,7 +47,7 @@ impl<'a> Widget for Input<'a> {

buf.set_style(
Rect { x, y, width: (end - start).min(win.width - x), height: 1.min(win.height - y) },
Style::new().bg(Color::Rgb(72, 77, 102)),
THEME.input.selected.into(),
)
}

Expand Down
9 changes: 5 additions & 4 deletions app/src/select/select.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::Ctx;

use ratatui::{buffer::Buffer, layout::Rect, style::{Color, Style}, widgets::{Block, BorderType, Borders, Clear, List, ListItem, Widget}};
use config::THEME;
use ratatui::{buffer::Buffer, layout::Rect, widgets::{Block, BorderType, Borders, Clear, List, ListItem, Widget}};

pub(crate) struct Select<'a> {
cx: &'a Ctx,
Expand All @@ -21,10 +22,10 @@ impl<'a> Widget for Select<'a> {
.enumerate()
.map(|(i, v)| {
if i != select.rel_cursor() {
return ListItem::new(format!(" {v}"));
return ListItem::new(format!(" {v}")).style(THEME.select.inactive.into());
}

ListItem::new(format!(" {v}")).style(Style::new().fg(Color::Magenta))
ListItem::new(format!(" {v}")).style(THEME.select.active.into())
})
.collect::<Vec<_>>();

Expand All @@ -35,7 +36,7 @@ impl<'a> Widget for Select<'a> {
.title(select.title())
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::new().fg(Color::Blue)),
.border_style(THEME.select.border.into()),
)
.render(area, buf);
}
Expand Down
13 changes: 9 additions & 4 deletions app/src/tasks/layout.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::{tasks::TASKS_PERCENT, Ctx};

use ratatui::{buffer::Buffer, layout::{self, Alignment, Constraint, Direction, Rect}, style::{Color, Modifier, Style}, widgets::{Block, BorderType, Borders, List, ListItem, Padding, Widget}};
use config::THEME;
use ratatui::{buffer::Buffer, layout::{self, Alignment, Constraint, Direction, Rect}, text::Line, widgets::{Block, BorderType, Borders, List, ListItem, Padding, Widget}};

use super::Clear;

Expand Down Expand Up @@ -38,12 +39,16 @@ impl<'a> Widget for Layout<'a> {

Clear.render(area, buf);
let block = Block::new()
.title("Tasks")
.title({
let mut line = Line::from("Tasks");
line.patch_style(THEME.tasks.title.into());
line
})
.title_alignment(Alignment::Center)
.padding(Padding::new(0, 0, 1, 1))
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::new().fg(Color::Rgb(128, 174, 250)));
.border_style(THEME.tasks.border.into());
block.clone().render(area, buf);

let tasks = &self.cx.tasks;
Expand All @@ -54,7 +59,7 @@ impl<'a> Widget for Layout<'a> {
.map(|(i, v)| {
let mut item = ListItem::new(v.name.clone());
if i == tasks.cursor {
item = item.style(Style::new().add_modifier(Modifier::UNDERLINED));
item = item.style(THEME.tasks.hovered.into());
}
item
})
Expand Down
5 changes: 3 additions & 2 deletions app/src/which/layout.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::Ctx;

use ratatui::{layout, prelude::{Buffer, Constraint, Direction, Rect}, style::{Color, Style}, widgets::{Block, Clear, Widget}};
use config::THEME;
use ratatui::{layout, prelude::{Buffer, Constraint, Direction, Rect}, widgets::{Block, Clear, Widget}};

use super::Side;

Expand Down Expand Up @@ -39,7 +40,7 @@ impl Widget for Which<'_> {
.split(area);

Clear.render(area, buf);
Block::new().style(Style::new().bg(Color::Rgb(47, 51, 73))).render(area, buf);
Block::new().style(THEME.which.mask.into()).render(area, buf);
Side::new(which.times, cands.0).render(chunks[0], buf);
Side::new(which.times, cands.1).render(chunks[1], buf);
Side::new(which.times, cands.2).render(chunks[2], buf);
Expand Down
20 changes: 10 additions & 10 deletions app/src/which/side.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use config::keymap::Control;
use ratatui::{prelude::{Buffer, Rect}, style::{Color, Style}, text::{Line, Span}, widgets::{Block, List, ListItem, Padding, Widget}};
use config::{keymap::Control, THEME};
use ratatui::{prelude::{Buffer, Rect}, text::{Line, Span}, widgets::{Block, List, ListItem, Padding, Widget}};

pub(super) struct Side<'a> {
times: usize,
Expand All @@ -21,19 +21,19 @@ impl Widget for Side<'_> {
// Keys
let keys = c.on[self.times..].iter().map(ToString::to_string).collect::<Vec<_>>();
spans.push(Span::raw(" ".repeat(10usize.saturating_sub(keys.join("").len()))));
spans.push(Span::styled(keys[0].clone(), Style::new().fg(Color::LightCyan)));
spans.push(Span::styled(keys[0].clone(), THEME.which.cand.into()));
spans.extend(
keys
.iter()
.skip(1)
.map(|k| Span::styled(k.to_string(), Style::new().fg(Color::DarkGray))),
keys.iter().skip(1).map(|k| Span::styled(k.to_string(), THEME.which.rest.into())),
);

// Separator
spans.push(Span::styled("  ".to_string(), Style::new().fg(Color::DarkGray)));
spans.push(Span::styled(
THEME.which.separator.to_string(),
THEME.which.separator_style.into(),
));

// Exec
spans.push(Span::styled(c.desc_or_exec(), Style::new().fg(Color::Magenta)));
// Desc / Exec
spans.push(Span::styled(c.desc_or_exec(), THEME.which.desc.into()));

ListItem::new(Line::from(spans))
})
Expand Down
130 changes: 100 additions & 30 deletions config/preset/theme.toml
Original file line number Diff line number Diff line change
@@ -1,64 +1,76 @@
[tabs]
active = { fg = "#1E2031", bg = "#80AEFA" }
inactive = { fg = "#C8D3F8", bg = "#484D66" }
max_width = 1
# vim:fileencoding=utf-8:foldmethod=marker

# : Status {{{

[status]
plain = { fg = "#FFFFFF" }
fancy = { bg = "#45475D" }
fancy = { bg = "darkgray" }
separator = { opening = "", closing = "" }

# Mode
mode_normal = { fg = "#181827", bg = "#7DB5FF", bold = true }
mode_select = { fg = "#1E1E30", bg = "#D2A4FE", bold = true }
mode_unset = { fg = "#1E1E30", bg = "#FFAF80", bold = true }
mode_normal = { fg = "black", bg = "blue", bold = true }
mode_select = { fg = "black", bg = "green", bold = true }
mode_unset = { fg = "black", bg = "magenta", bold = true }

# Progress
progress_label = { fg = "#FFFFFF", bold = true }
progress_normal = { fg = "#FFA577", bg = "#484D66" }
progress_error = { fg = "#FF84A9", bg = "#484D66" }

# Permissions
permissions_t = { fg = "#97DC8D" }
permissions_r = { fg = "#F3D398" }
permissions_w = { fg = "#FA7F94" }
permissions_x = { fg = "#7AD9E5" }
permissions_s = { fg = "#6D738F" }
permissions_t = { fg = "lightgreen" }
permissions_r = { fg = "lightyellow" }
permissions_w = { fg = "lightred" }
permissions_x = { fg = "lightcyan" }
permissions_s = { fg = "darkgray" }

# : }}}


# : Manager {{{

[tabs]
active = { fg = "black", bg = "blue" }
inactive = { bg = "darkgray" }
max_width = 1

[files]
hovered = { fg = "#1E2031", bg = "#80AEFA" }
hovered = { fg = "#000000", bg = "blue" }

[marker]
selected = { fg = "#97DC8D", bg = "#97DC8D" }
copied = { fg = "#F3D398", bg = "#F3D398" }
cut = { fg = "#FF84A9", bg = "#FF84A9" }
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"

# : }}}


# : File-specific styles {{{

[filetype]

rules = [
# Images
{ mime = "image/*", fg = "#7AD9E5" },
{ mime = "image/*", fg = "cyan" },

# Videos
{ mime = "video/*", fg = "#F3D398" },
{ mime = "audio/*", fg = "#F3D398" },
{ mime = "video/*", fg = "yellow" },
{ mime = "audio/*", fg = "yellow" },

# Archives
{ mime = "application/zip", fg = "#CD9EFC" },
{ mime = "application/gzip", fg = "#CD9EFC" },
{ mime = "application/x-tar", fg = "#CD9EFC" },
{ mime = "application/x-bzip", fg = "#CD9EFC" },
{ mime = "application/x-bzip2", fg = "#CD9EFC" },
{ mime = "application/x-7z-compressed", fg = "#CD9EFC" },
{ mime = "application/x-rar", fg = "#CD9EFC" },
{ mime = "application/zip", fg = "magenta" },
{ mime = "application/gzip", fg = "magenta" },
{ mime = "application/x-tar", fg = "magenta" },
{ mime = "application/x-bzip", fg = "magenta" },
{ mime = "application/x-bzip2", fg = "magenta" },
{ mime = "application/x-7z-compressed", fg = "magenta" },
{ mime = "application/x-rar", fg = "magenta" },

# Fallback
{ name = "*", fg = "#C8D3F8" },
{ name = "*/", fg = "#80AEFA" }
{ name = "*/", fg = "blue" }
]

[icons]
Expand Down Expand Up @@ -155,3 +167,61 @@ rules = [
# Default
"*" = ""
"*/" = ""

# : }}}


# : 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" }

# : }}}
Loading

0 comments on commit d032b68

Please sign in to comment.