Fixing color schemes

This commit is contained in:
2026-01-30 20:15:43 +01:00
parent 44d1e9af24
commit eb3969b952
22 changed files with 2888 additions and 482 deletions

View File

@@ -7,7 +7,7 @@ use ratatui::Frame;
use tui_big_text::{BigText, PixelSize};
use crate::app::App;
use crate::theme::{dict, markdown, search, ui};
use crate::theme;
use crate::views::highlight;
// To add a new help topic: drop a .md file in docs/ and add one line here.
@@ -32,22 +32,28 @@ pub fn render(frame: &mut Frame, app: &App, area: Rect) {
}
fn render_topics(frame: &mut Frame, app: &App, area: Rect) {
let theme = theme::get();
let items: Vec<ListItem> = DOCS
.iter()
.enumerate()
.map(|(i, (name, _))| {
let selected = i == app.ui.help_topic;
let style = if selected {
Style::new().fg(dict::CATEGORY_SELECTED).add_modifier(Modifier::BOLD)
Style::new().fg(theme.dict.category_selected).add_modifier(Modifier::BOLD)
} else {
Style::new().fg(ui::TEXT_PRIMARY)
Style::new().fg(theme.ui.text_primary)
};
let prefix = if selected { "> " } else { " " };
ListItem::new(format!("{prefix}{name}")).style(style)
})
.collect();
let list = List::new(items).block(Block::default().borders(Borders::ALL).title("Topics"));
let list = List::new(items).block(
Block::default()
.borders(Borders::ALL)
.border_style(Style::new().fg(theme.dict.border_focused))
.title("Topics"),
);
frame.render_widget(list, area);
}
@@ -55,6 +61,7 @@ const WELCOME_TOPIC: usize = 0;
const BIG_TITLE_HEIGHT: u16 = 6;
fn render_content(frame: &mut Frame, app: &App, area: Rect) {
let theme = theme::get();
let (_, md) = DOCS[app.ui.help_topic];
let is_welcome = app.ui.help_topic == WELCOME_TOPIC;
@@ -64,13 +71,13 @@ fn render_content(frame: &mut Frame, app: &App, area: Rect) {
.areas(area);
let big_title = BigText::builder()
.pixel_size(PixelSize::Quadrant)
.style(Style::new().fg(markdown::H1).bold())
.style(Style::new().fg(theme.markdown.h1).bold())
.lines(vec!["CAGIRE".into()])
.centered()
.build();
let subtitle = Paragraph::new(RLine::from(Span::styled(
"A Forth Sequencer",
Style::new().fg(ui::TEXT_PRIMARY),
Style::new().fg(theme.ui.text_primary),
)))
.alignment(ratatui::layout::Alignment::Center);
let [big_area, subtitle_area] =
@@ -119,6 +126,7 @@ fn render_content(frame: &mut Frame, app: &App, area: Rect) {
.block(
Block::default()
.borders(Borders::ALL)
.border_style(Style::new().fg(theme.ui.border))
.padding(Padding::new(2, 2, 2, 2)),
)
.wrap(Wrap { trim: false });
@@ -126,10 +134,11 @@ fn render_content(frame: &mut Frame, app: &App, area: Rect) {
}
fn render_search_bar(frame: &mut Frame, app: &App, area: Rect) {
let theme = theme::get();
let style = if app.ui.help_search_active {
Style::new().fg(search::ACTIVE)
Style::new().fg(theme.search.active)
} else {
Style::new().fg(search::INACTIVE)
Style::new().fg(theme.search.inactive)
};
let cursor = if app.ui.help_search_active { "" } else { "" };
let text = format!(" /{}{cursor}", app.ui.help_search_query);
@@ -137,6 +146,7 @@ fn render_search_bar(frame: &mut Frame, app: &App, area: Rect) {
}
fn highlight_line<'a>(line: RLine<'a>, query: &str) -> RLine<'a> {
let theme = theme::get();
let mut result: Vec<Span<'a>> = Vec::new();
for span in line.spans {
let lower = span.content.to_lowercase();
@@ -146,7 +156,7 @@ fn highlight_line<'a>(line: RLine<'a>, query: &str) -> RLine<'a> {
}
let content = span.content.to_string();
let base_style = span.style;
let hl_style = base_style.bg(search::MATCH_BG).fg(search::MATCH_FG);
let hl_style = base_style.bg(theme.search.match_bg).fg(theme.search.match_fg);
let mut start = 0;
let lower_bytes = lower.as_bytes();
let query_bytes = query.as_bytes();
@@ -186,7 +196,8 @@ pub fn find_match(query: &str) -> Option<(usize, usize)> {
}
fn code_border_style() -> Style {
Style::new().fg(markdown::CODE_BORDER)
let theme = theme::get();
Style::new().fg(theme.markdown.code_border)
}
fn preprocess_underscores(md: &str) -> String {
@@ -269,16 +280,17 @@ fn parse_markdown(md: &str) -> Vec<RLine<'static>> {
}
fn composite_to_line(composite: Composite) -> RLine<'static> {
let theme = theme::get();
let base_style = match composite.style {
CompositeStyle::Header(1) => Style::new()
.fg(markdown::H1)
.fg(theme.markdown.h1)
.add_modifier(Modifier::BOLD | Modifier::UNDERLINED),
CompositeStyle::Header(2) => Style::new().fg(markdown::H2).add_modifier(Modifier::BOLD),
CompositeStyle::Header(_) => Style::new().fg(markdown::H3).add_modifier(Modifier::BOLD),
CompositeStyle::ListItem(_) => Style::new().fg(markdown::LIST),
CompositeStyle::Quote => Style::new().fg(markdown::QUOTE),
CompositeStyle::Code => Style::new().fg(markdown::CODE),
CompositeStyle::Paragraph => Style::new().fg(markdown::TEXT),
CompositeStyle::Header(2) => Style::new().fg(theme.markdown.h2).add_modifier(Modifier::BOLD),
CompositeStyle::Header(_) => Style::new().fg(theme.markdown.h3).add_modifier(Modifier::BOLD),
CompositeStyle::ListItem(_) => Style::new().fg(theme.markdown.list),
CompositeStyle::Quote => Style::new().fg(theme.markdown.quote),
CompositeStyle::Code => Style::new().fg(theme.markdown.code),
CompositeStyle::Paragraph => Style::new().fg(theme.markdown.text),
};
let prefix = match composite.style {
@@ -300,6 +312,7 @@ fn composite_to_line(composite: Composite) -> RLine<'static> {
}
fn compound_to_spans(compound: Compound, base: Style, out: &mut Vec<Span<'static>>) {
let theme = theme::get();
let mut style = base;
if compound.bold {
@@ -309,7 +322,7 @@ fn compound_to_spans(compound: Compound, base: Style, out: &mut Vec<Span<'static
style = style.add_modifier(Modifier::ITALIC);
}
if compound.code {
style = Style::new().fg(markdown::CODE);
style = Style::new().fg(theme.markdown.code);
}
if compound.strikeout {
style = style.add_modifier(Modifier::CROSSED_OUT);
@@ -317,7 +330,7 @@ fn compound_to_spans(compound: Compound, base: Style, out: &mut Vec<Span<'static
let src = compound.src.to_string();
let link_style = Style::new()
.fg(markdown::LINK)
.fg(theme.markdown.link)
.add_modifier(Modifier::UNDERLINED);
let mut rest = src.as_str();
@@ -337,7 +350,7 @@ fn compound_to_spans(compound: Compound, base: Style, out: &mut Vec<Span<'static
out.push(Span::styled(text.to_string(), link_style));
out.push(Span::styled(
format!(" ({url})"),
Style::new().fg(markdown::LINK_URL),
Style::new().fg(theme.markdown.link_url),
));
}
rest = &rest[url_start + url_end + 1..];