Struct Curses

Source
#[repr(C)]
pub struct Curses { /* private fields */ }
Expand description

Handle to the terminal’s curses interface.

Implementations§

Source§

impl Curses

Source

pub fn init() -> Self

Initializes curses.

  • Automatically enables color, if available.
  • Automatically enables keypad keys (arrow keys, function keys, etc).
§Panics
  • If you double-initialize curses this will panic.
  • If your previous curses handle has been dropped it is legal to init another one. Curses mode will resume just fine.
§Other
  • If this fails on the curses side, curses will “helpfully” print an error and abort the process for you.
  • This installs a custom panic hook that ends curses mode before printing the panic message. Otherwise your panic messages get eaten. The normal panic hook is restored when Curses drops.
Examples found in repository?
examples/demo.rs (line 8)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn refresh(&mut self) -> Result<(), &'static str>

Pushes all updates out to the physical screen, refreshing the display.

Source

pub fn set_echo(&mut self, echoing: bool) -> Result<(), &'static str>

Sets if user inputs should automatically echo to the screen or not.

  • Initially this is enabled.
Examples found in repository?
examples/demo.rs (line 10)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn get_cursor_position(&self) -> Position

Get the cursor’s current row and column.

Examples found in repository?
examples/demo.rs (line 79)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn get_terminal_size(&self) -> TerminalSize

Get the size of the terminal.

Cursor positions can range in 0..COUNT in each dimension.

Examples found in repository?
examples/demo.rs (line 80)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn move_cursor(&mut self, p: Position) -> Result<(), &'static str>

Move the cursor to the position given.

Examples found in repository?
examples/demo.rs (line 17)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn print_ch<C: Into<CursesGlyph>>( &mut self, c: C, ) -> Result<(), &'static str>

Prints the character given, advancing the cursor.

  • Wraps to the next line if in the final col.
  • Will scroll the terminal if in the final row, if scrolling is enabled.
Examples found in repository?
examples/demo.rs (lines 20-24)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn print_str(&mut self, s: &str) -> Result<(), &'static str>

Prints the str given, advancing the cursor.

This is identical to calling print_ch on every byte in s. If your &str has non-ascii data you’ll get garbage on the screen.

  • Wraps to the next line if in the final col.
  • Will scroll the terminal if in the final row, if scrolling is enabled.
Examples found in repository?
examples/demo.rs (line 15)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn insert_ch<C: Into<CursesGlyph>>( &mut self, c: C, ) -> Result<(), &'static str>

Inserts the given character under the cursor.

  • The cursor doesn’t move.
  • Other characters to the right get pushed 1 cell forward.
  • The last character of the line gets pushed off the screen.
Source

pub fn delete_ch(&mut self) -> Result<(), &'static str>

Deleted character under the cursor.

  • The cursor doesn’t move.
  • Other characters to the right get pulled 1 cell backward.
  • The last character of the line is now blank.
Source

pub fn copy_glyphs(&mut self, s: &[CursesGlyph]) -> Result<(), &'static str>

Copies the slice of glyphs starting from the cursor position.

  • Does not advance the cursor.
  • Does not wrap the content to the next line.
Examples found in repository?
examples/demo.rs (line 65)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn clear(&mut self) -> Result<(), &'static str>

Clears the entire screen and moves the cursor to (0,0).

This can have somewhat poor performance. If you’re just going to overwrite the entire screen with new content anyway, you shouldn’t use this.

Examples found in repository?
examples/demo.rs (line 34)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn set_attributes( &mut self, attr: Attributes, on: bool, ) -> Result<(), &'static str>

Set the given attribute bits to be on or off.

Source

pub fn set_terminal_size( &mut self, size: TerminalSize, ) -> Result<(), &'static str>

Attempts to change the terminal size to a new size.

In many contexts the terminal size cannot change. Your program should tolerate that this will fail under reasonable conditions.

Source

pub fn set_timeout(&mut self, time: i32)

Assigns the timeout to use with poll_events.

  • Negative: infinite time, poll_events is blocking.
  • Zero: No timeout, poll_events returns None immediately if no input is ready.
  • Positive: wait up to this many milliseconds before returning None.

The default is to have blocking input.

Source

pub fn poll_events(&mut self) -> Option<CursesKey>

Gets an input event.

  • Ascii keys are returned as their ascii value.
  • Special keys each have an enum variant of their own.
  • If the terminal is resized, that shows up as a type of “key”.
  • If you have a timeout set and the time expires, you get None back.
Examples found in repository?
examples/demo.rs (line 31)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn un_get_event( &mut self, event: Option<CursesKey>, ) -> Result<(), &'static str>

Pushes this event to the front of the event queue so that the next poll_events returns this value.

Source

pub fn flush_events(&mut self) -> Result<(), &'static str>

Flushes all pending key events.

Source

pub fn shell_mode<'a>(&'a mut self) -> Result<CursesShell<'a>, &'static str>

Return the terminal to shell mode temporarily.

Examples found in repository?
examples/demo.rs (line 74)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn has_color(&self) -> bool

If the terminal supports colors at all.

Source

pub fn can_change_colors(&self) -> bool

