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
122
123
124
125
126
127
#![allow(deprecated)]
use std::ptr;
use crate::{
NCurseswError,
gen::{ColorPairType, ColorPairGeneric, ColorPairColors, ColorsType},
ncursescolortype::{set_ncurses_colortype, NCursesColorType},
shims::ncurses::SCREEN,
extend::{Colors, Color},
ncurses::{
init_extended_pair, extended_pair_content,
init_extended_pair_sp, extended_pair_content_sp
}
};
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct ColorPair {
screen: Option<SCREEN>,
number: i32
}
impl ColorPair {
pub(in crate) fn _from(screen: Option<SCREEN>, number: i32) -> Self {
assert!(screen.map_or_else(|| true, |screen| !screen.is_null()), "ColorPair::_from() : screen.is_null()");
set_ncurses_colortype(NCursesColorType::Extend);
Self { screen, number }
}
}
impl ColorPair {
pub fn new(pair: i32, colors: Colors) -> result!(Self) {
assert!(colors.screen().is_none(), "ColorPair::new() : colors.screen().is_some()");
init_extended_pair(pair, colors)
}
pub fn new_sp(screen: SCREEN, pair: i32, colors: Colors) -> result!(Self) {
assert!(colors.screen().map_or_else(|| false, |colors_screen| ptr::eq(screen, colors_screen)), "ColorPair::new_sp() : screen.is_null() || screen != colors.screen()");
init_extended_pair_sp(screen, pair, colors)
}
pub unsafe fn set_screen(&mut self, screen: Option<SCREEN>) {
self.screen = screen
}
}
impl ColorPairColors<Colors, Color, i32> for ColorPair {
fn colors(&self) -> result!(Colors) {
match self.screen {
None => extended_pair_content(self.number),
Some(screen) => extended_pair_content_sp(screen, self.number)
}
}
}
impl ColorPairType<i32> for ColorPair {
fn screen(&self) -> Option<SCREEN> {
self.screen
}
fn number(&self) -> i32 {
self.number
}
}
impl ColorPairGeneric<i32> for ColorPair {
fn as_const_ptr(&self) -> *const libc::c_void {
let color_pair = self.number;
let ptr: *const i32 = &color_pair;
ptr as *const libc::c_void
}
fn as_mut_ptr(&self) -> *mut libc::c_void {
let mut color_pair = self.number;
let ptr: *mut i32 = &mut color_pair;
ptr as *mut libc::c_void
}
}
impl AsRef<ColorPair> for ColorPair {
fn as_ref(&self) -> &Self {
self
}
}
impl AsMut<ColorPair> for ColorPair {
fn as_mut(&mut self) -> &mut Self {
self
}
}