Skip to main content

oxidized_curses/window/
main_window.rs

1use crate::cursor::*;
2use crate::io_attrs::*;
3use crate::window::Window;
4
5pub struct MainWindow {}
6
7impl Window for MainWindow {
8    fn move_print(&mut self, point: crate::utils::ScreenPoint, text: &str) {
9        ncurses::mvaddstr(point.y as i32, point.x as i32, text);
10    }
11
12    fn print(&mut self, text: &str) {
13        ncurses::addstr(text);
14    }
15
16    fn refresh(&mut self) {
17        ncurses::refresh();
18    }
19
20    fn get_char(&mut self) -> char {
21        ncurses::getch() as u8 as char
22    }
23}
24
25/// The fullscreen ncurses window
26impl MainWindow {
27    /// Set up the window with some basic defaults
28    pub fn init() -> Self {
29        ncurses::initscr();
30        set_cbreak(true);
31        set_echo(false);
32        set_cursor(CursorState::Invisible);
33        MainWindow {}
34    }
35}
36
37impl Drop for MainWindow {
38    /// Reset the tty to a reasonable state and clean up curses
39    fn drop(&mut self) {
40        set_echo(true);
41        set_cbreak(false);
42        set_cursor(CursorState::Visible);
43
44        ncurses::endwin();
45    }
46}