-
Notifications
You must be signed in to change notification settings - Fork 771
Expand file tree
/
Copy pathconstants.rs
More file actions
84 lines (76 loc) · 2.41 KB
/
constants.rs
File metadata and controls
84 lines (76 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use super::*;
const CONSTANTS: &[(&str, &str, Option<&str>, &str)] = &[
("HEX", "0123456789abcdef", None, "1.27.0"),
("HEXLOWER", "0123456789abcdef", None, "1.27.0"),
("HEXUPPER", "0123456789ABCDEF", None, "1.27.0"),
("PATH_SEP", "/", Some("\\"), "1.41.0"),
("PATH_VAR_SEP", ":", Some(";"), "1.41.0"),
("CLEAR", "\x1bc", None, "1.37.0"),
("NORMAL", "\x1b[0m", None, "1.37.0"),
("BOLD", "\x1b[1m", None, "1.37.0"),
("ITALIC", "\x1b[3m", None, "1.37.0"),
("UNDERLINE", "\x1b[4m", None, "1.37.0"),
("INVERT", "\x1b[7m", None, "1.37.0"),
("HIDE", "\x1b[8m", None, "1.37.0"),
("STRIKETHROUGH", "\x1b[9m", None, "1.37.0"),
("BLACK", "\x1b[30m", None, "1.37.0"),
("RED", "\x1b[31m", None, "1.37.0"),
("GREEN", "\x1b[32m", None, "1.37.0"),
("YELLOW", "\x1b[33m", None, "1.37.0"),
("BLUE", "\x1b[34m", None, "1.37.0"),
("MAGENTA", "\x1b[35m", None, "1.37.0"),
("CYAN", "\x1b[36m", None, "1.37.0"),
("WHITE", "\x1b[37m", None, "1.37.0"),
("BG_BLACK", "\x1b[40m", None, "1.37.0"),
("BG_RED", "\x1b[41m", None, "1.37.0"),
("BG_GREEN", "\x1b[42m", None, "1.37.0"),
("BG_YELLOW", "\x1b[43m", None, "1.37.0"),
("BG_BLUE", "\x1b[44m", None, "1.37.0"),
("BG_MAGENTA", "\x1b[45m", None, "1.37.0"),
("BG_CYAN", "\x1b[46m", None, "1.37.0"),
("BG_WHITE", "\x1b[47m", None, "1.37.0"),
];
pub(crate) fn constants() -> &'static BTreeMap<&'static str, &'static str> {
static MAP: LazyLock<BTreeMap<&str, &str>> = LazyLock::new(|| {
CONSTANTS
.iter()
.copied()
.map(|(name, unix, windows, _version)| {
(
name,
if cfg!(windows) {
windows.unwrap_or(unix)
} else {
unix
},
)
})
.collect()
});
&MAP
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn readme_table() {
let mut table = Vec::<String>::new();
table.push("| Name | Value | Value on Windows |".into());
table.push("|---|---|---|".into());
for (name, unix, windows, version) in CONSTANTS {
table.push(format!(
"| `{name}`<sup>{version}</sup> | `\"{}\"` | {} |",
unix.replace('\x1b', "\\e"),
windows
.map(|value| format!("`\"{value}\"`"))
.unwrap_or_default(),
));
}
let table = table.join("\n");
let readme = fs::read_to_string("README.md").unwrap();
assert!(
readme.contains(&table),
"could not find table in readme:\n{table}",
);
}
}