If the terminal is able to change the RGB values of a given ColorID

Examples found in repository?
examples/demo.rs (line 12)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn get_max_color_id_inclusive(&self) -> Option<ColorID>

Gets the highest allowed color id for this terminal.

Examples found in repository?
examples/demo.rs (line 81)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn get_max_color_pair_inclusive(&self) -> Option<ColorPair>

Gets the highest allowed color pair for this terminal.

Examples found in repository?
examples/demo.rs (line 82)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn set_color_id_rgb( &mut self, c: ColorID, [r, g, b]: [f32; 3], ) -> Result<(), &'static str>

Sets the color id to use the RGB values given, or closest approximation available.

Inputs are clamped to the range 0.0 ..= 1.0

Examples found in repository?
examples/demo.rs (line 13)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn get_color_id_rgb(&self, c: ColorID) -> Result<[f32; 3], &'static str>

Gets the RGB values of the given color id.

Examples found in repository?
examples/demo.rs (line 76)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn set_color_pair_content( &mut self, pair: ColorPair, fg: ColorID, bg: ColorID, ) -> Result<(), &'static str>

Assigns the selected color pair to use the foreground and background specified.

A character cell is associated to a given color pair, so changing any color pair will immediately change all character cells displaying the color pair.

Source

pub fn get_color_pair_content( &self, c: ColorID, ) -> Result<(ColorID, ColorID), &'static str>

Gets the RGB values of the given color id.

Source

pub fn set_active_color_pair( &mut self, opt_pair: Option<ColorPair>, ) -> Result<(), &'static str>

Sets the default coloring for all newly printed glyphs.

Source

pub fn set_scrollable(&mut self, yes: bool) -> Result<(), &'static str>

Set if the window can be scrolled or not.

  • Off by default.
Source

pub fn set_scroll_region( &mut self, top: u32, bottom: u32, ) -> Result<(), &'static str>

Sets the top line and bottom line that mark the edges of the scrollable region.

Lines 0..=top and bottom.. will stay static when the window is scrolled. All other lines will move 1 row upward.

  • By default the scroll region is the entire terminal.
Source

pub fn scroll(&mut self, n: i32) -> Result<(), &'static str>

Scrolls the window by the given number of lines.

  • Negative: text moves down the page.
  • Positive: text moves up the page.
  • Zero: text doesn’t move.
Source

pub fn set_cursor_visibility( &mut self, vis: CursorVisibility, ) -> Result<CursorVisibility, &'static str>

Sets the cursor visibility.

Returns the old visibility, or Err if it can’t be set.

Examples found in repository?
examples/demo.rs (line 11)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn set_background<C: Into<CursesGlyph>>( &mut self, c: C, ) -> Result<(), &'static str>

Sets the background glyph.

Examples found in repository?
examples/demo.rs (line 33)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn get_background(&self) -> CursesGlyph

Gets the background glyph.

Source§

impl Curses

Source

pub fn acs_block(&self) -> CursesGlyph

Solid square block, but sometimes a hash.

Source

pub fn acs_board(&self) -> CursesGlyph

Board of squares, often just a hash.

Source

pub fn acs_btee(&self) -> CursesGlyph

Bottom T

Examples found in repository?
examples/demo.rs (line 55)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn acs_bullet(&self) -> CursesGlyph

Bullet point

Examples found in repository?
examples/demo.rs (line 42)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn acs_ckboard(&self) -> CursesGlyph

Checkerboard, usually like a 50% stipple

Examples found in repository?
examples/demo.rs (line 57)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn acs_darrow(&self) -> CursesGlyph

Down arrow

Source

pub fn acs_degree(&self) -> CursesGlyph

Degree symbol (like with an angle)

Examples found in repository?
examples/demo.rs (line 40)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn acs_diamond(&self) -> CursesGlyph

Diamond

Source

pub fn acs_gequal(&self) -> CursesGlyph

Greater-than or equal to.

Examples found in repository?
examples/demo.rs (line 45)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn acs_hline(&self) -> CursesGlyph

Horizontal line

Examples found in repository?
examples/demo.rs (line 46)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn acs_lantern(&self) -> CursesGlyph

Lantern symbol

Source

pub fn acs_larrow(&self) -> CursesGlyph

Left arrow

Source

pub fn acs_lequal(&self) -> CursesGlyph

Less-than or equal to.

Examples found in repository?
examples/demo.rs (line 44)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn acs_llcorner(&self) -> CursesGlyph

Lower left corner of a box.

Examples found in repository?
examples/demo.rs (line 50)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn acs_lrcorner(&self) -> CursesGlyph

Lower right corner of a box.

Examples found in repository?
examples/demo.rs (line 51)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn acs_ltee(&self) -> CursesGlyph

Left T

Examples found in repository?
examples/demo.rs (line 52)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn acs_nequal(&self) -> CursesGlyph

Not-equal to.

Source

pub fn acs_pi(&self) -> CursesGlyph

Pi

Examples found in repository?
examples/demo.rs (line 43)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn acs_plminus(&self) -> CursesGlyph

Plus/Minus

