mirror of
https://github.com/nushell/nushell.git
synced 2025-05-30 06:39:33 +02:00
Fix binary view for better approx
This commit is contained in:
parent
5ec5167cb9
commit
a3f628427f
@ -75,9 +75,56 @@ impl Context {
|
|||||||
let cursor = cursor();
|
let cursor = cursor();
|
||||||
cursor.goto(0, 0)?;
|
cursor.goto(0, 0)?;
|
||||||
|
|
||||||
let mut prev_color: Option<(u8, u8, u8)> = None;
|
let mut prev_fg: Option<(u8, u8, u8)> = None;
|
||||||
|
let mut prev_bg: Option<(u8, u8, u8)> = None;
|
||||||
let mut prev_count = 1;
|
let mut prev_count = 1;
|
||||||
|
|
||||||
|
let mut pos = 0;
|
||||||
|
let fb_len = self.frame_buffer.len();
|
||||||
|
while pos < (fb_len - self.width) {
|
||||||
|
let top_pixel = self.frame_buffer[pos].1;
|
||||||
|
let bottom_pixel = self.frame_buffer[pos + self.width].1;
|
||||||
|
|
||||||
|
match (prev_fg, prev_bg) {
|
||||||
|
(Some(c), Some(d)) if c == top_pixel && d == bottom_pixel => {
|
||||||
|
prev_count += 1;
|
||||||
|
}
|
||||||
|
(Some(c), Some(d)) => {
|
||||||
|
print!(
|
||||||
|
"{}",
|
||||||
|
ansi_term::Colour::RGB(c.0, c.1, c.2)
|
||||||
|
.on(ansi_term::Colour::RGB(d.0, d.1, d.2,))
|
||||||
|
.paint((0..prev_count).map(|_| "▀").collect::<String>())
|
||||||
|
);
|
||||||
|
prev_fg = Some(top_pixel);
|
||||||
|
prev_bg = Some(bottom_pixel);
|
||||||
|
prev_count = 1;
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
prev_fg = Some(top_pixel);
|
||||||
|
prev_bg = Some(bottom_pixel);
|
||||||
|
prev_count = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pos += 1;
|
||||||
|
if pos % self.width == 0 {
|
||||||
|
pos += self.width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if prev_count > 0 {
|
||||||
|
match (prev_fg, prev_bg) {
|
||||||
|
(Some(c), Some(d)) => {
|
||||||
|
print!(
|
||||||
|
"{}",
|
||||||
|
ansi_term::Colour::RGB(c.0, c.1, c.2)
|
||||||
|
.on(ansi_term::Colour::RGB(d.0, d.1, d.2,))
|
||||||
|
.paint((0..prev_count).map(|_| "▀").collect::<String>())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
for pixel in &self.frame_buffer {
|
for pixel in &self.frame_buffer {
|
||||||
match prev_color {
|
match prev_color {
|
||||||
Some(c) if c == pixel.1 => {
|
Some(c) if c == pixel.1 => {
|
||||||
@ -104,11 +151,11 @@ impl Context {
|
|||||||
print!(
|
print!(
|
||||||
"{}",
|
"{}",
|
||||||
ansi_term::Colour::RGB(color.0, color.1, color.2)
|
ansi_term::Colour::RGB(color.0, color.1, color.2)
|
||||||
.paint((0..prev_count).map(|_| "@").collect::<String>())
|
.paint((0..prev_count).map(|_| "▄").collect::<String>())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
println!("{}", Attribute::Reset);
|
println!("{}", Attribute::Reset);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -122,7 +169,7 @@ impl Context {
|
|||||||
cursor.hide()?;
|
cursor.hide()?;
|
||||||
|
|
||||||
self.width = terminal_size.0 as usize + 1;
|
self.width = terminal_size.0 as usize + 1;
|
||||||
self.height = terminal_size.1 as usize;
|
self.height = terminal_size.1 as usize * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user