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 ca4e6bc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/cursor/sys/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,12 @@ impl From<Handle> for ScreenBufferCursor {

#[cfg(test)]
mod tests {
use serial_test::serial;
use super::{
move_down, move_left, move_right, move_to, move_to_column, move_to_next_line,
move_to_previous_line, move_to_row, move_up, position, restore_position, save_position,
};
use crate::terminal::sys::temp_screen_buffer;
use serial_test::serial;

#[test]
#[serial]
Expand Down
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
1 change: 0 additions & 1 deletion src/style/types/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ mod tests {
}
}


#[cfg(test)]
#[cfg(feature = "serde")]
mod serde_tests {
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
12 changes: 5 additions & 7 deletions src/terminal/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@
pub use self::unix::supports_keyboard_enhancement;
#[cfg(unix)]
pub(crate) use self::unix::{
disable_raw_mode, enable_raw_mode, window_size, is_raw_mode_enabled, size,
disable_raw_mode, enable_raw_mode, is_raw_mode_enabled, size, window_size,
};
#[cfg(windows)]
#[cfg(feature = "events")]
pub use self::windows::supports_keyboard_enhancement;
#[cfg(windows)]
pub(crate) use self::windows::{
clear, disable_raw_mode, enable_raw_mode, window_size, is_raw_mode_enabled, scroll_down,
scroll_up, set_size, set_window_title, size,
};
#[cfg(all(windows, test))]
pub(crate) use self::windows::temp_screen_buffer;
#[cfg(windows)]
pub(crate) use self::windows::{
temp_screen_buffer,
clear, disable_raw_mode, enable_raw_mode, is_raw_mode_enabled, scroll_down, scroll_up,
set_size, set_window_title, size, window_size,
};

#[cfg(windows)]
Expand Down

0 comments on commit ca4e6bc

Please sign in to comment.