From 3df1f35eb253e4b687e03a4c366d20a5ee56af68 Mon Sep 17 00:00:00 2001 From: Peter Hebden <peterhebden6@gmail.com> Date: Sat, 29 Jul 2023 15:02:29 +0100 Subject: [PATCH 1/3] Add command for the terminal bell sound --- src/lib.rs | 3 ++- src/terminal.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 6c6e07f9..c9db6141 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -64,7 +64,8 @@ //! [`SetSize`](terminal/struct.SetSize.html), //! [`SetTitle`](terminal/struct.SetTitle.html), //! [`DisableLineWrap`](terminal/struct.DisableLineWrap.html), -//! [`EnableLineWrap`](terminal/struct.EnableLineWrap.html) +//! [`EnableLineWrap`](terminal/struct.EnableLineWrap.html), +//! [`Bell`](terminal/struct.Bell.html) //! - Alternate screen - [`EnterAlternateScreen`](terminal/struct.EnterAlternateScreen.html), //! [`LeaveAlternateScreen`](terminal/struct.LeaveAlternateScreen.html) //! diff --git a/src/terminal.rs b/src/terminal.rs index 49f413b1..8e1775a0 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -502,10 +502,38 @@ impl Command for EndSynchronizedUpdate { } } +/// A command that instructs the terminal to give an alert. +/// +/// # Notes +/// +/// Typically this is a bell sound, but may also be a visual alert such as a screen flash. +/// +/// See [Wikipedia](https://en.wikipedia.org/wiki/Bell_character). +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct Bell; + +impl Command for Bell { + fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result { + f.write_char(0x07 as char) + } + + #[cfg(windows)] + fn execute_winapi(&self) -> io::Result<()> { + Ok(()) + } + + #[cfg(windows)] + #[inline] + fn is_ansi_code_supported(&self) -> bool { + true + } +} + impl_display!(for ScrollUp); impl_display!(for ScrollDown); impl_display!(for SetSize); impl_display!(for Clear); +impl_display!(for Bell); #[cfg(test)] mod tests { From 372b9f4a7f57e2929190ab16ebecd5e29baf42e2 Mon Sep 17 00:00:00 2001 From: Peter Hebden <peterhebden6@gmail.com> Date: Sat, 5 Aug 2023 15:15:17 +0100 Subject: [PATCH 2/3] Remove terminal bell from Command API --- src/lib.rs | 3 +-- src/terminal.rs | 45 +++++++++++++++++---------------------------- 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c9db6141..6c6e07f9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -64,8 +64,7 @@ //! [`SetSize`](terminal/struct.SetSize.html), //! [`SetTitle`](terminal/struct.SetTitle.html), //! [`DisableLineWrap`](terminal/struct.DisableLineWrap.html), -//! [`EnableLineWrap`](terminal/struct.EnableLineWrap.html), -//! [`Bell`](terminal/struct.Bell.html) +//! [`EnableLineWrap`](terminal/struct.EnableLineWrap.html) //! - Alternate screen - [`EnterAlternateScreen`](terminal/struct.EnterAlternateScreen.html), //! [`LeaveAlternateScreen`](terminal/struct.LeaveAlternateScreen.html) //! diff --git a/src/terminal.rs b/src/terminal.rs index 8e1775a0..849ef0c2 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -154,6 +154,23 @@ pub fn window_size() -> io::Result<WindowSize> { sys::window_size() } +/// Instructs the terminal to give an alert. +/// +/// # Notes +/// +/// Typically this is a bell sound, but may also be a visual alert such as a screen flash. +/// +/// See [Wikipedia](https://en.wikipedia.org/wiki/Bell_character). +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct Bell; + +impl fmt::Display for Bell { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + use fmt::Write; + f.write_char(0x07 as char) + } +} + /// Disables line wrapping. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct DisableLineWrap; @@ -502,38 +519,10 @@ impl Command for EndSynchronizedUpdate { } } -/// A command that instructs the terminal to give an alert. -/// -/// # Notes -/// -/// Typically this is a bell sound, but may also be a visual alert such as a screen flash. -/// -/// See [Wikipedia](https://en.wikipedia.org/wiki/Bell_character). -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub struct Bell; - -impl Command for Bell { - fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result { - f.write_char(0x07 as char) - } - - #[cfg(windows)] - fn execute_winapi(&self) -> io::Result<()> { - Ok(()) - } - - #[cfg(windows)] - #[inline] - fn is_ansi_code_supported(&self) -> bool { - true - } -} - impl_display!(for ScrollUp); impl_display!(for ScrollDown); impl_display!(for SetSize); impl_display!(for Clear); -impl_display!(for Bell); #[cfg(test)] mod tests { From b99f51063309fb69c830b36915fcf8a1de71a760 Mon Sep 17 00:00:00 2001 From: Peter Hebden <peterhebden6@gmail.com> Date: Mon, 29 Jul 2024 16:05:55 +0100 Subject: [PATCH 3/3] Change terminal bell to function api --- src/terminal.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/terminal.rs b/src/terminal.rs index 849ef0c2..2a45c673 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -161,14 +161,8 @@ pub fn window_size() -> io::Result<WindowSize> { /// Typically this is a bell sound, but may also be a visual alert such as a screen flash. /// /// See [Wikipedia](https://en.wikipedia.org/wiki/Bell_character). -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub struct Bell; - -impl fmt::Display for Bell { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - use fmt::Write; - f.write_char(0x07 as char) - } +pub fn bell() { + print!("{}", 0x07 as char); } /// Disables line wrapping.