Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethlove committed Aug 21, 2024
1 parent a605ec3 commit f406fb2
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 74 deletions.
6 changes: 3 additions & 3 deletions src/cli/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ pub fn get_database_url() -> String {

/// Parses command line options
pub fn parse() {
let app_styles = crate::color::AppStyles::new();
let cli_styles = crate::color::CliStyles::new();
let cli = Cli::parse();
let db_url = get_database_url();
let mut db = Database::new(&db_url).expect("Could not load database");
let response_style = Style::new().bold().fg(app_styles.response_fg.into());
let response_style = Style::new().bold().fg(cli_styles.response_fg.into());
match &cli.command {
Commands::Add { task, frequency } => match frequency {
Frequency::Daily => {
Expand Down Expand Up @@ -219,7 +219,7 @@ pub fn parse() {
Err(e) => {
let response = Style::new()
.bold()
.fg(app_styles.response_error_fg)
.fg(cli_styles.response_error_fg)
.paint("Error checking in:");
eprintln!("{response} {}", e)
}
Expand Down
6 changes: 3 additions & 3 deletions src/cli/table.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::color::AppStyles;
use crate::streak::Streak;
use ansi_term::Style;
use tabled::{builder::Builder, settings::Style as TabledStyle};
use term_size::dimensions;
use crate::color::CliStyles;

/// Builds table of streaks from list
pub fn build_table(streaks: Vec<Streak>) -> String {
let app_styles = AppStyles::new();
let cli_styles = CliStyles::new();
let mut builder = Builder::new();
let header_style = Style::new().italic().fg(app_styles.table_header_fg);
let header_style = Style::new().italic().fg(cli_styles.table_header_fg);
builder.push_record([
header_style.paint("\nIdent").to_string(),
header_style.paint("\nTask").to_string(),
Expand Down
48 changes: 39 additions & 9 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,24 @@ const fn rgb(color: &catppuccin::Color) -> Color {
}

#[derive(Clone, Debug)]
pub struct AppStyles {
pub struct CliStyles {
pub response_fg: ansi_term::Color,
pub response_error_fg: ansi_term::Color,
pub table_header_fg: ansi_term::Color
}

impl CliStyles {
pub fn new() -> Self {
CliStyles {
response_fg: ansi(&PALETTE.colors.text),
response_error_fg: ansi(&PALETTE.colors.red),
table_header_fg: ansi(&PALETTE.colors.peach),
}
}
}

#[derive(Clone, Debug)]
pub struct TuiStyles {
pub background: Color,
pub foreground: Color,
pub danger: Color,
Expand All @@ -23,18 +40,15 @@ pub struct AppStyles {
pub highlight_fg: Color,
pub tab_fg: Color,
pub selected_tab_fg: Color,
pub response_fg: ansi_term::Color,
pub response_error_fg: ansi_term::Color,
pub table_header_fg: ansi_term::Color,
}

impl AppStyles {
impl TuiStyles {
pub fn new() -> Self {
let peach = rgb(&PALETTE.colors.peach);
let text = rgb(&PALETTE.colors.text);
let base = rgb(&PALETTE.colors.base);

AppStyles {
TuiStyles {
background: base,
foreground: text,
danger: Color::Rgb(
Expand All @@ -58,9 +72,25 @@ impl AppStyles {
highlight_fg: base,
tab_fg: text,
selected_tab_fg: peach,
response_fg: ansi(&PALETTE.colors.peach),
response_error_fg: ansi(&PALETTE.colors.red),
table_header_fg: ansi(&PALETTE.colors.peach),
}
}
}

#[derive(Clone, Debug)]
pub struct GuiStyles {
pub header_bg: Color,
pub header_fg: Color,
pub background: String,
pub foreground: String,
}

impl GuiStyles {
pub fn new() -> Self {
GuiStyles {
header_bg: rgb(&PALETTE.colors.peach),
header_fg: rgb(&PALETTE.colors.surface0),
background: PALETTE.colors.base.hex.to_string(),
foreground: PALETTE.colors.text.hex.to_string(),
}
}
}
119 changes: 64 additions & 55 deletions src/gui/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::cli::get_database_url;
use crate::filtering::FilterByStatus;
use crate::sorting::{SortByDirection, SortByField};
use crate::streak::Status;
use crate::color::GuiStyles;
use crate::{db::Database, streak::Frequency, streak::Streak};
use dioxus::desktop::{use_global_shortcut, Config, WindowBuilder};
use dioxus::prelude::*;
Expand All @@ -16,6 +17,7 @@ pub fn main() {

fn app() -> Element {
let mut streaks = use_signal(Streaks::new);
let gui_styles = GuiStyles::new();

let show_popup = use_signal(|| None);
_ = use_global_shortcut("CmdOrCtrl+Q", move || {
Expand All @@ -26,20 +28,17 @@ fn app() -> Element {
});

rsx! {
head {
link { rel: "stylesheet", href: asset!("./assets/bulma.min.css") }
link { rel: "stylesheet", href: asset!("./assets/streaks.css") }
head::Link { rel: "stylesheet", href: asset!("./assets/bulma.min.css") }
head::Link { rel: "stylesheet", href: asset!("./assets/streaks.css") }

style { r#type: "text/css",
{format!(r#"body {{ background-color: {0}; color: {1}; }}"#, gui_styles.background, gui_styles.foreground)}
}
div {
head {
link {
rel: "stylesheet",
href: "https://fonts.googleapis.com/icon?family=Material+Icons"
}
}

header { style: "background-color: {catppuccin::PALETTE.mocha.colors.mauve.hex.to_string()}",
h1 { style: "color: {catppuccin::PALETTE.mocha.colors.crust.hex.to_string()}",
div {
header { style: "background-color: {gui_styles.header_bg}",
h1 { style: "color: {gui_styles.header_fg}",
class: "is-bold",
"Skidmarks"
}
}
Expand Down Expand Up @@ -72,6 +71,8 @@ fn app() -> Element {
option { "Missed" }
}
}
}
div { class: "column",
button {
class: "button",
onclick: move |_| {
Expand All @@ -82,7 +83,7 @@ fn app() -> Element {
}
}
}
main { {streak_table(streaks, show_popup)} }
main { class: "section", {streak_table(streaks, show_popup)} }
div { class: "section", {streak_form(streaks)} }
{popup(show_popup, streaks)}
}
Expand Down Expand Up @@ -217,52 +218,60 @@ fn streak_form(mut streaks: Signal<Streaks>) -> Element {
h2 { "Submitted!" }
}

form {
id: "streak-form",
class: "form",
oninput: move |event| {
values.set(event.values());
},
onsubmit: move |event| {
submitted_values.set(event.values());
let values = submitted_values.read();
let task = values.get("task").expect("Unable to get task value");
let default_frequency = FormValue(vec!["Daily".to_string()]);
let freq = values.get("frequency").unwrap_or(&default_frequency);
match freq.as_value().as_str() {
"Daily" => streaks.write().new_streak(&task.as_value(), Frequency::Daily),
"Weekly" => streaks.write().new_streak(&task.as_value(), Frequency::Weekly),
_ => streaks.write().new_streak(&task.as_value(), Frequency::Daily),
};
task_signal.set(String::new());
freq_signal
.set(FormValue {
0: vec!["Daily".to_string()],
});
streaks.write().load_streaks();
},
input {
class: "input",
r#type: "text",
name: "task",
placeholder: "Task",
value: task_signal.read().clone().into_value(),
div {
form {
id: "streak-form",
class: "form columns",
oninput: move |event| {
task_signal.set(event.data().value());
values.set(event.values());
},
onsubmit: move |event| {
submitted_values.set(event.values());
let values = submitted_values.read();
let task = values.get("task").expect("Unable to get task value");
let default_frequency = FormValue(vec!["Daily".to_string()]);
let freq = values.get("frequency").unwrap_or(&default_frequency);
match freq.as_value().as_str() {
"Daily" => streaks.write().new_streak(&task.as_value(), Frequency::Daily),
"Weekly" => streaks.write().new_streak(&task.as_value(), Frequency::Weekly),
_ => streaks.write().new_streak(&task.as_value(), Frequency::Daily),
};
task_signal.set(String::new());
freq_signal
.set(FormValue {
0: vec!["Daily".to_string()],
});
streaks.write().load_streaks();
},
div { class: "column is-three-quarters",
input {
class: "input",
r#type: "text",
name: "task",
placeholder: "Task",
value: task_signal.read().clone().into_value(),
oninput: move |event| {
task_signal.set(event.data().value());
}
}
}
}
div { class: "select",
select {
class: "select",
name: "frequency",
oninput: move |_| {
freq_signal.set(freq_value.clone());
},
option { "Daily" }
option { "Weekly" }
div { class: "column",
div { class: "select",
select {
class: "select",
name: "frequency",
oninput: move |_| {
freq_signal.set(freq_value.clone());
},
option { "Daily" }
option { "Weekly" }
}
}
}
div { class: "column",
button { class: "button", r#type: "submit", "Add" }
}
}
button { class: "button", r#type: "submit", "Add" }
}
)
}
Expand Down
8 changes: 4 additions & 4 deletions src/tui/tui.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::cli::get_database_url;
use crate::color::AppStyles;
use crate::color::TuiStyles;
use crate::db::Database;
use crate::filtering::{filter_by_status, FilterByStatus};
use crate::sorting::{SortByDirection, SortByField};
Expand Down Expand Up @@ -58,7 +58,7 @@ struct App {
tab_state: u8,
search_phrase: String,
new_streak: NewStreak,
styles: AppStyles,
styles: TuiStyles,
}

impl App {
Expand All @@ -75,7 +75,7 @@ impl App {
tab_state: 0,
search_phrase: String::default(),
new_streak: NewStreak::default(),
styles: AppStyles::new(),
styles: TuiStyles::new(),
}
}

Expand Down Expand Up @@ -495,7 +495,7 @@ fn get_rows(app: &mut App) -> Vec<Row<'static>> {
.collect();
}

let styles = AppStyles::new();
let styles = TuiStyles::new();

let mut rows = vec![];
let (w, _) = dimensions().unwrap();
Expand Down

0 comments on commit f406fb2

Please sign in to comment.