Skip to main content

Screen

Struct Screen 

Source
pub struct Screen { /* private fields */ }
Expand description

Main screen interface

Implementations§

Source§

impl Screen

Source

pub fn init() -> Result<Self>

Initialize the screen

Examples found in repository?
examples/text_input.rs (line 4)
3fn main() -> tv::Result<()> {
4    let mut scr = Screen::init()?;
5    scr.set_cursor_style(5)?; // blinking bar
6    scr.cursor_visible(true)?;
7
8    let mut input = String::new();
9    let mut cursor = 0usize;
10    let label = "Name: ";
11
12    loop {
13        scr.clear()?;
14
15        // Title
16        scr.set_foreground(Color::rgb(139, 233, 253))?;
17        scr.add_attribute(Attr::BOLD)?;
18        scr.move_print(1, 2, "Text Input Example")?;
19        scr.remove_attribute(Attr::BOLD)?;
20
21        // Label
22        scr.set_foreground(Color::rgb(98, 114, 164))?;
23        scr.move_print(3, 2, label)?;
24
25        // Input text
26        scr.set_foreground(Color::rgb(248, 248, 242))?;
27        scr.print(&input)?;
28
29        // Position cursor inside the input
30        scr.move_cursor(3, (2 + label.len() + cursor) as u16)?;
31
32        // Hint
33        scr.set_foreground(Color::rgb(98, 114, 164))?;
34        scr.move_print(5, 2, "Type text, use ←/→ to move, Ctrl+Q to quit")?;
35
36        // Preview
37        if !input.is_empty() {
38            scr.set_foreground(Color::rgb(80, 250, 123))?;
39            scr.move_print(7, 2, &format!("Hello, {}!", input))?;
40        }
41
42        let key = scr.get_char()?;
43        match key {
44            Key::Ctrl('q') => break,
45            Key::Char(ch) => {
46                input.insert(cursor, ch);
47                cursor += 1;
48            }
49            Key::Backspace => {
50                if cursor > 0 {
51                    cursor -= 1;
52                    input.remove(cursor);
53                }
54            }
55            Key::Delete => {
56                if cursor < input.len() {
57                    input.remove(cursor);
58                }
59            }
60            Key::Left => {
61                if cursor > 0 {
62                    cursor -= 1;
63                }
64            }
65            Key::Right => {
66                if cursor < input.len() {
67                    cursor += 1;
68                }
69            }
70            Key::Home => cursor = 0,
71            Key::End => cursor = input.len(),
72            _ => {}
73        }
74    }
75
76    scr.set_cursor_style(0)?;
77    scr.endwin()?;
78    Ok(())
79}
Source

pub fn endwin(self) -> Result<()>

Clean up and restore terminal

Examples found in repository?
examples/text_input.rs (line 77)
3fn main() -> tv::Result<()> {
4    let mut scr = Screen::init()?;
5    scr.set_cursor_style(5)?; // blinking bar
6    scr.cursor_visible(true)?;
7
8    let mut input = String::new();
9    let mut cursor = 0usize;
10    let label = "Name: ";
11
12    loop {
13        scr.clear()?;
14
15        // Title
16        scr.set_foreground(Color::rgb(139, 233, 253))?;
17        scr.add_attribute(Attr::BOLD)?;
18        scr.move_print(1, 2, "Text Input Example")?;
19        scr.remove_attribute(Attr::BOLD)?;
20
21        // Label
22        scr.set_foreground(Color::rgb(98, 114, 164))?;
23        scr.move_print(3, 2, label)?;
24
25        // Input text
26        scr.set_foreground(Color::rgb(248, 248, 242))?;
27        scr.print(&input)?;
28
29        // Position cursor inside the input
30        scr.move_cursor(3, (2 + label.len() + cursor) as u16)?;
31
32        // Hint
33        scr.set_foreground(Color::rgb(98, 114, 164))?;
34        scr.move_print(5, 2, "Type text, use ←/→ to move, Ctrl+Q to quit")?;
35
36        // Preview
37        if !input.is_empty() {
38            scr.set_foreground(Color::rgb(80, 250, 123))?;
39            scr.move_print(7, 2, &format!("Hello, {}!", input))?;
40        }
41
42        let key = scr.get_char()?;
43        match key {
44            Key::Ctrl('q') => break,
45            Key::Char(ch) => {
46                input.insert(cursor, ch);
47                cursor += 1;
48            }
49            Key::Backspace => {
50                if cursor > 0 {
51                    cursor -= 1;
52                    input.remove(cursor);
53                }
54            }
55            Key::Delete => {
56                if cursor < input.len() {
57                    input.remove(cursor);
58                }
59            }
60            Key::Left => {
61                if cursor > 0 {
62                    cursor -= 1;
63                }
64            }
65            Key::Right => {
66                if cursor < input.len() {
67                    cursor += 1;
68                }
69            }
70            Key::Home => cursor = 0,
71            Key::End => cursor = input.len(),
72            _ => {}
73        }
74    }
75
76    scr.set_cursor_style(0)?;
77    scr.endwin()?;
78    Ok(())
79}
Source

