summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2022-01-15 16:50:14 -0500
committerJesse Luehrs <doy@tozt.net>2022-01-15 16:50:14 -0500
commitfb8a568b7e359a36cec80d4e92602d0046a4249f (patch)
treecb0215e686efc6031cd53ca1341688987762bb2c
parent30e37c7f6e3e69fefc709b6be5bcfb3a647909fc (diff)
downloadnbsh-fb8a568b7e359a36cec80d4e92602d0046a4249f.tar.gz
nbsh-fb8a568b7e359a36cec80d4e92602d0046a4249f.zip
improve bell handling
-rw-r--r--src/shell/history/entry.rs68
-rw-r--r--src/shell/history/mod.rs2
2 files changed, 51 insertions, 19 deletions
diff --git a/src/shell/history/entry.rs b/src/shell/history/entry.rs
index b20321d..01aad8b 100644
--- a/src/shell/history/entry.rs
+++ b/src/shell/history/entry.rs
@@ -12,6 +12,9 @@ pub struct Entry {
vt: vt100::Parser,
audible_bell_state: usize,
visual_bell_state: usize,
+ audible_bell: bool,
+ visual_bell: bool,
+ real_bell_pending: bool,
fullscreen: Option<bool>,
input: async_std::channel::Sender<Vec<u8>>,
resize: async_std::channel::Sender<(u16, u16)>,
@@ -35,6 +38,9 @@ impl Entry {
vt: vt100::Parser::new(size.0, size.1, 0),
audible_bell_state: 0,
visual_bell_state: 0,
+ audible_bell: false,
+ visual_bell: false,
+ real_bell_pending: false,
input,
resize,
fullscreen: None,
@@ -44,7 +50,7 @@ impl Entry {
}
pub fn render(
- &self,
+ &mut self,
out: &mut impl textmode::Textmode,
idx: usize,
entry_count: usize,
@@ -71,6 +77,12 @@ impl Entry {
},
);
+ self.bell(out);
+ if focused {
+ self.audible_bell = false;
+ self.visual_bell = false;
+ }
+
set_bgcolor(out, idx, focused);
out.set_fgcolor(textmode::color::YELLOW);
let entry_count_width = format!("{}", entry_count + 1).len();
@@ -95,8 +107,13 @@ impl Entry {
}
out.reset_attributes();
- set_bgcolor(out, idx, focused);
+ if self.audible_bell || self.visual_bell {
+ out.set_bgcolor(textmode::Color::Rgb(64, 16, 16));
+ } else {
+ set_bgcolor(out, idx, focused);
+ }
out.write_str("$ ");
+ set_bgcolor(out, idx, focused);
let start = usize::from(out.screen().cursor_position().1);
let end = usize::from(size.1) - time.len() - 2;
let max_len = end - start;
@@ -203,22 +220,10 @@ impl Entry {
}
pub fn render_fullscreen(&mut self, out: &mut impl textmode::Textmode) {
- let screen = self.vt.screen();
- let new_audible_bell_state = screen.audible_bell_count();
- let new_visual_bell_state = screen.visual_bell_count();
-
- out.write(&screen.state_formatted());
-
- if self.audible_bell_state != new_audible_bell_state {
- out.write(b"\x07");
- self.audible_bell_state = new_audible_bell_state;
- }
-
- if self.visual_bell_state != new_visual_bell_state {
- out.write(b"\x1bg");
- self.visual_bell_state = new_visual_bell_state;
- }
-
+ out.write(&self.vt.screen().state_formatted());
+ self.bell(out);
+ self.audible_bell = false;
+ self.visual_bell = false;
out.reset_attributes();
}
@@ -241,6 +246,21 @@ impl Entry {
pub fn process(&mut self, input: &[u8]) {
self.vt.process(input);
+ let screen = self.vt.screen();
+
+ let new_audible_bell_state = screen.audible_bell_count();
+ if new_audible_bell_state != self.audible_bell_state {
+ self.audible_bell = true;
+ self.real_bell_pending = true;
+ self.audible_bell_state = new_audible_bell_state;
+ }
+
+ let new_visual_bell_state = screen.visual_bell_count();
+ if new_visual_bell_state != self.visual_bell_state {
+ self.visual_bell = true;
+ self.real_bell_pending = true;
+ self.visual_bell_state = new_visual_bell_state;
+ }
}
pub fn cmd(&self) -> &str {
@@ -334,6 +354,18 @@ impl Entry {
State::Exited(exit_info) => Some(exit_info),
}
}
+
+ fn bell(&mut self, out: &mut impl textmode::Textmode) {
+ if self.real_bell_pending {
+ if self.audible_bell {
+ out.write(b"\x07");
+ }
+ if self.visual_bell {
+ out.write(b"\x1bg");
+ }
+ self.real_bell_pending = false;
+ }
+ }
}
struct ExitInfo {
diff --git a/src/shell/history/mod.rs b/src/shell/history/mod.rs
index 19223ec..2863cad 100644
--- a/src/shell/history/mod.rs
+++ b/src/shell/history/mod.rs
@@ -29,7 +29,7 @@ impl History {
) -> anyhow::Result<()> {
let mut used_lines = repl_lines;
let mut cursor = None;
- for (idx, entry) in
+ for (idx, mut entry) in
self.visible(repl_lines, focus, scrolling).await.rev()
{
let focused = focus.map_or(false, |focus| idx == focus);