chore: start work on cli
This commit is contained in:
parent
023427e3f9
commit
1ae8995ac2
3 changed files with 74 additions and 2 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -206,6 +206,7 @@ name = "cli"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"rmenu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -5,4 +5,5 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
clap = { version = "4.5.27", features = ["derive"] }
|
||||
rmenu = { version = "0.1.0", path = "../core" }
|
||||
|
||||
|
|
|
@ -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<usize, ParseIntError> {
|
||||
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<bool>,
|
||||
pub height: Option<usize>,
|
||||
pub padding: Option<usize>,
|
||||
pub lines: Option<usize>,
|
||||
pub line_height: Option<usize>,
|
||||
|
||||
// typography
|
||||
pub font_family: Option<String>,
|
||||
pub font_size: Option<usize>,
|
||||
pub language: Option<String>,
|
||||
|
||||
// color
|
||||
pub normal_fg: Option<String>,
|
||||
pub normal_bg: Option<String>,
|
||||
pub prompt_fg: Option<String>,
|
||||
pub prompt_bg: Option<String>,
|
||||
pub selection_fg: Option<String>,
|
||||
pub selection_bg: Option<String>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = Args::parse();
|
||||
let cfg = create_config(args);
|
||||
println!("{cfg:?}");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue