Skip to content

Commit

Permalink
Organize
Browse files Browse the repository at this point in the history
  • Loading branch information
lusingander committed Sep 28, 2024
1 parent 9276601 commit ef08696
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 38 deletions.
62 changes: 40 additions & 22 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,55 @@ use ratatui::style::Color;
pub struct ColorTheme {
pub bg: Color,
pub fg: Color,
pub selected: Color,
pub selected_text: Color,
pub disabled: Color,
pub match_text: Color,
pub link: Color,
pub short_help: Color,
pub info_status: Color,
pub success_status: Color,
pub warn_status: Color,
pub error_status: Color,
pub line_number: Color,

pub divider: Color,
pub link: Color,

pub list_selected_bg: Color,
pub list_selected_fg: Color,
pub list_selected_inactive_bg: Color,
pub list_selected_inactive_fg: Color,
pub list_filter_match: Color,

pub detail_selected: Color,

pub dialog_selected: Color,

pub preview_line_number: Color,

pub status_help: Color,
pub status_info: Color,
pub status_success: Color,
pub status_warn: Color,
pub status_error: Color,
}

impl Default for ColorTheme {
fn default() -> Self {
Self {
bg: Color::Reset,
fg: Color::Reset,
selected: Color::Cyan,
selected_text: Color::Black,
disabled: Color::DarkGray,
match_text: Color::Red,
link: Color::Blue,
short_help: Color::DarkGray,
info_status: Color::Blue,
success_status: Color::Green,
warn_status: Color::Yellow,
error_status: Color::Red,
line_number: Color::DarkGray,

divider: Color::DarkGray,
link: Color::Blue,

list_selected_bg: Color::Cyan,
list_selected_fg: Color::Black,
list_selected_inactive_bg: Color::DarkGray,
list_selected_inactive_fg: Color::Black,
list_filter_match: Color::Red,

detail_selected: Color::Cyan,

dialog_selected: Color::Cyan,

preview_line_number: Color::DarkGray,

status_help: Color::DarkGray,
status_info: Color::Blue,
status_success: Color::Green,
status_warn: Color::Yellow,
status_error: Color::Red,
}
}
}
6 changes: 4 additions & 2 deletions src/pages/bucket_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,14 +493,16 @@ fn build_list_item<'a>(
Line::from(vec![
" ".into(),
before.into(),
highlighted.fg(theme.match_text),
highlighted.fg(theme.list_filter_match),
after.into(),
" ".into(),
])
};

let style = if selected {
Style::default().bg(theme.selected).fg(theme.selected_text)
Style::default()
.bg(theme.list_selected_bg)
.fg(theme.list_selected_fg)
} else {
Style::default()
};
Expand Down
10 changes: 7 additions & 3 deletions src/pages/object_detail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,11 @@ fn build_list_item_from_object_item<'a>(
}
};
if idx + offset == selected {
ListItem::new(content).style(Style::default().bg(theme.disabled).fg(theme.selected_text))
ListItem::new(content).style(
Style::default()
.bg(theme.list_selected_inactive_bg)
.fg(theme.list_selected_inactive_fg),
)
} else {
ListItem::new(content)
}
Expand All @@ -474,7 +478,7 @@ fn build_tabs(tab: &Tab, theme: &ColorTheme) -> Tabs<'static> {
.highlight_style(
Style::default()
.add_modifier(Modifier::BOLD)
.fg(theme.selected),
.fg(theme.detail_selected),
)
.block(Block::default().borders(Borders::BOTTOM))
}
Expand Down Expand Up @@ -656,7 +660,7 @@ struct VersionTabColor {
impl VersionTabColor {
fn new(theme: &ColorTheme) -> Self {
Self {
selected: theme.selected,
selected: theme.detail_selected,
divider: theme.divider,
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/pages/object_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,9 @@ fn build_list_item<'a>(
};

let style = if selected {
Style::default().bg(theme.selected).fg(theme.selected_text)
Style::default()
.bg(theme.list_selected_bg)
.fg(theme.list_selected_fg)
} else {
Style::default()
};
Expand All @@ -591,7 +593,7 @@ fn build_object_dir_line<'a>(name: &'a str, filter: &'a str, theme: &ColorTheme)
Line::from(vec![
" ".into(),
before.bold(),
highlighted.fg(theme.match_text).bold(),
highlighted.fg(theme.list_filter_match).bold(),
after.bold(),
"/".bold(),
" ".into(),
Expand Down Expand Up @@ -633,7 +635,7 @@ fn build_object_file_line<'a>(
Line::from(vec![
" ".into(),
before.into(),
highlighted.fg(theme.match_text),
highlighted.fg(theme.list_filter_match),
after.into(),
" ".into(),
date.into(),
Expand Down
10 changes: 5 additions & 5 deletions src/ui/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn build_short_help(app: &App, width: u16) -> Paragraph {
let pad = Padding::horizontal(2);
let max_width = (width - pad.left - pad.right) as usize;
let help = build_short_help_string(&helps, max_width);
Paragraph::new(help.fg(app.theme.short_help)).block(Block::default().padding(pad))
Paragraph::new(help.fg(app.theme.status_help)).block(Block::default().padding(pad))
}

fn build_short_help_string(helps: &[(String, usize)], max_width: usize) -> String {
Expand All @@ -136,23 +136,23 @@ fn build_short_help_string(helps: &[(String, usize)], max_width: usize) -> Strin
}

fn build_info_status<'a>(msg: &'a str, theme: &'a ColorTheme) -> Paragraph<'a> {
Paragraph::new(msg.fg(theme.info_status))
Paragraph::new(msg.fg(theme.status_info))
.block(Block::default().padding(Padding::horizontal(2)))
}

fn build_success_status<'a>(msg: &'a str, theme: &'a ColorTheme) -> Paragraph<'a> {
Paragraph::new(msg.add_modifier(Modifier::BOLD).fg(theme.success_status))
Paragraph::new(msg.add_modifier(Modifier::BOLD).fg(theme.status_success))
.block(Block::default().padding(Padding::horizontal(2)))
}

fn build_warn_status<'a>(msg: &'a str, theme: &'a ColorTheme) -> Paragraph<'a> {
Paragraph::new(msg.add_modifier(Modifier::BOLD).fg(theme.warn_status))
Paragraph::new(msg.add_modifier(Modifier::BOLD).fg(theme.status_warn))
.block(Block::default().padding(Padding::horizontal(2)))
}

fn build_error_status<'a>(err: &'a str, theme: &'a ColorTheme) -> Paragraph<'a> {
let err = format!("ERROR: {}", err);
Paragraph::new(err.add_modifier(Modifier::BOLD).fg(theme.error_status))
Paragraph::new(err.add_modifier(Modifier::BOLD).fg(theme.status_error))
.block(Block::default().padding(Padding::horizontal(2)))
}

Expand Down
2 changes: 1 addition & 1 deletion src/widget/copy_detail_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl CopyDetailDialogColor {
bg: theme.bg,
block: theme.fg,
text: theme.fg,
selected: theme.selected,
selected: theme.dialog_selected,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/widget/scroll_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl ScrollLinesColor {
fn new(theme: &ColorTheme) -> Self {
Self {
block: theme.fg,
line_number: theme.line_number,
line_number: theme.preview_line_number,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/widget/sort_list_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl ListSortDialogColor {
bg: theme.bg,
block: theme.fg,
text: theme.fg,
selected: theme.selected,
selected: theme.dialog_selected,
}
}
}
Expand Down

0 comments on commit ef08696

Please sign in to comment.