diff --git a/CHANGELOG.md b/CHANGELOG.md index bef60bc..0305201 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,17 +13,6 @@ Procedure when bumping the version number: ## Unreleased -## v0.3.4 - 2025-03-8 - -### Added -- `Frame::set_bell` to print a bell character when the frame is displayed -- `widgets::bell` - -## v0.3.3 - 2025-02-28 - -### Fixed -- Rendering glitches in unicode-based with estimation - ## v0.3.2 - 2025-02-23 ### Added diff --git a/Cargo.toml b/Cargo.toml index 22967fc..af2b654 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "toss" -version = "0.3.4" +version = "0.3.2" edition = "2021" [dependencies] diff --git a/src/frame.rs b/src/frame.rs index e42ba6b..03fbb04 100644 --- a/src/frame.rs +++ b/src/frame.rs @@ -8,7 +8,6 @@ pub struct Frame { pub(crate) widthdb: WidthDb, pub(crate) buffer: Buffer, pub(crate) title: Option, - pub(crate) bell: bool, } impl Frame { @@ -49,10 +48,6 @@ impl Frame { self.title = title; } - pub fn set_bell(&mut self, bell: bool) { - self.bell = bell; - } - pub fn widthdb(&mut self) -> &mut WidthDb { &mut self.widthdb } diff --git a/src/terminal.rs b/src/terminal.rs index 07fe686..c26b0fc 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -8,7 +8,7 @@ use crossterm::event::{ DisableBracketedPaste, EnableBracketedPaste, KeyboardEnhancementFlags, PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags, }; -use crossterm::style::{Print, PrintStyledContent, StyledContent}; +use crossterm::style::{PrintStyledContent, StyledContent}; use crossterm::terminal::{ BeginSynchronizedUpdate, Clear, ClearType, EndSynchronizedUpdate, EnterAlternateScreen, LeaveAlternateScreen, SetTitle, @@ -274,7 +274,6 @@ impl Terminal { self.draw_differences()?; self.update_cursor()?; self.update_title()?; - self.ring_bell()?; Ok(()) } @@ -316,12 +315,4 @@ impl Terminal { } Ok(()) } - - fn ring_bell(&mut self) -> io::Result<()> { - if self.frame.bell { - self.out.queue(Print('\x07'))?; - } - self.frame.bell = false; - Ok(()) - } } diff --git a/src/widgets.rs b/src/widgets.rs index cbbff7c..28b44d8 100644 --- a/src/widgets.rs +++ b/src/widgets.rs @@ -1,5 +1,4 @@ pub mod background; -pub mod bell; pub mod border; pub mod boxed; pub mod cursor; @@ -17,7 +16,6 @@ pub mod text; pub mod title; pub use background::*; -pub use bell::*; pub use border::*; pub use boxed::*; pub use cursor::*; diff --git a/src/widgets/bell.rs b/src/widgets/bell.rs deleted file mode 100644 index b37fb67..0000000 --- a/src/widgets/bell.rs +++ /dev/null @@ -1,55 +0,0 @@ -use crate::{Frame, Size, Widget, WidthDb}; - -/////////// -// State // -/////////// - -#[derive(Debug, Default, Clone)] -pub struct BellState { - // Whether the bell should be rung the next time the widget is displayed. - pub ring: bool, -} - -impl BellState { - pub fn new() -> Self { - Self::default() - } - - pub fn widget(&mut self) -> Bell<'_> { - Bell { state: self } - } -} - -//////////// -// Widget // -//////////// - -#[derive(Debug)] -pub struct Bell<'a> { - state: &'a mut BellState, -} - -impl Bell<'_> { - pub fn state(&mut self) -> &mut BellState { - self.state - } -} - -impl Widget for Bell<'_> { - fn size( - &self, - _widthdb: &mut WidthDb, - _max_width: Option, - _max_height: Option, - ) -> Result { - Ok(Size::ZERO) - } - - fn draw(self, frame: &mut Frame) -> Result<(), E> { - if self.state.ring { - frame.set_bell(true); - self.state.ring = false - } - Ok(()) - } -} diff --git a/src/widthdb.rs b/src/widthdb.rs index fe5a26e..bb21ef6 100644 --- a/src/widthdb.rs +++ b/src/widthdb.rs @@ -88,10 +88,10 @@ impl WidthDb { .try_into() .unwrap_or(u8::MAX), - // The unicode width crate considers control chars to have a width - // of 1 even though they usually have a width of 0 when displayed. + // The unicode width crate considers newlines to have a width of 1 + // while the rendering code expects it to have a width of 0. WidthEstimationMethod::Unicode => grapheme - .split(|c: char| c.is_ascii_control()) + .split('\n') .map(|s| s.width()) .sum::() .try_into()