added a slight debounce to bell bytes sent to the terminal

This commit is contained in:
2026-03-06 00:46:43 -05:00
parent e31e27f935
commit 5d827c7654
3 changed files with 27 additions and 11 deletions

View File

@@ -223,9 +223,9 @@ fn shed_interactive(args: ShedArgs) -> ShResult<()> {
readline.reset_active_widget(false)?; readline.reset_active_widget(false)?;
} }
ShErrKind::CleanExit(code) => { ShErrKind::CleanExit(code) => {
QUIT_CODE.store(*code, Ordering::SeqCst); QUIT_CODE.store(*code, Ordering::SeqCst);
return Ok(()); return Ok(());
} }
_ => e.print_error(), _ => e.print_error(),
} }
} }

View File

@@ -313,7 +313,7 @@ impl Dispatcher {
Ok(()) Ok(())
} }
fn exec_subsh(&mut self, subsh: Node) -> ShResult<()> { fn exec_subsh(&mut self, subsh: Node) -> ShResult<()> {
let blame = subsh.get_span().clone(); let _blame = subsh.get_span().clone();
let NdRule::Command { assignments, argv } = subsh.class else { let NdRule::Command { assignments, argv } = subsh.class else {
unreachable!() unreachable!()
}; };

View File

@@ -4,7 +4,7 @@ use std::{
fmt::{Debug, Write}, fmt::{Debug, Write},
io::{BufRead, BufReader, Read}, io::{BufRead, BufReader, Read},
os::fd::{AsFd, BorrowedFd, RawFd}, os::fd::{AsFd, BorrowedFd, RawFd},
sync::Arc, sync::Arc, time::Instant,
}; };
use nix::{ use nix::{
@@ -822,6 +822,7 @@ impl Default for Layout {
} }
pub struct TermWriter { pub struct TermWriter {
last_bell: Option<Instant>,
out: RawFd, out: RawFd,
pub t_cols: Col, // terminal width pub t_cols: Col, // terminal width
buffer: String, buffer: String,
@@ -831,6 +832,7 @@ impl TermWriter {
pub fn new(out: RawFd) -> Self { pub fn new(out: RawFd) -> Self {
let (t_cols, _) = get_win_size(out); let (t_cols, _) = get_win_size(out);
Self { Self {
last_bell: None,
out, out,
t_cols, t_cols,
buffer: String::new(), buffer: String::new(),
@@ -1067,10 +1069,24 @@ impl LineWriter for TermWriter {
Ok(()) Ok(())
} }
fn send_bell(&mut self) -> ShResult<()> { fn send_bell(&mut self) -> ShResult<()> {
if read_shopts(|o| o.core.bell_enabled) { if read_shopts(|o| o.core.bell_enabled) {
self.flush_write("\x07")?; // we use a cooldown because I don't like having my ears assaulted by 1 million bells
} // whenever i finish clearing the line using backspace.
Ok(()) let now = Instant::now();
}
// surprisingly, a fixed cooldown like '100' is actually more annoying than 1 million bells.
// I've found this range of 50-150 to be the best balance
let cooldown = rand::random_range(50..150);
let should_send = match self.last_bell {
None => true,
Some(time) => now.duration_since(time).as_millis() > cooldown,
};
if should_send {
self.flush_write("\x07")?;
self.last_bell = Some(now);
}
}
Ok(())
}
} }