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 ratatui::prelude::*;
const green: Color = Color::Rgb(127, 255, 0);
const orange: Color = Color::Rgb(255, 165, 0);
pub trait Summarize {
fn heading(&self) -> Vec<Span>;
fn brief(&self) -> Vec<Vec<Span>>;
@ -23,28 +26,40 @@ impl Summarize for MovementGraphItem {
]
}
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>> {
let heading = self.heading();
let mut output = vec![heading];
let items = &self.values.items;
let items = if items.len() > 2 {
vec![items.first().unwrap(), items.last().unwrap()]
let mut items = if items.len() > 2 {
vec![
items.first().unwrap().heading(),
vec![Span::from("...").fg(Color::DarkGray)],
items.last().unwrap().heading(),
vec![Span::raw("")],
]
} else {
items.iter().collect()
items.iter().map(|i| i.heading()).collect()
};
let mut output = vec![heading];
for item in items {
let mut heading = item.heading();
heading.insert(0, Span::from(" ".repeat(4)));
output.push(heading);
for mut item in items {
item.insert(0, Span::from(" ".repeat(4)));
output.push(item);
}
output
@ -54,7 +69,13 @@ impl Summarize for MovementGraphItem {
let heading = self
.heading()
.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();
let items = &self.values.items;
@ -68,6 +89,10 @@ impl Summarize for MovementGraphItem {
}
}
if !items.is_empty() {
output.push(vec![Span::raw("")]);
}
output
}
}

187
demo.cast

File diff suppressed because one or more lines are too long