pub fn get_size(&self) -> Result<(u16, u16)>

Get terminal size (rows, cols)

Source

pub fn move_cursor(&mut self, y: u16, x: u16) -> Result<()>

Move cursor to position (y, x)

Examples found in repository?
examples/text_input.rs (line 30)
3fn main() -> tv::Result<()> {
4    let mut scr = Screen::init()?;
5    scr.set_cursor_style(5)?; // blinking bar
6    scr.cursor_visible(true)?;
7
8    let mut input = String::new();
9    let mut cursor = 0usize;
10    let label = "Name: ";
11
12    loop {
13        scr.clear()?;
14
15        // Title
16        scr.set_foreground(Color::rgb(139, 233, 253))?;
17        scr.add_attribute(Attr::BOLD)?;
18        scr.move_print(1, 2, "Text Input Example")?;
19        scr.remove_attribute(Attr::BOLD)?;
20
21        // Label
22        scr.set_foreground(Color::rgb(98, 114, 164))?;
23        scr.move_print(3, 2, label)?;
24
25        // Input text
26        scr.set_foreground(Color::rgb(248, 248, 242))?;
27        scr.print(&input)?;
28
29        // Position cursor inside the input
30        scr.move_cursor(3, (2 + label.len() + cursor) as u16)?;
31
32        // Hint
33        scr.set_foreground(Color::rgb(98, 114, 164))?;
34        scr.move_print(5, 2, "Type text, use ←/→ to move, Ctrl+Q to quit")?;
35
36        // Preview
37        if !input.is_empty() {
38            scr.set_foreground(Color::rgb(80, 250, 123))?;
39            scr.move_print(7, 2, &format!("Hello, {}!", input))?;
40        }
41
42        let key = scr.get_char()?;
43        match key {
44            Key::Ctrl('q') => break,
45            Key::Char(ch) => {
46                input.insert(cursor, ch);
47                cursor += 1;
48            }
49            Key::Backspace => {
50                if cursor > 0 {
51                    cursor -= 1;
52                    input.remove(cursor);
53                }
54            }
55            Key::Delete => {
56                if cursor < input.len() {
57                    input.remove(cursor);
58                }
59            }
60            Key::Left => {
61                if cursor > 0 {
62                    cursor -= 1;
63                }
64            }
65            Key::Right => {
66                if cursor < input.len() {
67                    cursor += 1;
68                }
69            }
70            Key::Home => cursor = 0,
71            Key::End => cursor = input.len(),
72            _ => {}
73        }
74    }
75
76    scr.set_cursor_style(0)?;
77    scr.endwin()?;
78    Ok(())
79}
Source

pub fn print(&mut self, text: &str) -> Result<()>

Print text at current cursor position. Advances the cursor by the text’s display width (cells), not its byte length — so multi-byte graphemes like │ or 中 don’t leave the cell grid out of sync with the terminal’s cursor.

