may_clack/
style.rs

1//! Style utility
2
3use is_unicode_supported::is_unicode_supported;
4use once_cell::sync::Lazy;
5
6pub(crate) static IS_UNICODE: Lazy<bool> = Lazy::new(is_unicode_supported);
7
8fn is_unicode(unicode: &'static str, non_unicode: &'static str) -> &'static str {
9	if *IS_UNICODE {
10		unicode
11	} else {
12		non_unicode
13	}
14}
15
16/// Clack prompt chars.
17///
18/// Changes if the terminal supports unicode.
19pub mod chars {
20	use super::is_unicode;
21	use once_cell::sync::Lazy;
22
23	/// Straight left bar
24	pub static BAR: Lazy<&str> = Lazy::new(|| is_unicode("│", "|"));
25	/// Start bar
26	pub static BAR_START: Lazy<&str> = Lazy::new(|| is_unicode("┌", "T"));
27	/// End bar
28	pub static BAR_END: Lazy<&str> = Lazy::new(|| is_unicode("└", "—"));
29	/// Active step
30	pub static STEP_ACTIVE: Lazy<&str> = Lazy::new(|| is_unicode("◆", "*"));
31	/// Cancelled step
32	pub static STEP_CANCEL: Lazy<&str> = Lazy::new(|| is_unicode("■", "x"));
33	/// Error step
34	pub static STEP_ERROR: Lazy<&str> = Lazy::new(|| is_unicode("▲", "x"));
35	/// Submitted step
36	pub static STEP_SUBMIT: Lazy<&str> = Lazy::new(|| is_unicode("◇", "o"));
37	/// Active radio
38	pub static RADIO_ACTIVE: Lazy<&str> = Lazy::new(|| is_unicode("●", ">"));
39	/// Inactive radio
40	pub static RADIO_INACTIVE: Lazy<&str> = Lazy::new(|| is_unicode("○", " "));
41	/// Active checkbox
42	pub static CHECKBOX_ACTIVE: Lazy<&str> = Lazy::new(|| is_unicode("◻", "[.]"));
43	/// Selected checkbox
44	pub static CHECKBOX_SELECTED: Lazy<&str> = Lazy::new(|| is_unicode("◼", "[+]"));
45	/// Inactive checkbox
46	pub static CHECKBOX_INACTIVE: Lazy<&str> = Lazy::new(|| is_unicode("◻", "[ ]"));
47}
48
49/// ANSI escape codes
50pub mod ansi {
51	/// ANSI escape code to clear the line
52	pub const CLEAR_LINE: &str = "\x1b[2K";
53}