Created
July 16, 2026 17:16
-
-
Save kaleidawave/5dc3af58b733fcfb639c441825b0b00d to your computer and use it in GitHub Desktop.
24 bit colour terminal background printing. Has some bugs: why the first line has no background... why it takes a few runs in a clean terminal before it prints new lines...?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn main() { | |
| let colours: &[[u16; 3]] = &[ | |
| [204, 12, 56], | |
| [238, 15, 44], | |
| [255, 64, 32], | |
| [255, 101, 39], | |
| [254, 189, 56], | |
| [254, 242, 198] | |
| ]; | |
| for colour in colours { | |
| use std::fmt::Write; | |
| let mut buf = String::new(); | |
| let [r, g, b] = colour; | |
| let bright = (r + g + b) > 384; | |
| let _ = write!(&mut buf, "\u{1b}[48;2;{r};{g};{b}m"); | |
| if bright { | |
| let _ = write!(&mut buf, "\u{1b}[30m"); | |
| } | |
| let _ = writeln!(&mut buf); | |
| let _ = writeln!(&mut buf); | |
| let _ = writeln!(&mut buf, "{colour:?}"); | |
| print!("{buf}\u{1b}[0m"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment