1
2
3
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
96
97
98
99
100
101
102
103
104
105
106
use ncurses::*;
use crate::io_attrs::*;
use crate::cursor::*;
use crate::utils::{ScreenRect,ScreenPoint};
pub trait Window {
fn move_print(&mut self, point: ScreenPoint, text: &str) {
mvaddstr(point.y as i32, point.x as i32, text);
}
fn print(&mut self, text: &str) {
addstr(text);
}
}
pub trait MovableWindow {
fn movew(&mut self, x: u32, y: u32);
}
pub struct MainWindow {
}
impl Window for MainWindow {
}
impl MainWindow {
pub fn init() -> Self {
initscr();
set_cbreak(true);
set_echo(false);
curs_set(CURSOR_VISIBILITY::CURSOR_INVISIBLE);
MainWindow {}
}
pub fn read_char(&self) -> char {
getch() as u8 as char
}
}
impl Drop for MainWindow {
fn drop(&mut self) {
set_echo(true);
set_cbreak(false);
set_cursor(CursorState::Visible);
endwin();
}
}
pub struct SubWindow {
this: WINDOW,
}
pub enum SubWindowError {
CoordinateError(ScreenRect),
OtherError,
}
impl SubWindow {
pub fn init(rect: ScreenRect) -> Result<Self,SubWindowError>{
let win = newwin(
rect.offset.y as i32,
rect.offset.x as i32,
rect.start.y as i32,
rect.start.x as i32
);
if win == 0 as *mut i8 {
Err(SubWindowError::CoordinateError(rect))
} else {
Ok(SubWindow { this: win })
}
}
}
impl Window for SubWindow {
fn move_print(&mut self, point: ScreenPoint, text: &str) {
mvwaddstr(self.this, point.y as i32, point.x as i32, text);
}
fn print(&mut self, text: &str) {
waddstr(self.this, text);
}
}
impl Drop for SubWindow {
fn drop(&mut self) {
delwin(self.this);
}
}