From 1ae8995ac258788a37d221cc7df1f9cd5b015511 Mon Sep 17 00:00:00 2001 From: rowan Date: Sun, 26 Jan 2025 22:36:07 -0600 Subject: [PATCH] chore: start work on cli --- Cargo.lock | 1 + cli/Cargo.toml | 1 + cli/src/main.rs | 74 +++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 126d3fc..bfd28fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -206,6 +206,7 @@ name = "cli" version = "0.1.0" dependencies = [ "clap", + "rmenu", ] [[package]] diff --git a/cli/Cargo.toml b/cli/Cargo.toml index e7766f6..56e0b01 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -5,4 +5,5 @@ edition = "2021" [dependencies] clap = { version = "4.5.27", features = ["derive"] } +rmenu = { version = "0.1.0", path = "../core" } diff --git a/cli/src/main.rs b/cli/src/main.rs index e7a11a9..b95dd6e 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,3 +1,73 @@ -fn main() { - println!("Hello, world!"); +use std::num::ParseIntError; + +use clap::Parser; + +macro_rules! set_opt { + ($arg:expr, $cfg:expr) => { + if arg.is_some() { + cfg = arg.unwrap(); + } + }; +} + +macro_rules! set_color { + ($fg:expr, $bg:expr, $cfg:expr) => { + set_opt!(bg, cfg.0); + set_opt!(fg, cfg.1); + }; +} + +fn parse_number(n: &str) -> Result { + match n.strip_prefix("0x") { + Some(value) => usize::from_str_radix(value, 16), + None => usize::from_str_radix(n, 10), + } +} + +fn create_config(args: Args) -> Config { + let cfg = Config::default(); + + set_opt!(args.bottom, cfg.bottom); + set_opt!(args.height, cfg.height); + set_opt!(args.padding, cfg.padding); + set_opt!(args.lines, cfg.lines); + set_opt!(args.line_height, cfg.line_height); + set_opt!(args.font_family, cfg.font_family); + set_opt!(args.font_size, cfg.font_size); + set_opt!(args.language, cfg.language); + set_color!(args.normal_bg, args.normal_fg, cfg.normal_color); + set_color!(args.prompt_bg, args.prompt_fg, cfg.prompt_color); + set_color!(args.selection_bg, args.selection_fg, cfg.selection_color); + + cfg +} + +#[derive(Parser)] +#[command(version, about, long_about = None)] +struct Args { + // transform + pub bottom: Option, + pub height: Option, + pub padding: Option, + pub lines: Option, + pub line_height: Option, + + // typography + pub font_family: Option, + pub font_size: Option, + pub language: Option, + + // color + pub normal_fg: Option, + pub normal_bg: Option, + pub prompt_fg: Option, + pub prompt_bg: Option, + pub selection_fg: Option, + pub selection_bg: Option, +} + +fn main() { + let args = Args::parse(); + let cfg = create_config(args); + println!("{cfg:?}"); }