Examples found in repository?
examples/text_input.rs (line 27)
3fn main() -> tv::Result<()> {
4    let mut scr = Screen::init()?;
5    scr.set_cursor_style(5)?; // blinking bar
6    scr.cursor_visible(true)?;
7
8    let mut input = String::new();
9    let mut cursor = 0usize;
10    let label = "Name: ";
11
12    loop {
13        scr.clear()?;
14
15        // Title
16        scr.set_foreground(Color::rgb(139, 233, 253))?;
17        scr.add_attribute(Attr::BOLD)?;
18        scr.move_print(1, 2, "Text Input Example")?;
19        scr.remove_attribute(Attr::BOLD)?;
20
21        // Label
22        scr.set_foreground(Color::rgb(98, 114, 164))?;
23        scr.move_print(3, 2, label)?;
24
25        // Input text
26        scr.set_foreground(Color::rgb(248, 248, 242))?;
27        scr.print(&input)?;
28
29        // Position cursor inside the input
30        scr.move_cursor(3, (2 + label.len() + cursor) as u16)?;
31
32        // Hint
33        scr.set_foreground(Color::rgb(98, 114, 164))?;
34        scr.move_print(5, 2, "Type text, use ←/→ to move, Ctrl+Q to quit")?;
35
36        // Preview
37        if !input.is_empty() {
38            scr.set_foreground(Color::rgb(80, 250, 123))?;
39            scr.move_print(7, 2, &format!("Hello, {}!", input))?;
40        }
41
42        let key = scr.get_char()?;
43        match key {
44            Key::Ctrl('q') => break,
45            Key::Char(ch) => {
46                input.insert(cursor, ch);
47                cursor += 1;
48            }
49            Key::Backspace => {
50                if cursor > 0 {
51                    cursor -= 1;
52                    input.remove(cursor);
53                }
54            }
55            Key::Delete => {
56                if cursor < input.len() {
57                    input.remove(cursor);
58                }
59            }
60            Key::Left => {
61                if cursor > 0 {
62                    cursor -= 1;
63                }
64            }
65            Key::Right => {
66                if cursor < input.len() {
67                    cursor += 1;
68                }
69            }
70            Key::Home => cursor = 0,
71            Key::End => cursor = input.len(),
72            _ => {}
73        }
74    }
75
76    scr.set_cursor_style(0)?;
77    scr.endwin()?;
78    Ok(())
79}
Source

pub fn move_print(&mut self, y: u16, x: u16, text: &str) -> Result<()>

Move cursor and print (like mvprintw)

Examples found in repository?
examples/text_input.rs (line 18)
3fn main() -> tv::Result<()> {
4    let mut scr = Screen::init()?;
5    scr.set_cursor_style(5)?; // blinking bar
6    scr.cursor_visible(true)?;
7
8    let mut input = String::new();
9    let mut cursor = 0usize;
10    let label = "Name: ";
11
12    loop {
13        scr.clear()?;
14
15        // Title
16        scr.set_foreground(Color::rgb(139, 233, 253))?;
17        scr.add_attribute(Attr::BOLD)?;
18        scr.move_print(1, 2, "Text Input Example")?;
19        scr.remove_attribute(Attr::BOLD)?;
20
21        // Label
22        scr.set_foreground(Color::rgb(98, 114, 164))?;
23        scr.move_print(3, 2, label)?;
24
25        // Input text
26        scr.set_foreground(Color::rgb(248, 248, 242))?;
27        scr.print(&input)?;
28
29        // Position cursor inside the input
30        scr.move_cursor(3, (2 + label.len() + cursor) as u16)?;
31
32        // Hint
33        scr.set_foreground(Color::rgb(98, 114, 164))?;
34        scr.move_print(5, 2, "Type text, use ←/→ to move, Ctrl+Q to quit")?;
35
36        // Preview
37        if !input.is_empty() {
38            scr.set_foreground(Color::rgb(80, 250, 123))?;
39            scr.move_print(7, 2, &format!("Hello, {}!", input))?;
40        }
41
42        let key = scr.get_char()?;
43        match key {
44            Key::Ctrl('q') => break,
45            Key::Char(ch) => {
46                input.insert(cursor, ch);
47                cursor += 1;
48            }
49            Key::Backspace => {
50                if cursor > 0 {
51                    cursor -= 1;
52                    input.remove(cursor);
53                }
54            }
55            Key::Delete => {
56                if cursor < input.len() {
57                    input.remove(cursor);
58                }
59            }
60            Key::Left => {
61                if cursor > 0 {
62                    cursor -= 1;
63                }
64            }
65            Key::Right => {
66                if cursor < input.len() {
67                    cursor += 1;
68                }
69            }
70            Key::Home => cursor = 0,
71            Key::End => cursor = input.len(),
72            _ => {}
73        }
74    }
75
76    scr.set_cursor_style(0)?;
77    scr.endwin()?;
78    Ok(())
79}
Source

pub fn add_char(&mut self, ch: char) -> Result<()>

Add a single character

Source

pub fn move_add_char(&mut self, y: u16, x: u16, ch: char) -> Result<()>

Move cursor and add character

Source

pub fn add_attribute(&mut self, attr: Attr) -> Result<()>

Turn on attributes

