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