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
pub type NcStyle = u16;
pub trait NcStyleApi {
const MASK: u16 = constants::NCSTYLE_MASK as u16;
const ITALIC: u16 = constants::NCSTYLE_ITALIC as u16;
const UNDERLINE: u16 = constants::NCSTYLE_UNDERLINE as u16;
const UNDERCURL: u16 = constants::NCSTYLE_UNDERCURL as u16;
const STRUCK: u16 = constants::NCSTYLE_STRUCK as u16;
const BOLD: u16 = constants::NCSTYLE_BOLD as u16;
const NOSTYLE: u16 = constants::NCSTYLE_NONE as u16;
fn add(&mut self, other_style: NcStyle);
fn has(&self, other: NcStyle) -> bool;
fn to_vec(&self) -> Vec<NcStyle>;
}
impl NcStyleApi for NcStyle {
fn to_vec(&self) -> Vec<NcStyle> {
let mut v = vec![];
let styles = [
NcStyle::ITALIC,
NcStyle::UNDERLINE,
NcStyle::UNDERCURL,
NcStyle::STRUCK,
NcStyle::BOLD,
NcStyle::NOSTYLE,
];
for s in &styles {
if self.has(*s) {
v.push(*s)
}
}
v
}
fn has(&self, other_style: NcStyle) -> bool {
(self & other_style) == other_style
}
fn add(&mut self, other_style: NcStyle) {
*self |= other_style
}
}
pub(crate) mod constants {
pub const NCSTYLE_MASK: u16 = crate::bindings::ffi::NCSTYLE_MASK as u16;
pub const NCSTYLE_ITALIC: u16 = crate::bindings::ffi::NCSTYLE_ITALIC as u16;
pub const NCSTYLE_UNDERLINE: u16 = crate::bindings::ffi::NCSTYLE_UNDERLINE as u16;
pub const NCSTYLE_UNDERCURL: u16 = crate::bindings::ffi::NCSTYLE_UNDERCURL as u16;
pub const NCSTYLE_STRUCK: u16 = crate::bindings::ffi::NCSTYLE_STRUCK as u16;
pub const NCSTYLE_BOLD: u16 = crate::bindings::ffi::NCSTYLE_BOLD as u16;
pub const NCSTYLE_NONE: u16 = crate::bindings::ffi::NCSTYLE_NONE as u16;
}