Examples found in repository?
examples/text_input.rs (line 17)
3fn main() -> tv::Result<()> {
4    let mut scr = Screen::init()?;
5    scr.set_cursor_style(5)?; // blinking bar
6    scr.cursor_visible(true)?;
7
8    let mut input = String::new();
9    let mut cursor = 0usize;
10    let label = "Name: ";
11
12    loop {
13        scr.clear()?;
14
15        // Title
16        scr.set_foreground(Color::rgb(139, 233, 253))?;
17        scr.add_attribute(Attr::BOLD)?;
18        scr.move_print(1, 2, "Text Input Example")?;
19        scr.remove_attribute(Attr::BOLD)?;
20
21        // Label
22        scr.set_foreground(Color::rgb(98, 114, 164))?;
23        scr.move_print(3, 2, label)?;
24
25        // Input text
26        scr.set_foreground(Color::rgb(248, 248, 242))?;
27        scr.print(&input)?;
28
29        // Position cursor inside the input
30        scr.move_cursor(3, (2 + label.len() + cursor) as u16)?;
31
32        // Hint
33        scr.set_foreground(Color::rgb(98, 114, 164))?;
34        scr.move_print(5, 2, "Type text, use ←/→ to move, Ctrl+Q to quit")?;
35
36        // Preview
37        if !input.is_empty() {
38            scr.set_foreground(Color::rgb(80, 250, 123))?;
39            scr.move_print(7, 2, &format!("Hello, {}!", input))?;
40        }
41
42        let key = scr.get_char()?;
43        match key {
44            Key::Ctrl('q') => break,
45            Key::Char(ch) => {
46                input.insert(cursor, ch);
47                cursor += 1;
48            }
49            Key::Backspace => {
50                if cursor > 0 {
51                    cursor -= 1;
52                    input.remove(cursor);
53                }
54            }
55            Key::Delete => {
56                if cursor < input.len() {
57                    input.remove(cursor);
58                }
59            }
60            Key::Left => {
61                if cursor > 0 {
62                    cursor -= 1;
63                }
64            }
65            Key::Right => {
66                if cursor < input.len() {
67                    cursor += 1;
68                }
69            }
70            Key::Home => cursor = 0,
71            Key::End => cursor = input.len(),
72            _ => {}
73        }
74    }
75
76    scr.set_cursor_style(0)?;
77    scr.endwin()?;
78    Ok(())
79}
Source

pub fn remove_attribute(&mut self, attr: Attr) -> Result<()>

Turn off attributes

Examples found in repository?
examples/text_input.rs (line 19)
3fn main() -> tv::Result<()> {
4    let mut scr = Screen::init()?;
5    scr.set_cursor_style(5)?; // blinking bar
6    scr.cursor_visible(true)?;
7
8    let mut input = String::new();
9    let mut cursor = 0usize;
10    let label = "Name: ";
11
12    loop {
13        scr.clear()?;
14
15        // Title
16        scr.set_foreground(Color::rgb(139, 233, 253))?;
17        scr.add_attribute(Attr::BOLD)?;
18        scr.move_print(1, 2, "Text Input Example")?;
19        scr.remove_attribute(Attr::BOLD)?;
20
21        // Label
22        scr.set_foreground(Color::rgb(98, 114, 164))?;
23        scr.move_print(3, 2, label)?;
24
25        // Input text
26        scr.set_foreground(Color::rgb(248, 248, 242))?;
27        scr.print(&input)?;
28
29        // Position cursor inside the input
30        scr.move_cursor(3, (2 + label.len() + cursor) as u16)?;
31
32        // Hint
33        scr.set_foreground(Color::rgb(98, 114, 164))?;
34        scr.move_print(5, 2, "Type text, use ←/→ to move, Ctrl+Q to quit")?;
35
36        // Preview
37        if !input.is_empty() {
38            scr.set_foreground(Color::rgb(80, 250, 123))?;
39            scr.move_print(7, 2, &format!("Hello, {}!", input))?;
40        }
41
42        let key = scr.get_char()?;
43        match key {
44            Key::Ctrl('q') => break,
45            Key::Char(ch) => {
46                input.insert(cursor, ch);
47                cursor += 1;
48            }
49            Key::Backspace => {
50                if cursor > 0 {
51                    cursor -= 1;
52                    input.remove(cursor);
53                }
54            }
55            Key::Delete => {
56                if cursor < input.len() {
57                    input.remove(cursor);
58                }
59            }
60            Key::Left => {
61                if cursor > 0 {
62                    cursor -= 1;
63                }
64            }
65            Key::Right => {
66                if cursor < input.len() {
67                    cursor += 1;
68                }
69            }
70            Key::Home => cursor = 0,
71            Key::End => cursor = input.len(),
72            _ => {}
73        }
74    }
75
76    scr.set_cursor_style(0)?;
77    scr.endwin()?;
78    Ok(())
79}
Source

