From 23e6ab9ea8b4b5d0c02bd6031d8a5f3bbdfc54b5 Mon Sep 17 00:00:00 2001 From: race604 Date: Tue, 19 Jul 2022 17:10:47 +0800 Subject: [PATCH] fix parsing color --- README.md | 13 ++++++++++++- src/app.rs | 6 +++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 34f6dbb..09a7c0f 100644 --- a/README.md +++ b/README.md @@ -45,12 +45,23 @@ You can press `Space` key to _pause_ and _resume_ the timer. ## Run stopwatch ```shell -# Start timer for 5 minutes $ tclock stopwatch ``` You can press `Space` key to _pause_ and _resume_ the stopwatch. +## Customize style + +You can customize the styles. + +* Size + +You can use `-s` or `--size` option to custome clock size, for example: + +```shell +$ tclock -s 2 +``` + # License MIT License. diff --git a/src/app.rs b/src/app.rs index 8dd588b..909f439 100644 --- a/src/app.rs +++ b/src/app.rs @@ -146,9 +146,9 @@ fn parse_color(s: &str) -> Result { .captures(s) .ok_or_else(|| format!("Invalid color: {}", s))?; let hex = cap.get(1).unwrap().as_str(); - let r = hex[1..3].parse::().unwrap(); - let g = hex[3..5].parse::().unwrap(); - let b = hex[5..7].parse::().unwrap(); + let r = u8::from_str_radix(&hex[0..2], 16).unwrap(); + let g = u8::from_str_radix(&hex[2..4], 16).unwrap(); + let b = u8::from_str_radix(&hex[4..], 16).unwrap(); Ok(Color::Rgb(r, g, b)) } }