Compare commits

..

2 Commits

Author SHA1 Message Date
88e3f8c3be Move escape sequence to mod 2024-01-13 23:18:33 +01:00
9c82deb4aa Loop forever 2024-01-13 23:17:29 +01:00
2 changed files with 10 additions and 5 deletions

View File

@ -1,11 +1,15 @@
fn escape(s: String) -> String { fn escape(s: String) -> String {
format!("\x1b[{}m", s) format!("\x1b[{}", s)
} }
pub fn reset() -> String { pub fn reset() -> String {
escape("0".to_string()) escape("0m".to_string())
} }
pub fn color(r: u8, g: u8, b: u8) -> String { pub fn color(r: u8, g: u8, b: u8) -> String {
escape(format!("38;2;{};{};{}", r, g, b)) escape(format!("38;2;{};{};{}m", r, g, b))
}
pub fn cursor_up(lines: u32) -> String {
escape(format!("{}A", lines))
} }

View File

@ -1,6 +1,7 @@
use std::thread::sleep; use std::thread::sleep;
use std::time; use std::time;
use fuedra_schwitzt::cpuusagebuffer::CpuUsageBuffer; use fuedra_schwitzt::cpuusagebuffer::CpuUsageBuffer;
use fuedra_schwitzt::ansiiescape::cursor_up;
fn main() { fn main() {
@ -12,12 +13,12 @@ fn main() {
// Print buffer // Print buffer
print!("{}", buffer.braille()); print!("{}", buffer.braille());
for _ in 0..100 { loop {
// Push new cpu usage stats // Push new cpu usage stats
buffer.push(); buffer.push();
// Reset paint area // Reset paint area
print!("\x1b[{}A", buffer.cpu_num()); print!("{}", cursor_up(buffer.cpu_num().try_into().unwrap()));
// Print buffer // Print buffer
print!("{}", buffer.braille()); print!("{}", buffer.braille());