diff --git a/src/config/basic.rs b/src/config/basic.rs index feb62e3..1b5a694 100644 --- a/src/config/basic.rs +++ b/src/config/basic.rs @@ -58,12 +58,12 @@ pub struct Config { /// /// Underline or surround the hint for increased visibility. /// If not provided, only the hint colors will be used. - #[clap(short = 's', long, arg_enum, rename_all = "lowercase")] - pub hint_style: Option, + #[clap(short = 's', long = "hint-style", arg_enum, rename_all = "lowercase")] + pub hint_style_arg: Option, /// Chars surrounding each hint, used with `Surround` style. #[clap(long, default_value = "{}", - parse(try_from_str = parse_chars))] + parse(try_from_str = try_parse_chars))] pub hint_surroundings: (char, char), } @@ -78,7 +78,7 @@ pub enum HintStyleArg { } /// Try to parse a `&str` into a tuple of `char`s. -fn parse_chars(src: &str) -> Result<(char, char)> { +fn try_parse_chars(src: &str) -> Result<(char, char)> { if src.chars().count() != 2 { return Err(Error::ExpectedSurroundingPair); } @@ -86,3 +86,20 @@ fn parse_chars(src: &str) -> Result<(char, char)> { let chars: Vec = src.chars().collect(); Ok((chars[0], chars[1])) } + +impl Config { + pub fn hint_style(&self) -> Option { + match &self.hint_style_arg { + None => None, + Some(style) => match style { + HintStyleArg::Bold => Some(ui::HintStyle::Bold), + HintStyleArg::Italic => Some(ui::HintStyle::Italic), + HintStyleArg::Underline => Some(ui::HintStyle::Underline), + HintStyleArg::Surround => { + let (open, close) = self.hint_surroundings; + Some(ui::HintStyle::Surround(open, close)) + } + }, + } + } +} diff --git a/src/config/extended.rs b/src/config/extended.rs index 2075baf..93a1658 100644 --- a/src/config/extended.rs +++ b/src/config/extended.rs @@ -96,7 +96,7 @@ impl ConfigExt { } "@copyrat-hint-style" => { let case_insensitive = true; - inner.hint_style = Some( + inner.hint_style_arg = Some( basic::HintStyleArg::from_str(value, case_insensitive) .map_err(Error::ExpectedEnumVariant)?, ) diff --git a/src/lib.rs b/src/lib.rs index d15496c..e3a1760 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,19 +27,6 @@ pub fn run(lines: &[&str], opt: &config::basic::Config) -> Option return None; } - let hint_style = match &opt.hint_style { - None => None, - Some(style) => match style { - config::basic::HintStyleArg::Bold => Some(ui::HintStyle::Bold), - config::basic::HintStyleArg::Italic => Some(ui::HintStyle::Italic), - config::basic::HintStyleArg::Underline => Some(ui::HintStyle::Underline), - config::basic::HintStyleArg::Surround => { - let (open, close) = opt.hint_surroundings; - Some(ui::HintStyle::Surround(open, close)) - } - }, - }; - let default_output_destination = config::extended::OutputDestination::Tmux; let selection: Option = { @@ -49,7 +36,7 @@ pub fn run(lines: &[&str], opt: &config::basic::Config) -> Option default_output_destination, &opt.colors, &opt.hint_alignment, - hint_style, + opt.hint_style(), ); ui.present()