feat: add color
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-05-10 22:22:19 +02:00
parent 3588dc2993
commit 55c731ef5b
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
2 changed files with 161 additions and 73 deletions

View File

@ -2,6 +2,9 @@ use crate::components::movement_graph::{GraphItemType, MovementGraph, MovementGr
use itertools::Itertools; use itertools::Itertools;
use ratatui::prelude::*; use ratatui::prelude::*;
const green: Color = Color::Rgb(127, 255, 0);
const orange: Color = Color::Rgb(255, 165, 0);
pub trait Summarize { pub trait Summarize {
fn heading(&self) -> Vec<Span>; fn heading(&self) -> Vec<Span>;
fn brief(&self) -> Vec<Vec<Span>>; fn brief(&self) -> Vec<Vec<Span>>;
@ -23,28 +26,40 @@ impl Summarize for MovementGraphItem {
] ]
} }
GraphItemType::Item { done } => { GraphItemType::Item { done } => {
vec![Span::from(if done { "[x] " } else { "[ ] " }), name] if done {
vec![
Span::from("["),
Span::from("x").fg(green),
Span::from("] "),
name,
]
} else {
vec![Span::from("[ ] "), name]
}
} }
} }
} }
fn brief(&self) -> Vec<Vec<Span>> { fn brief(&self) -> Vec<Vec<Span>> {
let heading = self.heading(); let heading = self.heading();
let mut output = vec![heading];
let items = &self.values.items; let items = &self.values.items;
let items = if items.len() > 2 { let mut items = if items.len() > 2 {
vec![items.first().unwrap(), items.last().unwrap()] vec![
items.first().unwrap().heading(),
vec![Span::from("...").fg(Color::DarkGray)],
items.last().unwrap().heading(),
vec![Span::raw("")],
]
} else { } else {
items.iter().collect() items.iter().map(|i| i.heading()).collect()
}; };
let mut output = vec![heading]; for mut item in items {
item.insert(0, Span::from(" ".repeat(4)));
for item in items { output.push(item);
let mut heading = item.heading();
heading.insert(0, Span::from(" ".repeat(4)));
output.push(heading);
} }
output output
@ -54,7 +69,13 @@ impl Summarize for MovementGraphItem {
let heading = self let heading = self
.heading() .heading()
.into_iter() .into_iter()
.map(|h| if selected { h.bold() } else { h }) .map(|h| {
if selected {
h.patch_style(Style::new().fg(orange))
} else {
h
}
})
.collect_vec(); .collect_vec();
let items = &self.values.items; let items = &self.values.items;
@ -68,6 +89,10 @@ impl Summarize for MovementGraphItem {
} }
} }
if !items.is_empty() {
output.push(vec![Span::raw("")]);
}
output output
} }
} }

187
demo.cast

File diff suppressed because one or more lines are too long