summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-12-06 21:22:14 -0500
committerJesse Luehrs <doy@tozt.net>2021-12-06 21:22:14 -0500
commit611e2bde934fccf0b66df089965d18051c76d6a0 (patch)
tree767c09bd416fa6ffcd818aea6613a4b3be4f8fda
parent0f783d9f9fcc1df1d94d7229c126a03357ad528a (diff)
downloadnbsh-611e2bde934fccf0b66df089965d18051c76d6a0.tar.gz
nbsh-611e2bde934fccf0b66df089965d18051c76d6a0.zip
try to avoid displaying invalid data
-rw-r--r--Cargo.lock4
-rw-r--r--Cargo.toml4
-rw-r--r--src/history.rs92
3 files changed, 59 insertions, 41 deletions
diff --git a/Cargo.lock b/Cargo.lock
index dae4157..c3b8df9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -603,8 +603,6 @@ dependencies = [
[[package]]
name = "textmode"
version = "0.2.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6b3f31cee8570f79f5d8cbf6f375e1379f55551015d48dafbde9a974df1b3987"
dependencies = [
"blocking",
"futures-lite",
@@ -693,8 +691,6 @@ checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
[[package]]
name = "vt100"
version = "0.14.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "355ca5788c590a972ec74d0d8a2b7174919d7d6c149c9a481822eb8e99b5ac9b"
dependencies = [
"itoa",
"log",
diff --git a/Cargo.toml b/Cargo.toml
index c4ea4d8..e887c1d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -17,9 +17,9 @@ pty-process = { version = "0.1.1", features = ["backend-async-std"] }
signal-hook = "0.3.10"
signal-hook-async-std = "0.2.1"
terminal_size = "0.1.17"
-textmode = { version = "0.2.2", features = ["async"] }
+textmode = { path = "../textmode", version = "0.2.2", features = ["async"] }
unicode-width = "0.1.9"
users = "0.11.0"
-vt100 = "0.14.0"
+vt100 = { path = "../vt100-rust", version = "0.14.0" }
[features]
diff --git a/src/history.rs b/src/history.rs
index d20de80..34093c3 100644
--- a/src/history.rs
+++ b/src/history.rs
@@ -218,46 +218,60 @@ impl HistoryEntry {
out.write_str(&time);
out.write_str(" ");
out.reset_attributes();
- let last_row = self.lines(width, focused);
- if last_row > 5 {
- out.write(b"\r\n");
- out.set_fgcolor(textmode::color::BLUE);
- out.write(b"...");
+
+ if self.binary() {
+ let msg = b"This appears to be binary data. Fullscreen this entry to view anyway.";
+ let len: u16 = msg.len().try_into().unwrap();
+ out.move_to(
+ out.screen().cursor_position().0 + 1,
+ (width - len) / 2,
+ );
+ out.set_fgcolor(textmode::color::RED);
+ out.write(msg);
+ out.write(b"\x1b[?25l");
out.reset_attributes();
- }
- let mut out_row = out.screen().cursor_position().0 + 1;
- let screen = self.vt.screen();
- let pos = screen.cursor_position();
- let mut wrapped = false;
- let mut cursor_found = None;
- for (idx, row) in screen
- .rows_formatted(0, width)
- .enumerate()
- .take(last_row)
- .skip(last_row.saturating_sub(5))
- {
- let idx: u16 = idx.try_into().unwrap();
- out.write(b"\x1b[m");
- if !wrapped {
- out.write(format!("\x1b[{}H", out_row + 1).as_bytes());
+ } else {
+ let last_row = self.lines(width, focused);
+ if last_row > 5 {
+ out.write(b"\r\n");
+ out.set_fgcolor(textmode::color::BLUE);
+ out.write(b"...");
+ out.reset_attributes();
}
- out.write(&row);
- wrapped = screen.row_wrapped(idx);
- if pos.0 == idx {
- cursor_found = Some(out_row);
+ let mut out_row = out.screen().cursor_position().0 + 1;
+ let screen = self.vt.screen();
+ let pos = screen.cursor_position();
+ let mut wrapped = false;
+ let mut cursor_found = None;
+ for (idx, row) in screen
+ .rows_formatted(0, width)
+ .enumerate()
+ .take(last_row)
+ .skip(last_row.saturating_sub(5))
+ {
+ let idx: u16 = idx.try_into().unwrap();
+ out.write(b"\x1b[m");
+ if !wrapped {
+ out.write(format!("\x1b[{}H", out_row + 1).as_bytes());
+ }
+ out.write(&row);
+ wrapped = screen.row_wrapped(idx);
+ if pos.0 == idx {
+ cursor_found = Some(out_row);
+ }
+ out_row += 1;
}
- out_row += 1;
- }
- if focused {
- if let Some(row) = cursor_found {
- if screen.hide_cursor() {
- out.write(b"\x1b[?25l");
+ if focused {
+ if let Some(row) = cursor_found {
+ if screen.hide_cursor() {
+ out.write(b"\x1b[?25l");
+ } else {
+ out.write(b"\x1b[?25h");
+ out.move_to(row, pos.1);
+ }
} else {
- out.write(b"\x1b[?25h");
- out.move_to(row, pos.1);
+ out.write(b"\x1b[?25l");
}
- } else {
- out.write(b"\x1b[?25l");
}
}
out.reset_attributes();
@@ -295,7 +309,15 @@ impl HistoryEntry {
self.exit_info.is_none()
}
+ fn binary(&self) -> bool {
+ self.vt.screen().errors() > 5
+ }
+
fn lines(&self, width: u16, focused: bool) -> usize {
+ if self.binary() {
+ return 1;
+ }
+
let screen = self.vt.screen();
let mut last_row = 0;
for (idx, row) in screen.rows(0, width).enumerate() {