Compare commits
3 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 57aa8c5930 | |||
| e3af509358 | |||
| 89b4595ed9 |
6 changed files with 79 additions and 2 deletions
|
|
@ -13,6 +13,12 @@ Procedure when bumping the version number:
|
||||||
|
|
||||||
## Unreleased
|
## 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
|
## v0.3.3 - 2025-02-28
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "toss"
|
name = "toss"
|
||||||
version = "0.3.3"
|
version = "0.3.4"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ pub struct Frame {
|
||||||
pub(crate) widthdb: WidthDb,
|
pub(crate) widthdb: WidthDb,
|
||||||
pub(crate) buffer: Buffer,
|
pub(crate) buffer: Buffer,
|
||||||
pub(crate) title: Option<String>,
|
pub(crate) title: Option<String>,
|
||||||
|
pub(crate) bell: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Frame {
|
impl Frame {
|
||||||
|
|
@ -48,6 +49,10 @@ impl Frame {
|
||||||
self.title = title;
|
self.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_bell(&mut self, bell: bool) {
|
||||||
|
self.bell = bell;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn widthdb(&mut self) -> &mut WidthDb {
|
pub fn widthdb(&mut self) -> &mut WidthDb {
|
||||||
&mut self.widthdb
|
&mut self.widthdb
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ use crossterm::event::{
|
||||||
DisableBracketedPaste, EnableBracketedPaste, KeyboardEnhancementFlags,
|
DisableBracketedPaste, EnableBracketedPaste, KeyboardEnhancementFlags,
|
||||||
PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags,
|
PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags,
|
||||||
};
|
};
|
||||||
use crossterm::style::{PrintStyledContent, StyledContent};
|
use crossterm::style::{Print, PrintStyledContent, StyledContent};
|
||||||
use crossterm::terminal::{
|
use crossterm::terminal::{
|
||||||
BeginSynchronizedUpdate, Clear, ClearType, EndSynchronizedUpdate, EnterAlternateScreen,
|
BeginSynchronizedUpdate, Clear, ClearType, EndSynchronizedUpdate, EnterAlternateScreen,
|
||||||
LeaveAlternateScreen, SetTitle,
|
LeaveAlternateScreen, SetTitle,
|
||||||
|
|
@ -274,6 +274,7 @@ impl Terminal {
|
||||||
self.draw_differences()?;
|
self.draw_differences()?;
|
||||||
self.update_cursor()?;
|
self.update_cursor()?;
|
||||||
self.update_title()?;
|
self.update_title()?;
|
||||||
|
self.ring_bell()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -315,4 +316,12 @@ impl Terminal {
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn ring_bell(&mut self) -> io::Result<()> {
|
||||||
|
if self.frame.bell {
|
||||||
|
self.out.queue(Print('\x07'))?;
|
||||||
|
}
|
||||||
|
self.frame.bell = false;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
pub mod background;
|
pub mod background;
|
||||||
|
pub mod bell;
|
||||||
pub mod border;
|
pub mod border;
|
||||||
pub mod boxed;
|
pub mod boxed;
|
||||||
pub mod cursor;
|
pub mod cursor;
|
||||||
|
|
@ -16,6 +17,7 @@ pub mod text;
|
||||||
pub mod title;
|
pub mod title;
|
||||||
|
|
||||||
pub use background::*;
|
pub use background::*;
|
||||||
|
pub use bell::*;
|
||||||
pub use border::*;
|
pub use border::*;
|
||||||
pub use boxed::*;
|
pub use boxed::*;
|
||||||
pub use cursor::*;
|
pub use cursor::*;
|
||||||
|
|
|
||||||
55
src/widgets/bell.rs
Normal file
55
src/widgets/bell.rs
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
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<E> Widget<E> for Bell<'_> {
|
||||||
|
fn size(
|
||||||
|
&self,
|
||||||
|
_widthdb: &mut WidthDb,
|
||||||
|
_max_width: Option<u16>,
|
||||||
|
_max_height: Option<u16>,
|
||||||
|
) -> Result<Size, E> {
|
||||||
|
Ok(Size::ZERO)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw(self, frame: &mut Frame) -> Result<(), E> {
|
||||||
|
if self.state.ring {
|
||||||
|
frame.set_bell(true);
|
||||||
|
self.state.ring = false
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue