Skip to content

Commit

Permalink
feat: adding ayu as the main applicaiton theme
Browse files Browse the repository at this point in the history
  • Loading branch information
wllfaria committed Apr 19, 2024
1 parent 8f22018 commit 346c2af
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 107 deletions.
108 changes: 46 additions & 62 deletions colors/src/colors.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crossterm::style::Color;

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Colors {
pub primary: PrimaryColors,
pub normal: NormalColors,
pub bright: BrightColors,
pub cursor_line: Color,
}

#[derive(Debug)]
Expand Down Expand Up @@ -40,21 +39,6 @@ pub struct BrightColors {
pub white: Color,
}

impl Default for Colors {
fn default() -> Self {
Colors {
primary: Default::default(),
normal: Default::default(),
bright: Default::default(),
cursor_line: Color::Rgb {
r: 0xE1,
g: 0xC5,
b: 0x8D,
},
}
}
}

impl Default for PrimaryColors {
fn default() -> Self {
PrimaryColors {
Expand Down Expand Up @@ -86,44 +70,44 @@ impl Default for NormalColors {
fn default() -> Self {
NormalColors {
black: Color::Rgb {
r: 0x0B,
g: 0x0E,
b: 0x14,
r: 0x03,
g: 0x03,
b: 0x03,
},
red: Color::Rgb {
r: 0xF8,
g: 0x70,
b: 0x70,
r: 0xD9,
g: 0x57,
b: 0x57,
},
green: Color::Rgb {
r: 0x36,
g: 0xC6,
b: 0x92,
r: 0xAA,
g: 0xd9,
b: 0x4C,
},
yellow: Color::Rgb {
r: 0xE1,
g: 0xC5,
b: 0x8D,
r: 0xE6,
g: 0xB4,
b: 0x50,
},
blue: Color::Rgb {
r: 0x5F,
g: 0xB0,
b: 0xFC,
r: 0x59,
g: 0xBA,
b: 0xE6,
},
magenta: Color::Rgb {
r: 0xB7,
g: 0x7E,
b: 0xE0,
r: 0x6C,
g: 0x59,
b: 0x80,
},
cyan: Color::Rgb {
r: 0x54,
g: 0xCE,
b: 0xD6,
r: 0x95,
g: 0xE6,
b: 0xCB,
},
white: Color::Rgb {
r: 0xCE,
g: 0xCE,
b: 0xCE,
r: 0xBF,
g: 0xBD,
b: 0xB6,
},
}
}
Expand All @@ -133,44 +117,44 @@ impl Default for BrightColors {
fn default() -> Self {
BrightColors {
black: Color::Rgb {
r: 0x51,
g: 0x5C,
b: 0x68,
r: 0x11,
g: 0x15,
b: 0x1C,
},
red: Color::Rgb {
r: 0xFB,
g: 0x73,
b: 0x73,
},
green: Color::Rgb {
r: 0x79,
g: 0xDC,
b: 0xAA,
r: 0x7F,
g: 0xD9,
b: 0x4C,
},
yellow: Color::Rgb {
r: 0xFF,
g: 0xE5,
b: 0x9E,
r: 0xE6,
g: 0xB6,
b: 0x73,
},
blue: Color::Rgb {
r: 0x7A,
g: 0xB0,
b: 0xDF,
r: 0x73,
g: 0xB8,
b: 0xFF,
},
magenta: Color::Rgb {
r: 0xC3,
g: 0x97,
b: 0xD8,
r: 0xD2,
g: 0xA6,
b: 0xFF,
},
cyan: Color::Rgb {
r: 0x70,
g: 0xC0,
b: 0xBA,
r: 0x95,
g: 0xE6,
b: 0xCB,
},
white: Color::Rgb {
r: 0xFF,
g: 0xFF,
b: 0xFF,
r: 0xFC,
g: 0xFC,
b: 0xFC,
},
}
}
Expand Down
93 changes: 60 additions & 33 deletions tui/src/components/dashboard/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ratatui::{
layout::{Alignment, Constraint, Direction, Flex, Layout, Rect},
style::{Style, Stylize},
text::Line,
widgets::{Block, Borders, Clear, Padding, Paragraph, StatefulWidget, Widget, Wrap},
widgets::{Block, Clear, Padding, Paragraph, StatefulWidget, Widget, Wrap},
Frame,
};
use std::ops::{Div, Not};
Expand Down Expand Up @@ -75,7 +75,6 @@ impl<'a> Dashboard<'a> {
filter: String::new(),
sender: None,
error_message: String::default(),

pane_focus: PaneFocus::List,
})
}
Expand Down Expand Up @@ -318,63 +317,83 @@ impl<'a> Dashboard<'a> {
}

fn build_hint_text(&self) -> Line<'static> {
"[j/k -> up/down] [n -> new] [enter -> select item] [? -> help] [q -> quit]"
.fg(self.colors.bright.black)
"[j/k -> up/down] [n -> new] [enter -> select item] [? -> help] [<C-c> -> quit]"
.fg(self.colors.normal.magenta)
.to_centered_line()
}

fn build_help_popup(&self) -> Paragraph<'_> {
fn make_overlay(&self, size: Rect) -> Paragraph<'_> {
let lines: Vec<Line<'_>> =
vec!["助ける".repeat(size.width.into()).into(); size.height.into()];

Paragraph::new(lines)
.fg(self.colors.primary.hover)
.bg(self.colors.primary.background.into())
.italic()
.bold()
}

fn draw_help_popup(&self, size: Rect, frame: &mut Frame) {
frame.render_widget(Clear, size);
let overlay = self.make_overlay(size);
frame.render_widget(overlay, size);

let lines = vec![
Line::from(vec![
"h/<left>".fg(self.colors.normal.magenta),
"h/<left>".fg(self.colors.bright.magenta),
" - select left item".into(),
]),
Line::from(vec![
"j/<down>".fg(self.colors.normal.magenta),
"j/<down>".fg(self.colors.bright.magenta),
" - select item below".into(),
]),
Line::from(vec![
"k/<up>".fg(self.colors.normal.magenta),
"k/<up>".fg(self.colors.bright.magenta),
" - select item above".into(),
]),
Line::from(vec![
"l/<right>".fg(self.colors.normal.magenta),
"l/<right>".fg(self.colors.bright.magenta),
" - select right item".into(),
]),
Line::from(vec![
"n/c".fg(self.colors.normal.magenta),
"n/c".fg(self.colors.bright.magenta),
" - creates a new collection".into(),
]),
Line::from(vec![
"d".fg(self.colors.normal.magenta),
"d".fg(self.colors.bright.magenta),
" - deletes the selected collection".into(),
]),
Line::from(vec![
"?".fg(self.colors.normal.magenta),
"?".fg(self.colors.bright.magenta),
" - toggle this help window".into(),
]),
Line::from(vec![
"enter".fg(self.colors.normal.magenta),
"enter".fg(self.colors.bright.magenta),
" - select item under cursor".into(),
]),
Line::from(vec![
"/".fg(self.colors.normal.magenta),
"/".fg(self.colors.bright.magenta),
" - enter filter mode".into(),
]),
Line::from(vec![
"q".fg(self.colors.normal.magenta),
" - quits the application".into(),
"<C-c>".fg(self.colors.bright.magenta),
" - quits the application".into(),
]),
Line::from(""),
Line::from("press any key to go back".fg(self.colors.normal.magenta)).centered(),
];
Paragraph::new(lines).wrap(Wrap { trim: true }).block(
Block::default()
.title("Help")
.title_style(Style::default().fg(self.colors.normal.white.into()))
.borders(Borders::ALL)
.border_style(Style::default().fg(self.colors.bright.black.into()))
.padding(Padding::new(2, 2, 1, 1))
.bg(self.colors.normal.black.into()),
)

frame.render_widget(Clear, self.layout.help_popup);
frame.render_widget(
Paragraph::new(lines).wrap(Wrap { trim: true }).block(
Block::default().padding(Padding::new(2, 2, 1, 1)).bg(self
.colors
.primary
.background
.into()),
),
self.layout.help_popup,
);
}

fn build_filter_input(&self) -> Line<'_> {
Expand All @@ -384,7 +403,7 @@ impl<'a> Dashboard<'a> {
fn build_title(&self) -> anyhow::Result<BigText<'_>> {
let title = BigText::builder()
.pixel_size(PixelSize::Quadrant)
.style(Style::default().fg(self.colors.normal.magenta.into()))
.style(Style::default().fg(self.colors.bright.magenta.into()))
.lines(vec!["Select a collection".into()])
.alignment(Alignment::Center)
.build()?;
Expand Down Expand Up @@ -432,12 +451,21 @@ impl<'a> Dashboard<'a> {

Ok((layout, empty_message))
}

fn draw_background(&self, size: Rect, frame: &mut Frame) {
frame.render_widget(Clear, size);
frame.render_widget(
Block::default().bg(self.colors.primary.background.into()),
size,
);
}
}

impl Component for Dashboard<'_> {
fn draw(&mut self, frame: &mut Frame, _: Rect) -> anyhow::Result<()> {
let title = self.build_title()?;
fn draw(&mut self, frame: &mut Frame, size: Rect) -> anyhow::Result<()> {
self.draw_background(size, frame);

let title = self.build_title()?;
frame.render_widget(title, self.layout.title_pane);

match (self.schemas.is_empty(), self.list_state.items.is_empty()) {
Expand Down Expand Up @@ -482,9 +510,7 @@ impl Component for Dashboard<'_> {
}

if self.pane_focus == PaneFocus::Help {
Clear.render(self.layout.help_popup, frame.buffer_mut());
let list_keymaps_popup = self.build_help_popup();
list_keymaps_popup.render(self.layout.help_popup, frame.buffer_mut());
self.draw_help_popup(size, frame);
}

if self.pane_focus == PaneFocus::Prompt {
Expand Down Expand Up @@ -537,6 +563,7 @@ impl Component for Dashboard<'_> {
}

fn build_layout(size: Rect) -> DashboardLayout {
let size = Rect::new(size.x + 1, size.y, size.width - 1, size.height);
let [top, help_pane] = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Fill(1), Constraint::Length(1)])
Expand All @@ -552,9 +579,9 @@ fn build_layout(size: Rect) -> DashboardLayout {
.areas(top);

let help_popup = Rect::new(
size.width / 4,
size.width.div(2).saturating_sub(25),
size.height.div(2).saturating_sub(7),
size.width / 2,
50,
14,
);
let confirm_popup = Rect::new(
Expand Down
Loading

0 comments on commit 346c2af

Please sign in to comment.