Skip to main content

rusty_bubbletea/
screen.rs

1//! Cleanroom Rust port of upstream Go source file: `screen.go`
2//! Upstream Target Tag / Version: `v2.0.8`
3//!
4//! <public-docs>
5//! # Screen Buffer & Window Size
6//!
7//! `WindowSizeMsg`, `clear_screen`, `ClearScreenMsg`, `ModeReportMsg`.
8//! </public-docs>
9
10use crate::model::Cmd;
11
12/// WindowSizeMsg is used to report the terminal size. It's sent to `update`
13/// once initially and then on every terminal resize. Note that Windows does not
14/// have support for reporting when resizes occur as it does not support the
15/// SIGWINCH signal.
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub struct WindowSizeMsg {
18    /// Width of terminal in columns.
19    pub width: usize,
20    /// Height of terminal in rows.
21    pub height: usize,
22}
23
24/// ClearScreenMsg is an internal message that signals to clear the screen.
25/// You can send a ClearScreenMsg with `clear_screen`.
26#[derive(Debug, Clone, Copy, PartialEq, Eq)]
27pub struct ClearScreenMsg;
28
29/// ClearScreen is a special command that tells the program to clear the screen
30/// before the next update. This can be used to move the cursor to the top left
31/// of the screen and clear visual clutter when the alt screen is not in use.
32///
33/// Note that it should never be necessary to call `clear_screen` for regular
34/// redraws.
35pub fn clear_screen() -> Cmd {
36    Some(Box::new(|| Some(Box::new(ClearScreenMsg))))
37}
38
39/// ModeReportMsg is a message that represents a mode report event (DECRPM).
40///
41/// This is sent by the terminal in response to a request for a terminal mode
42/// report (DECRQM). It indicates the current setting of a specific terminal
43/// mode like cursor visibility, mouse tracking, etc.
44///
45/// See: <https://vt100.net/docs/vt510-rm/DECRPM.html>
46#[derive(Debug, Clone, Copy, PartialEq, Eq)]
47pub struct ModeReportMsg {
48    /// Mode is the mode number.
49    pub mode: u32,
50    /// Value is the mode setting value.
51    pub value: u32,
52}