Examples found in repository?
examples/demo.rs (line 41)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn acs_plus(&self) -> CursesGlyph

Plus shaped “line” in all four directions

Examples found in repository?
examples/demo.rs (line 56)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn acs_rarrow(&self) -> CursesGlyph

Right arrow

Source

pub fn acs_rtee(&self) -> CursesGlyph

Right T

Examples found in repository?
examples/demo.rs (line 53)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn acs_s1(&self) -> CursesGlyph

Horizontal Scanline 1

Source

pub fn acs_s3(&self) -> CursesGlyph

Horizontal Scanline 3

Source

pub fn acs_s7(&self) -> CursesGlyph

Horizontal Scanline 7

Source

pub fn acs_s9(&self) -> CursesGlyph

Horizontal Scanline 9

Source

pub fn acs_sterling(&self) -> CursesGlyph

British pounds sterling.

Examples found in repository?
examples/demo.rs (line 39)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn acs_ttee(&self) -> CursesGlyph

Top T

Examples found in repository?
examples/demo.rs (line 54)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn acs_uarrow(&self) -> CursesGlyph

Up arrow

Source

pub fn acs_ulcorner(&self) -> CursesGlyph

Upper left corner of a box.

Examples found in repository?
examples/demo.rs (line 48)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn acs_urcorner(&self) -> CursesGlyph

Upper right corner of a box.

Examples found in repository?
examples/demo.rs (line 49)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}
Source

pub fn acs_vline(&self) -> CursesGlyph

Vertical line

Examples found in repository?
examples/demo.rs (line 47)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
fn main() {
  // This will rust-panic on double-init, and on failure in the C layer the C
  // code will "helpfully" print the error message and abort the process.
  // Otherwise, this "always succeeds".
  let mut win = Curses::init();

  win.set_echo(false);
  win.set_cursor_visibility(CursorVisibility::Invisible);
  if win.can_change_colors() {
    win.set_color_id_rgb(ColorID::WHITE, [1.0, 1.0, 1.0]).unwrap();
  } else {
    win.print_str("This terminal cannot change colors :(");
  }
  win.move_cursor(Position { x: 75, y: 1 });
  let ascii = b'@';
  let opt_color_pair = None;
  win.print_ch(CursesGlyph {
    ascii,
    opt_color_pair,
    attributes: Attributes(0),
  });
  for n in 0..16 {
    let attributes = Attributes(1 << n);
    win.print_ch(CursesGlyph { ascii, opt_color_pair, attributes });
  }
  win.move_cursor(Position { x: 75, y: 5 });
  win.print_str("Hello there, General Kenobi!");
  win.poll_events().unwrap();
  //
  win.set_background('!');
  win.clear();
  win.print_str("ACS:");
  // These are the ACS characters that are most likely to be consistent-enough
  // across terminals:
  for ch in [
    win.acs_sterling(),
    win.acs_degree(),
    win.acs_plminus(),
    win.acs_bullet(),
    win.acs_pi(),
    win.acs_lequal(),
    win.acs_gequal(),
    win.acs_hline(),
    win.acs_vline(),
    win.acs_ulcorner(),
    win.acs_urcorner(),
    win.acs_llcorner(),
    win.acs_lrcorner(),
    win.acs_ltee(),
    win.acs_rtee(),
    win.acs_ttee(),
    win.acs_btee(),
    win.acs_plus(),
    win.acs_ckboard(),
  ]
  .iter()
  .copied()
  {
    win.print_ch(ch);
  }
  win.move_cursor(Position { x: 75, y: 8 });
  win.copy_glyphs(&[CursesGlyph::from(ascii); 10]);
  const Q: CursesKey = CursesKey::from_ascii(b'q');
  const P: CursesKey = CursesKey::from_ascii(b'p');
  const BANG: CursesKey = CursesKey::from_ascii(b'!');
  loop {
    match win.poll_events() {
      Some(Q) => break,
      Some(BANG) => panic!("test panic"),
      Some(P) => {
        let sh = win.shell_mode().unwrap();
        for cid in 0..8 {
          let [r, g, b] = sh.get_color_id_rgb(ColorID(cid)).unwrap();
          eprintln!("CID({}): [{},{},{}]", cid, r, g, b);
        }
        eprintln!("{:?}", sh.get_cursor_position());
        eprintln!("{:?}", sh.get_terminal_size());
        eprintln!("{:?}", sh.get_max_color_id_inclusive());
        eprintln!("{:?}", sh.get_max_color_pair_inclusive());
        let mut str_buf = String::with_capacity(1024);
        std::io::stdin().read_line(&mut str_buf).unwrap();
        println!("got line: {}", str_buf);
      }
      Some(CursesKey::UnknownKey(u)) => {
        let sh = win.shell_mode().unwrap();
        panic!("Unknown Key: {}", u);
      }
      _ => continue,
    }
  }
  println!("Demo over.");
}

Trait Implementations§

Source§

impl Drop for Curses

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Curses

§

impl !RefUnwindSafe for Curses

§

impl !Send for Curses

§

impl !Sync for Curses

§

impl Unpin for Curses

§

impl !UnwindSafe for Curses

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.