Use pairs of buffer values to render braille
This commit is contained in:
parent
f76b5f4f5e
commit
ac4777e50c
@ -2,6 +2,7 @@ use crate::cpustats::get_cpu_usage;
|
||||
use crate::cpustats::get_clk_tck;
|
||||
use crate::ansiiescape;
|
||||
use crate::braille::braille_symbol;
|
||||
use crate::vectools::ValuePairs;
|
||||
|
||||
pub struct CpuUsageBuffer {
|
||||
clk_tck: u32,
|
||||
@ -48,6 +49,15 @@ fn cpu_usages_to_braille(a: u32, b: u32) -> u8 {
|
||||
a_braille + shift_braille_one_col(b_braille)
|
||||
}
|
||||
|
||||
fn max(a: u32, b: u32) -> u32 {
|
||||
if a > b {
|
||||
return a;
|
||||
}
|
||||
else {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
impl CpuUsageBuffer {
|
||||
pub fn new() -> Self {
|
||||
let first_value = get_cpu_usage();
|
||||
@ -73,9 +83,9 @@ impl CpuUsageBuffer {
|
||||
pub fn braille(&self) -> String {
|
||||
let mut out: String = String::new();
|
||||
for n in 0..(self.cpu_num()) {
|
||||
for u in &self.buffer {
|
||||
out += &cpu_usage_to_color(u[n]);
|
||||
out += &braille_symbol(cpu_usages_to_braille(u[n], u[n]));
|
||||
for u in ValuePairs::new(self.buffer.clone().into_iter()) {
|
||||
out += &cpu_usage_to_color(max(u.0[n], u.1[n]));
|
||||
out += &braille_symbol(cpu_usages_to_braille(u.0[n], u.1[n]));
|
||||
}
|
||||
out += &ansiiescape::reset();
|
||||
out += "\n";
|
||||
|
@ -2,3 +2,4 @@ pub mod ansiiescape;
|
||||
pub mod braille;
|
||||
pub mod cpustats;
|
||||
pub mod cpuusagebuffer;
|
||||
pub mod vectools;
|
||||
|
@ -2,11 +2,10 @@ use std::thread::sleep;
|
||||
use std::time;
|
||||
use fuedra_schwitzt::cpuusagebuffer::CpuUsageBuffer;
|
||||
use fuedra_schwitzt::ansiiescape::cursor_up;
|
||||
use fuedra_schwitzt::vectools;
|
||||
|
||||
|
||||
fn main() {
|
||||
|
||||
|
||||
// Init buffer
|
||||
let mut buffer = CpuUsageBuffer::new();
|
||||
|
||||
|
17
src/vectools.rs
Normal file
17
src/vectools.rs
Normal file
@ -0,0 +1,17 @@
|
||||
pub struct ValuePairs<I: Iterator> {
|
||||
iter: I,
|
||||
}
|
||||
|
||||
impl<I: Iterator> ValuePairs<I> {
|
||||
pub fn new(iter: I) -> ValuePairs<I> {
|
||||
ValuePairs { iter }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<I: Iterator> Iterator for ValuePairs<I> {
|
||||
type Item = (I::Item, I::Item);
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
Some((self.iter.next()?, self.iter.next()?))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user