feat(colors): implement color gradient generation

Swadhin Biswas committed 7 months ago
0fc9e5f
1 parent b521b58
commit 0fc9e5f
1 file changed
+50 -0
Showing 1 changed file+50-0
▼src/colors/mod.rs
+50-0
78
78
} else {
79
79
color(c1)
80
80
};
81
+
82
+ // If the second color is 7 or 8, subtitle uses the first color instead
83
+ let subtitle = if c2 == 7 || c2 == 8 {
84
+ if c1 == 8 || c1 == 7 {
85
+ RESET.to_string()
86
+ } else {
87
+ color(c1)
88
+ }
89
+ } else {
90
+ color(c2)
91
+ };
92
+
93
+ Self {
94
+ c,
95
+ title,
96
+ at: RESET.to_string(),
97
+ underline: RESET.to_string(),
98
+ subtitle,
99
+ colon: RESET.to_string(),
100
+ info: RESET.to_string(),
101
+ ascii_bold: bold,
102
+ }
103
+ }
104
+
105
+ /// Create a no-color scheme (for --stdout / --no-color).
106
+ pub fn plain() -> Self {
107
+ Self {
108
+ c: Default::default(),
109
+ title: String::new(),
110
+ at: String::new(),
111
+ underline: String::new(),
112
+ subtitle: String::new(),
113
+ colon: String::new(),
114
+ info: String::new(),
115
+ ascii_bold: false,
116
+ }
117
+ }
118
+}
119
+
120
+impl Default for ColorScheme {
121
+ fn default() -> Self {
122
+ Self::from_colors(&[6, 6, 7, 1], true)
123
+ }
124
+}
125
+
126
+/// Generate color blocks matching neofetch's get_cols().
127
+/// Colors 0-7 use standard ANSI (fg+bg), colors 8+ use 256-color mode.
128
+/// Blocks are split into two rows: standard (0-7) and extended (8+).
129
+pub fn color_blocks(start: u8, end: u8, width: usize) -> Vec<String> {
130
+ let block = "\u{2588}".repeat(width); // █ repeated
81
131