diff options
| author | Іван Потієнко <[email protected]> | 2025-08-05 19:12:06 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-05 19:12:06 +0300 |
| commit | 026117cc402803cb17dd87b9e69659a5ba96de9a (patch) | |
| tree | 6cf912d79532dc8de99dc6ee9baea74e1eedd24f /src/main.rs | |
| parent | 93e431196b8f9d8a66ce1ef99b2c92953ce12a3a (diff) | |
| parent | a810883f63f821fea42cc7dbcff70e5697aef6a1 (diff) | |
| download | mikusays-c-026117cc402803cb17dd87b9e69659a5ba96de9a.tar.gz mikusays-c-026117cc402803cb17dd87b9e69659a5ba96de9a.zip | |
Merge pull request #2 from Strubbelkopp/main
Add optional argument to select a specific style
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs index e4d1b6e..e0ffba7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,28 +1,34 @@ +use clap::Parser; use crossterm::terminal::size; -use std::env; use unicode_width::UnicodeWidthStr; mod mikuart; use mikuart::get_miku_art; -fn main() -> Result<(), Box<dyn std::error::Error>> { - let args: Vec<String> = env::args().collect(); +#[derive(Parser)] +#[command(version, about, long_about = None)] +struct Args { + /// Text to display in the speech bubble + text: String, - if args.len() == 1 { - println!("Usage: mikusays <text>"); - println!("Example: mikusays \"Hello, World!\""); - return Ok(()); - } + /// Style of the Miku art. A random one is chosen if not specified + #[arg(short, long)] + style: Option<i32>, +} + +fn main() -> Result<(), Box<dyn std::error::Error>> { + let args = Args::parse(); - let text = args[1..].join(" "); - draw_miku_says(&text)?; + let text = args.text; + let style = args.style.unwrap_or(-1); // Default to -1 to select a random style + draw_miku_says(&text, style)?; Ok(()) } -fn draw_miku_says(text: &str) -> Result<(), Box<dyn std::error::Error>> { +fn draw_miku_says(text: &str, style: i32) -> Result<(), Box<dyn std::error::Error>> { let speech_bubble_lines = get_speech_bubble_lines(text); - let miku_art = get_miku_art(); + let miku_art = get_miku_art(style); let (window_width, window_height) = size()?; let available_width = window_width as usize; |
