Skip to content

Commit

Permalink
Remove terminal bell from Command API
Browse files Browse the repository at this point in the history
  • Loading branch information
Piturnah committed Aug 5, 2023
1 parent 3df1f35 commit 372b9f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 30 deletions.
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
//!
Expand Down
45 changes: 17 additions & 28 deletions src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 372b9f4

Please sign in to comment.