pub fn set_attribute(&mut self, attr: Attr) -> Result<()>

Set attributes

Source

pub fn init_pair(&mut self, pair: u8, fg: Color, bg: Color) -> Result<()>

Initialize a color pair

Source

pub fn color_pair(&mut self, pair: u8) -> Result<()>

Set current color pair

Source

pub fn set_foreground(&mut self, color: Color) -> Result<()>

Set foreground color

Examples found in repository?
examples/text_input.rs (line 16)
3fn main() -> tv::Result<()> {
4    let mut scr = Screen::init()?;
5    scr.set_cursor_style(5)?; // blinking bar
6    scr.cursor_visible(true)?;
7
8    let mut input = String::new();
9    let mut cursor = 0usize;
10    let label = "Name: ";
11
12    loop {
13        scr.clear()?;
14
15        // Title
16        scr.set_foreground(Color::rgb(139, 233, 253))?;
17        scr.add_attribute(Attr::BOLD)?;
18        scr.move_print(1, 2, "Text Input Example")?;
19        scr.remove_attribute(Attr::BOLD)?;
20
21        // Label
22        scr.set_foreground(Color::rgb(98, 114, 164))?;
23        scr.move_print(3, 2, label)?;
24
25        // Input text
26        scr.set_foreground(Color::rgb(248, 248, 242))?;
27        scr.print(&input)?;
28
29        // Position cursor inside the input
30        scr.move_cursor(3, (2 + label.len() + cursor) as u16)?;
31
32        // Hint
33        scr.set_foreground(Color::rgb(98, 114, 164))?;
34        scr.move_print(5, 2, "Type text, use ←/→ to move, Ctrl+Q to quit")?;
35
36        // Preview
37        if !input.is_empty() {
38            scr.set_foreground(Color::rgb(80, 250, 123))?;
39            scr.move_print(7, 2, &format!("Hello, {}!", input))?;
40        }
41
42        let key = scr.get_char()?;
43        match key {
44            Key::Ctrl('q') => break,
45            Key::Char(ch) => {
46                input.insert(cursor, ch);
47                cursor += 1;
48            }
49            Key::Backspace => {
50                if cursor > 0 {
51                    cursor -= 1;
52                    input.remove(cursor);
53                }
54            }
55            Key::Delete => {
56                if cursor < input.len() {
57                    input.remove(cursor);
58                }
59            }
60            Key::Left => {
61                if cursor > 0 {
62                    cursor -= 1;
63                }
64            }
65            Key::Right => {
66                if cursor < input.len() {
67                    cursor += 1;
68                }
69            }
70            Key::Home => cursor = 0,
71            Key::End => cursor = input.len(),
72            _ => {}
73        }
74    }
75
76    scr.set_cursor_style(0)?;
77    scr.endwin()?;
78    Ok(())
79}
Source

pub fn set_background(&mut self, color: Color) -> Result<()>

Set background color

Source

pub fn set_base(&mut self, fg: Color, bg: Color) -> Result<()>

Set the base (default) fg/bg used to fill unwritten cells and prime SGR before erase/scroll ops. Analogous to ncplane_set_base in notcurses or wbkgdset in ncurses.

