codeberg_cli/render/
color.rs1use inquire::{validator::Validation, Text};
2
3pub fn mk_color_validator(prompt: Text) -> Text {
4 prompt
5 .with_help_message("(format: #xxxxxx)")
6 .with_validator(|color: &str| {
7 Ok((color.len() == 7
8 && color.starts_with('#')
9 && color
10 .chars()
11 .skip(1)
12 .take(6)
13 .filter(|digit| digit.is_ascii_hexdigit())
14 .count()
15 == 6)
16 .then_some(Validation::Valid)
17 .unwrap_or_else(|| Validation::Invalid("Not a color: format <#XXXXXX>".into())))
18 })
19}