#![allow(clippy::from_over_into)]
use std::convert::TryInto;
use crate::{
gen::{AttributesType, ColorPairType, ColorAttributeTypes},
ncurseswerror::NCurseswError,
shims::bindings::cchar_t,
wide::WideChar,
ncurses::{setcchar, wunctrl}
};
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct ComplexChar {
inner: cchar_t
}
impl ComplexChar {
pub fn from_wide_char<A, P, T>(ch: WideChar, attrs: &A, color_pair: &P) -> result!(Self)
where A: AttributesType<T>,
P: ColorPairType<T>,
T: ColorAttributeTypes
{
setcchar(WideChar::try_into(ch)?, attrs, color_pair)
}
pub fn from_char<A, P, T>(ch: char, attrs: &A, color_pair: &P) -> result!(Self)
where A: AttributesType<T>,
P: ColorPairType<T>,
T: ColorAttributeTypes
{
setcchar(ch, attrs, color_pair)
}
pub fn as_wide_char(self) -> result!(WideChar) {
wunctrl(self)
}
}
impl From<cchar_t> for ComplexChar {
fn from(raw: cchar_t) -> Self {
Self { inner: raw }
}
}
impl Into<cchar_t> for ComplexChar {
fn into(self) -> cchar_t {
self.inner
}
}