This ALSO repaints the physical screen with the base and updates the internal state to match, so the terminal’s post-init \x1b[2J (which fills with terminal-default bg — usually black) no longer leaks through for cells that the render path never writes to. After set_base, both current_content and pending_content are filled with a “base cell” (space with base fg/bg) — so Cell::BLANK never appears as a stable state at diff time.

Source

pub fn clear(&mut self) -> Result<()>

Clear the entire screen

Examples found in repository?
examples/text_input.rs (line 13)
3fn main() -> tv::Result<()> {
4    let mut scr = Screen::init()?;
5    scr.set_cursor_style(5)?; // blinking bar
6    scr.cursor_visible(true)?;
7
8    let mut input = String::new();
9    let mut cursor = 0usize;
10    let label = "Name: ";
11
12    loop {
13        scr.clear()?;
14
15        // Title
16        scr.set_foreground(Color::rgb(139, 233, 253))?;
17        scr.add_attribute(Attr::BOLD)?;
18        scr.move_print(1, 2, "Text Input Example")?;
19        scr.remove_attribute(Attr::BOLD)?;
20
21        // Label
22        scr.set_foreground(Color::rgb(98, 114, 164))?;
23        scr.move_print(3, 2, label)?;
24
25        // Input text
26        scr.set_foreground(Color::rgb(248, 248, 242))?;
27        scr.print(&input)?;
28
29        // Position cursor inside the input
30        scr.move_cursor(3, (2 + label.len() + cursor) as u16)?;
31
32        // Hint
33        scr.set_foreground(Color::rgb(98, 114, 164))?;
34        scr.move_print(5, 2, "Type text, use ←/→ to move, Ctrl+Q to quit")?;
35
36        // Preview
37        if !input.is_empty() {
38            scr.set_foreground(Color::rgb(80, 250, 123))?;
39            scr.move_print(7, 2, &format!("Hello, {}!", input))?;
40        }
41
42        let key = scr.get_char()?;
43        match key {
44            Key::Ctrl('q') => break,
45            Key::Char(ch) => {
46                input.insert(cursor, ch);
47                cursor += 1;
48            }
49            Key::Backspace => {
50                if cursor > 0 {
51                    cursor -= 1;
52                    input.remove(cursor);
53                }
54            }
55            Key::Delete => {
56                if cursor < input.len() {
57                    input.remove(cursor);
58                }
59            }
60            Key::Left => {
61                if cursor > 0 {
62                    cursor -= 1;
63                }
64            }
65            Key::Right => {
66                if cursor < input.len() {
67                    cursor += 1;
68                }
69            }
70            Key::Home => cursor = 0,
71            Key::End => cursor = input.len(),
72            _ => {}
73        }
74    }
75
76    scr.set_cursor_style(0)?;
77    scr.endwin()?;
78    Ok(())
79}
Source

pub fn clear_to_end_of_line(&mut self) -> Result<()>

Clear to end of line

Source

pub fn clear_to_bottom_of_screen(&mut self) -> Result<()>

Clear to bottom of screen

Source

pub fn cursor_visible(&mut self, visible: bool) -> Result<()>

Set cursor visibility

Examples found in repository?
examples/text_input.rs (line 6)
3fn main() -> tv::Result<()> {
4    let mut scr = Screen::init()?;
5    scr.set_cursor_style(5)?; // blinking bar
6    scr.cursor_visible(true)?;
7
8    let mut input = String::new();
9    let mut cursor = 0usize;
10    let label = "Name: ";
11
12    loop {
13        scr.clear()?;
14
15        // Title
16        scr.set_foreground(Color::rgb(139, 233, 253))?;
17        scr.add_attribute(Attr::BOLD)?;
18        scr.move_print(1, 2, "Text Input Example")?;
19        scr.remove_attribute(Attr::BOLD)?;
20
21        // Label
22        scr.set_foreground(Color::rgb(98, 114, 164))?;
23        scr.move_print(3, 2, label)?;
24
25        // Input text
26        scr.set_foreground(Color::rgb(248, 248, 242))?;
27        scr.print(&input)?;
28
29        // Position cursor inside the input
30        scr.move_cursor(3, (2 + label.len() + cursor) as u16)?;
31
32        // Hint
33        scr.set_foreground(Color::rgb(98, 114, 164))?;
34        scr.move_print(5, 2, "Type text, use ←/→ to move, Ctrl+Q to quit")?;
35
36        // Preview
37        if !input.is_empty() {
38            scr.set_foreground(Color::rgb(80, 250, 123))?;
39            scr.move_print(7, 2, &format!("Hello, {}!", input))?;
40        }
41
42        let key = scr.get_char()?;
43        match key {
44            Key::Ctrl('q') => break,
45            Key::Char(ch) => {
46                input.insert(cursor, ch);
47                cursor += 1;
48            }
49            Key::Backspace => {
50                if cursor > 0 {
51                    cursor -= 1;
52                    input.remove(cursor);
53                }
54            }
55            Key::Delete => {
56                if cursor < input.len() {
57                    input.remove(cursor);
58                }
59            }
60            Key::Left => {
61                if cursor > 0 {
62                    cursor -= 1;
63                }
64            }
65            Key::Right => {
66                if cursor < input.len() {
67                    cursor += 1;
68                }
69            }
70            Key::Home => cursor = 0,
71            Key::End => cursor = input.len(),
72            _ => {}
73        }
74    }
75
76    scr.set_cursor_style(0)?;
77    scr.endwin()?;
78    Ok(())
79}
Source

pub fn border( &mut self, ls: char, rs: char, ts: char, bs: char, tl: char, tr: char, bl: char, br: char, ) -> Result<()>

Draw a box border

Source

pub fn draw_box(&mut self) -> Result<()>

Draw a box using ACS line-drawing characters

Source

pub fn get_char(&mut self) -> Result<Key>

Read a single key

Examples found in repository?
examples/text_input.rs (line 42)
3fn main() -> tv::Result<()> {
4    let mut scr = Screen::init()?;
5    scr.set_cursor_style(5)?; // blinking bar
6    scr.cursor_visible(true)?;
7
8    let mut input = String::new();
9    let mut cursor = 0usize;
10    let label = "Name: ";
11
12    loop {
13        scr.clear()?;
14
15        // Title
16        scr.set_foreground(Color::rgb(139, 233, 253))?;
17        scr.add_attribute(Attr::BOLD)?;
18        scr.move_print(1, 2, "Text Input Example")?;
19        scr.remove_attribute(Attr::BOLD)?;
20
21        // Label
22        scr.set_foreground(Color::rgb(98, 114, 164))?;
23        scr.move_print(3, 2, label)?;
24
25        // Input text
26        scr.set_foreground(Color::rgb(248, 248, 242))?;
27        scr.print(&input)?;
28
29        // Position cursor inside the input
30        scr.move_cursor(3, (2 + label.len() + cursor) as u16)?;
31
32        // Hint
33        scr.set_foreground(Color::rgb(98, 114, 164))?;
34        scr.move_print(5, 2, "Type text, use ←/→ to move, Ctrl+Q to quit")?;
35
36        // Preview
37        if !input.is_empty() {
38            scr.set_foreground(Color::rgb(80, 250, 123))?;
39            scr.move_print(7, 2, &format!("Hello, {}!", input))?;
40        }
41
42        let key = scr.get_char()?;
43        match key {
44            Key::Ctrl('q') => break,
45            Key::Char(ch) => {
46                input.insert(cursor, ch);
47                cursor += 1;
48            }
49            Key::Backspace => {
50                if cursor > 0 {
51                    cursor -= 1;
52                    input.remove(cursor);
53                }
54            }
55            Key::Delete => {
56                if cursor < input.len() {
57                    input.remove(cursor);
58                }
59            }
60            Key::Left => {
61                if cursor > 0 {
62                    cursor -= 1;
63                }
64            }
65            Key::Right => {
66                if cursor < input.len() {
67                    cursor += 1;
68                }
69            }
70            Key::Home => cursor = 0,
71            Key::End => cursor = input.len(),
72            _ => {}
73        }
74    }
75
76    scr.set_cursor_style(0)?;
77    scr.endwin()?;
78    Ok(())
79}
Source

pub fn get_char_timeout(&mut self, timeout_ms: u64) -> Result<Option<Key>>

Read a key with timeout (in milliseconds). Returns None if timeout expires.

Source

pub fn set_check_interval(&mut self, lines: usize)

Set how often to check for input during refresh (Phase 2.1 optimization)

Lower values = more responsive but slightly more CPU overhead Higher values = less overhead but potential input lag

Default: 5 lines

Source

pub fn hold_refresh(&mut self)

Temporarily disable input checking during critical updates

Use when you need a consistent screen state without interruption

Source

pub fn release_refresh(&mut self)

Re-enable input checking during refresh

Source

pub fn refresh(&mut self) -> Result<()>

Refresh the screen (flush buffer to stdout)

Source

pub fn wnoutrefresh(&mut self) -> Result<()>

Update internal buffer without refreshing screen

Source

pub fn doupdate() -> Result<()>

Update physical screen with all pending changes

Source

pub fn set_bracketed_paste(&mut self, enabled: bool) -> Result<()>

Enable Kitty keyboard protocol with the specified flags.

Alias for push_kitty_keyboard — the kitty spec only offers a stack-based enable, so there is no separate “set without pushing” primitive at this layer. Toggle bracketed-paste mode (DEC private mode 2004). When enabled, pasted content arrives wrapped in ESC [ 200 ~ and ESC [ 201 ~, surfaced via Key::Paste rather than as a stream of individual key events.

Source

pub fn osc52_copy(&mut self, text: &str) -> Result<()>

Publish text to the system clipboard via OSC 52. The terminal (if it permits clipboard writes) base64-decodes the payload and writes it to the system clipboard. Works without a clipboard daemon — no pbcopy/xclip shell-out required.

Source

pub fn enable_kitty_keyboard(&mut self, flags: KittyFlags) -> Result<()>

Source

pub fn disable_kitty_keyboard(&mut self) -> Result<()>

Disable Kitty keyboard protocol by popping the top of the stack.

Source

pub fn push_kitty_keyboard(&mut self, flags: KittyFlags) -> Result<()>

Push flags onto the terminal’s keyboard-mode stack so the previous configuration is preserved.

Source

pub fn pop_kitty_keyboard(&mut self) -> Result<()>

Pop one entry from the keyboard-mode stack.

Source

pub fn pop_kitty_keyboard_n(&mut self, n: u32) -> Result<()>

Pop n entries from the keyboard-mode stack.

Source

pub fn set_kitty_keyboard( &mut self, flags: KittyFlags, mode: SetMode, ) -> Result<()>

Set the top-of-stack flags directly without pushing. mode controls whether to replace, OR, or AND-NOT the current flags — see SetMode for details.

Source

pub fn query_kitty_keyboard(&mut self) -> Result<()>

Query the terminal for its active keyboard flags. The reply arrives asynchronously as CSI ? flags u; tv does not yet decode it — callers that care can read stdin and parse it.

Source

pub fn display_kitty_image(&mut self, image: &KittyImage<'_>) -> Result<()>

Display an image using Kitty graphics protocol

Source

pub fn display_sixel_image(&mut self, image: &SixelImage<'_>) -> Result<()>

Display an image using Sixel graphics protocol

Source

pub fn delete_kitty_image(&mut self, image_id: u32) -> Result<()>

Delete a Kitty image by ID

Source

pub fn delete_all_kitty_images(&mut self) -> Result<()>

Delete all Kitty images

Source

pub fn newwin(&self, height: u16, width: u16, y: u16, x: u16) -> Result<Surface>

Create a new surface

Source

pub fn set_cursor_style(&mut self, style: u8) -> Result<()>

Set cursor style using DECSCUSR

0 = default, 1 = blinking block, 2 = steady block, 3 = blinking underline, 4 = steady underline, 5 = blinking bar, 6 = steady bar

Examples found in repository?
examples/text_input.rs (line 5)
3fn main() -> tv::Result<()> {
4    let mut scr = Screen::init()?;
5    scr.set_cursor_style(5)?; // blinking bar
6    scr.cursor_visible(true)?;
7
8    let mut input = String::new();
9    let mut cursor = 0usize;
10    let label = "Name: ";
11
12    loop {
13        scr.clear()?;
14
15        // Title
16        scr.set_foreground(Color::rgb(139, 233, 253))?;
17        scr.add_attribute(Attr::BOLD)?;
18        scr.move_print(1, 2, "Text Input Example")?;
19        scr.remove_attribute(Attr::BOLD)?;
20
21        // Label
22        scr.set_foreground(Color::rgb(98, 114, 164))?;
23        scr.move_print(3, 2, label)?;
24
25        // Input text
26        scr.set_foreground(Color::rgb(248, 248, 242))?;
27        scr.print(&input)?;
28
29        // Position cursor inside the input
30        scr.move_cursor(3, (2 + label.len() + cursor) as u16)?;
31
32        // Hint
33        scr.set_foreground(Color::rgb(98, 114, 164))?;
34        scr.move_print(5, 2, "Type text, use ←/→ to move, Ctrl+Q to quit")?;
35
36        // Preview
37        if !input.is_empty() {
38            scr.set_foreground(Color::rgb(80, 250, 123))?;
39            scr.move_print(7, 2, &format!("Hello, {}!", input))?;
40        }
41
42        let key = scr.get_char()?;
43        match key {
44            Key::Ctrl('q') => break,
45            Key::Char(ch) => {
46                input.insert(cursor, ch);
47                cursor += 1;
48            }
49            Key::Backspace => {
50                if cursor > 0 {
51                    cursor -= 1;
52                    input.remove(cursor);
53                }
54            }
55            Key::Delete => {
56                if cursor < input.len() {
57                    input.remove(cursor);
58                }
59            }
60            Key::Left => {
61                if cursor > 0 {
62                    cursor -= 1;
63                }
64            }
65            Key::Right => {
66                if cursor < input.len() {
67                    cursor += 1;
68                }
69            }
70            Key::Home => cursor = 0,
71            Key::End => cursor = input.len(),
72            _ => {}
73        }
74    }
75
76    scr.set_cursor_style(0)?;
77    scr.endwin()?;
78    Ok(())
79}
Source

pub fn set_cursor_position(&mut self, y: u16, x: u16)

Set the terminal cursor position after the next refresh.

Auto Trait Implementations§

§

impl Forget for Screen

§

impl Freeze for Screen

§

impl Move for Screen

§

impl RefUnwindSafe for Screen

§

impl Send for Screen

§

impl Sync for Screen

§

impl Unpin for Screen

§

impl UnsafeUnpin for Screen

§

impl UnwindSafe for Screen

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.