use std::{fmt::{Display, Formatter}, sync::atomic::{AtomicBool, Ordering}};
lazy_static! {
static ref EXTENDED_COLORS: AtomicBool = AtomicBool::new(false);
static ref EXTENDED_COLORS_ALREADY_SET: AtomicBool = AtomicBool::new(false);
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum NCursesColorType {
Normal,
Extend
}
impl Display for NCursesColorType {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "{}", match self {
NCursesColorType::Normal => "Normal",
NCursesColorType::Extend => "Extend"
})
}
}
pub fn ncurses_colortype() -> NCursesColorType {
if EXTENDED_COLORS.load(Ordering::SeqCst) {
NCursesColorType::Extend
} else {
NCursesColorType::Normal
}
}
pub fn ncurses_colortype_set() -> bool {
EXTENDED_COLORS_ALREADY_SET.load(Ordering::SeqCst)
}
pub(in crate) fn set_ncurses_colortype(colortype: NCursesColorType) {
let set_colortype = ncurses_colortype();
if colortype != set_colortype {
if ncurses_colortype_set() {
panic!("ncursesw color type already set as {}!", set_colortype);
} else {
EXTENDED_COLORS_ALREADY_SET.store(true, Ordering::SeqCst);
EXTENDED_COLORS.store(match colortype {
NCursesColorType::Normal => false,
NCursesColorType::Extend => true
},
Ordering::SeqCst
);
}
}
}