pub struct Screen { /* private fields */ }Expand description
Main screen interface
Implementations§
Source§impl Screen
impl Screen
Sourcepub fn init() -> Result<Self>
pub fn init() -> Result<Self>
Initialize the screen
Examples found in repository?
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}Sourcepub fn endwin(self) -> Result<()>
pub fn endwin(self) -> Result<()>
Clean up and restore terminal
Examples found in repository?
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}Sourcepub fn move_cursor(&mut self, y: u16, x: u16) -> Result<()>
pub fn move_cursor(&mut self, y: u16, x: u16) -> Result<()>
Move cursor to position (y, x)
Examples found in repository?
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}Sourcepub fn print(&mut self, text: &str) -> Result<()>
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?
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}Sourcepub fn move_print(&mut self, y: u16, x: u16, text: &str) -> Result<()>
pub fn move_print(&mut self, y: u16, x: u16, text: &str) -> Result<()>
Move cursor and print (like mvprintw)
Examples found in repository?
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}Sourcepub fn move_add_char(&mut self, y: u16, x: u16, ch: char) -> Result<()>
pub fn move_add_char(&mut self, y: u16, x: u16, ch: char) -> Result<()>
Move cursor and add character
Sourcepub fn add_attribute(&mut self, attr: Attr) -> Result<()>
pub fn add_attribute(&mut self, attr: Attr) -> Result<()>
Turn on attributes
Examples found in repository?
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}Sourcepub fn remove_attribute(&mut self, attr: Attr) -> Result<()>
pub fn remove_attribute(&mut self, attr: Attr) -> Result<()>
Turn off attributes
Examples found in repository?
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}Sourcepub fn set_attribute(&mut self, attr: Attr) -> Result<()>
pub fn set_attribute(&mut self, attr: Attr) -> Result<()>
Set attributes
Sourcepub fn init_pair(&mut self, pair: u8, fg: Color, bg: Color) -> Result<()>
pub fn init_pair(&mut self, pair: u8, fg: Color, bg: Color) -> Result<()>
Initialize a color pair
Sourcepub fn color_pair(&mut self, pair: u8) -> Result<()>
pub fn color_pair(&mut self, pair: u8) -> Result<()>
Set current color pair
Sourcepub fn set_foreground(&mut self, color: Color) -> Result<()>
pub fn set_foreground(&mut self, color: Color) -> Result<()>
Set foreground color
Examples found in repository?
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}Sourcepub fn set_background(&mut self, color: Color) -> Result<()>
pub fn set_background(&mut self, color: Color) -> Result<()>
Set background color
Sourcepub fn set_base(&mut self, fg: Color, bg: Color) -> Result<()>
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.
Sourcepub fn clear(&mut self) -> Result<()>
pub fn clear(&mut self) -> Result<()>
Clear the entire screen
Examples found in repository?
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}Sourcepub fn clear_to_end_of_line(&mut self) -> Result<()>
pub fn clear_to_end_of_line(&mut self) -> Result<()>
Clear to end of line
Sourcepub fn clear_to_bottom_of_screen(&mut self) -> Result<()>
pub fn clear_to_bottom_of_screen(&mut self) -> Result<()>
Clear to bottom of screen
Sourcepub fn cursor_visible(&mut self, visible: bool) -> Result<()>
pub fn cursor_visible(&mut self, visible: bool) -> Result<()>
Set cursor visibility
Examples found in repository?
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}Sourcepub fn border(
&mut self,
ls: char,
rs: char,
ts: char,
bs: char,
tl: char,
tr: char,
bl: char,
br: char,
) -> Result<()>
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
Sourcepub fn get_char(&mut self) -> Result<Key>
pub fn get_char(&mut self) -> Result<Key>
Read a single key
Examples found in repository?
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}Sourcepub fn get_char_timeout(&mut self, timeout_ms: u64) -> Result<Option<Key>>
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.
Sourcepub fn set_check_interval(&mut self, lines: usize)
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
Sourcepub fn hold_refresh(&mut self)
pub fn hold_refresh(&mut self)
Temporarily disable input checking during critical updates
Use when you need a consistent screen state without interruption
Sourcepub fn release_refresh(&mut self)
pub fn release_refresh(&mut self)
Re-enable input checking during refresh
Sourcepub fn wnoutrefresh(&mut self) -> Result<()>
pub fn wnoutrefresh(&mut self) -> Result<()>
Update internal buffer without refreshing screen
Sourcepub fn set_bracketed_paste(&mut self, enabled: bool) -> Result<()>
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.
Sourcepub fn osc52_copy(&mut self, text: &str) -> Result<()>
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.
pub fn enable_kitty_keyboard(&mut self, flags: KittyFlags) -> Result<()>
Sourcepub fn disable_kitty_keyboard(&mut self) -> Result<()>
pub fn disable_kitty_keyboard(&mut self) -> Result<()>
Disable Kitty keyboard protocol by popping the top of the stack.
Sourcepub fn push_kitty_keyboard(&mut self, flags: KittyFlags) -> Result<()>
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.
Sourcepub fn pop_kitty_keyboard(&mut self) -> Result<()>
pub fn pop_kitty_keyboard(&mut self) -> Result<()>
Pop one entry from the keyboard-mode stack.
Sourcepub fn pop_kitty_keyboard_n(&mut self, n: u32) -> Result<()>
pub fn pop_kitty_keyboard_n(&mut self, n: u32) -> Result<()>
Pop n entries from the keyboard-mode stack.
Sourcepub fn set_kitty_keyboard(
&mut self,
flags: KittyFlags,
mode: SetMode,
) -> Result<()>
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.
Sourcepub fn query_kitty_keyboard(&mut self) -> Result<()>
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.
Sourcepub fn display_kitty_image(&mut self, image: &KittyImage<'_>) -> Result<()>
pub fn display_kitty_image(&mut self, image: &KittyImage<'_>) -> Result<()>
Display an image using Kitty graphics protocol
Sourcepub fn display_sixel_image(&mut self, image: &SixelImage<'_>) -> Result<()>
pub fn display_sixel_image(&mut self, image: &SixelImage<'_>) -> Result<()>
Display an image using Sixel graphics protocol
Sourcepub fn delete_kitty_image(&mut self, image_id: u32) -> Result<()>
pub fn delete_kitty_image(&mut self, image_id: u32) -> Result<()>
Delete a Kitty image by ID
Sourcepub fn delete_all_kitty_images(&mut self) -> Result<()>
pub fn delete_all_kitty_images(&mut self) -> Result<()>
Delete all Kitty images
Sourcepub fn newwin(&self, height: u16, width: u16, y: u16, x: u16) -> Result<Surface>
pub fn newwin(&self, height: u16, width: u16, y: u16, x: u16) -> Result<Surface>
Create a new surface
Sourcepub fn set_cursor_style(&mut self, style: u8) -> Result<()>
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?
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}Sourcepub fn set_cursor_position(&mut self, y: u16, x: u16)
pub fn set_cursor_position(&mut self, y: u16, x: u16)
Set the terminal cursor position after the next refresh.