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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
use core::ptr::{null, null_mut};
use crate::{
Nc, NcAlign, NcDim, NcError, NcInput, NcOffset, NcPlane, NcResult, NcTime, NCALIGN_CENTER,
NCALIGN_LEFT, NCALIGN_RIGHT, NCRESULT_MAX,
};
#[inline]
pub fn notcurses_align(availcols: NcDim, align: NcAlign, cols: NcDim) -> NcOffset {
if align == NCALIGN_LEFT {
return 0;
}
if cols > availcols {
return 0;
}
if align == NCALIGN_CENTER {
return ((availcols - cols) / 2) as NcOffset;
}
if align == NCALIGN_RIGHT {
return (availcols - cols) as NcOffset;
}
-NCRESULT_MAX
}
#[inline]
pub fn notcurses_getc_nblock(nc: &mut Nc, input: &mut NcInput) -> char {
unsafe {
let ts = NcTime {
tv_sec: 0,
tv_nsec: 0,
};
core::char::from_u32_unchecked(crate::notcurses_getc(nc, &ts, null_mut(), input))
}
}
#[inline]
pub fn notcurses_getc_blocking(nc: &mut Nc, input: Option<&mut NcInput>) -> char {
let input_ptr;
if let Some(i) = input {
input_ptr = i as *mut _;
} else {
input_ptr = null_mut();
}
unsafe {
core::char::from_u32_unchecked(crate::notcurses_getc(nc, null(), null_mut(), input_ptr))
}
}
#[inline]
pub fn notcurses_stddim_yx<'a>(
nc: &'a mut Nc,
y: &mut NcDim,
x: &mut NcDim,
) -> NcResult<&'a mut NcPlane> {
unsafe {
let sp = crate::notcurses_stdplane(nc);
if !sp.is_null() {
crate::ncplane_dim_yx(sp, &mut (*y as i32), &mut (*x as i32));
return Ok(&mut *sp);
}
}
Err(NcError::new())
}
#[inline]
pub fn notcurses_stddim_yx_const<'a>(
nc: &'a Nc,
y: &mut NcDim,
x: &mut NcDim,
) -> NcResult<&'a NcPlane> {
unsafe {
let sp = crate::notcurses_stdplane_const(nc);
if !sp.is_null() {
crate::ncplane_dim_yx(sp, &mut (*y as i32), &mut (*x as i32));
return Ok(&*sp);
}
}
Err(NcError::new())
}
#[inline]
pub fn notcurses_term_dim_yx(nc: &Nc) -> (NcDim, NcDim) {
let (mut y, mut x) = (0, 0);
unsafe {
crate::ncplane_dim_yx(crate::notcurses_stdplane_const(nc), &mut y, &mut x);
}
(y as NcDim, x as NcDim)
}