mirror of
https://github.com/nushell/nushell
synced 2024-12-28 14:03:09 +00:00
Improve ansi handling
This commit is contained in:
parent
563fabfdca
commit
71ac03f287
2 changed files with 27 additions and 26 deletions
|
@ -25,8 +25,8 @@ chrono-humanize = "0.0.11"
|
||||||
byte-unit = "2.1.0"
|
byte-unit = "2.1.0"
|
||||||
ordered-float = {version = "1.0.2", features = ["serde"]}
|
ordered-float = {version = "1.0.2", features = ["serde"]}
|
||||||
prettyprint = "0.7.0"
|
prettyprint = "0.7.0"
|
||||||
futures-preview = { version = "0.3.0-alpha.16", features = ["compat", "io-compat"] }
|
futures-preview = { version = "=0.3.0-alpha.16", features = ["compat", "io-compat"] }
|
||||||
futures-sink-preview = "0.3.0-alpha.16"
|
futures-sink-preview = "=0.3.0-alpha.16"
|
||||||
futures_codec = "0.2.2"
|
futures_codec = "0.2.2"
|
||||||
term = "0.5.2"
|
term = "0.5.2"
|
||||||
bytes = "0.4.12"
|
bytes = "0.4.12"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crossterm::{cursor, terminal, Attribute, Color, Colored, RawScreen};
|
use crossterm::{cursor, terminal, Attribute, RawScreen};
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use nu::{serve_plugin, Args, CommandConfig, Plugin, ShellError, Value};
|
use nu::{serve_plugin, Args, CommandConfig, Plugin, ShellError, Value};
|
||||||
|
|
||||||
|
@ -52,17 +52,6 @@ fn view_binary(b: &[u8]) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
|
||||||
pub enum JoyButton {
|
|
||||||
A = 0,
|
|
||||||
B = 1,
|
|
||||||
Select = 2,
|
|
||||||
Start = 3,
|
|
||||||
Up = 4,
|
|
||||||
Down = 5,
|
|
||||||
Left = 6,
|
|
||||||
Right = 7,
|
|
||||||
}
|
|
||||||
pub struct Context {
|
pub struct Context {
|
||||||
pub width: usize,
|
pub width: usize,
|
||||||
pub height: usize,
|
pub height: usize,
|
||||||
|
@ -86,28 +75,40 @@ impl Context {
|
||||||
let cursor = cursor();
|
let cursor = cursor();
|
||||||
cursor.goto(0, 0)?;
|
cursor.goto(0, 0)?;
|
||||||
|
|
||||||
let mut prev_color = None;
|
let mut prev_color: Option<(u8,u8,u8)> = None;
|
||||||
|
let mut prev_count = 1;
|
||||||
|
|
||||||
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 => {
|
||||||
print!("{}", pixel.0);
|
prev_count += 1;
|
||||||
|
}
|
||||||
|
Some(c) => {
|
||||||
|
print!(
|
||||||
|
"{}",
|
||||||
|
ansi_term::Colour::RGB(c.0, c.1, c.2)
|
||||||
|
.paint((0..prev_count).map(|_| pixel.0).collect::<String>())
|
||||||
|
);
|
||||||
|
prev_color = Some(pixel.1);
|
||||||
|
prev_count = 1;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
prev_color = Some(pixel.1);
|
prev_color = Some(pixel.1);
|
||||||
print!(
|
prev_count = 1;
|
||||||
"{}{}",
|
|
||||||
Colored::Fg(Color::Rgb {
|
|
||||||
r: (pixel.1).0,
|
|
||||||
g: (pixel.1).1,
|
|
||||||
b: (pixel.1).2
|
|
||||||
}),
|
|
||||||
pixel.0
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if prev_count > 0 {
|
||||||
|
if let Some(color) = prev_color {
|
||||||
|
print!(
|
||||||
|
"{}",
|
||||||
|
ansi_term::Colour::RGB(color.0, color.1, color.2)
|
||||||
|
.paint((0..prev_count).map(|_| "@").collect::<String>())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
println!("{}", Attribute::Reset);
|
println!("{}", Attribute::Reset);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue