Created
June 7, 2021 09:30
-
-
Save q2p/f61f812882ceffb6156d5d3a3e9a1c73 to your computer and use it in GitHub Desktop.
Fancy console colors
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() { | |
table_1(); | |
table_2(); | |
} | |
fn format(codes:Vec<u8>, string:String) { | |
for i in codes { | |
print!("{}", esc(i)); | |
} | |
print!("{:^4}", string); | |
print!("{}", esc(0)); | |
} | |
fn esc(c:u8) -> String { | |
return format!("\x1b[{}m", c); | |
} | |
fn clear() { | |
for _ in 0..10 { | |
println!(); | |
} | |
} | |
fn table_1() { | |
for i in 0..110 { | |
print!("{}{:>4}{}", esc(i), i, esc(0)); | |
if i % 10 == 9 { | |
println!(); | |
} | |
} | |
println!(); | |
println!(); | |
} | |
fn table_2() { | |
for i in 0..=9 { | |
format(vec![i], i.to_string()); | |
for x in 40..=47 { | |
format(vec![i, x], x.to_string()); | |
} | |
println!(); | |
for y in 30..=37 { | |
format(vec![i, y], y.to_string()); | |
for x in 40..=47 { | |
format(vec![i, y, x], ":)".to_string()); | |
} | |
println!(); | |
} | |
println!(); | |
} | |
} | |
fn table_3() { | |
for i in 32..=126 { | |
let sym = String::from_utf8(vec![i]).unwrap_or(String::from("_")); | |
print!("{:>3} {} ", i, sym); | |
if i%8 == 7 { | |
println!(); | |
} | |
} | |
println!(); | |
} | |
fn table_4() { | |
for i in 0x20..=0xFFFF { | |
let c = i & 0xF; | |
if c == 0 { | |
print!("{:>3X}_ | ", i >> 4); | |
} | |
let sym = String::from_utf16(&[i]).unwrap_or(String::from("_")); | |
print!("{:X}={} ", i & 0xF, sym); | |
if c == 15 { | |
println!(); | |
} | |
} | |
println!(); | |
} | |
fn blind() { | |
let mut i:u8 = 0; | |
loop { | |
let c = 0x2800|i as u16; | |
let sym = String::from_utf16(&[c]).unwrap(); | |
println!("{:0X} {}", c, sym); | |
std::thread::sleep(std::time::Duration::from_millis(100)); | |
i = i.wrapping_add(1); | |
} | |
} | |
fn bricks() { | |
let syms = ['⠉', '⠛', '⠶', '⣤', '⣀', '⠀']; | |
let mut i:usize = 0; | |
let mut ss = String::with_capacity(256); | |
loop { | |
ss.push_str("\n\n\n\n"); | |
for j in 0..64 { | |
ss.push(syms[(i+j*(syms.len()-4)) % syms.len()]); | |
ss.push('\n'); | |
} | |
i+=1; | |
println!("{}", ss); | |
ss.clear(); | |
std::thread::sleep(std::time::Duration::from_millis(100)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment