use crate::{ColorDepth, TermCap};
crate::bitfield! {
#[must_use]
#[doc = crate::_tags!(term runtime set bit)]
#[doc = crate::_doc_meta!{
location("sys/os/term"),
test_size_of(TermCaps = 4|32),
}]
pub struct TermCaps(u32) {
KEYBOARD = 0;
MOUSE = 1;
MOUSE_DRAG = 2;
MOUSE_MOTION = 3;
MOUSE_SGR = 4;
MOUSE_SGR_PIXELS = 5;
FOCUS = 6;
BRACKETED_PASTE = 7;
RESIZE = 8;
ANSI = 9;
CURSOR = 10;
STYLE = 11;
ALT_SCREEN = 12;
SYNC_UPDATE = 13;
SIXEL = 14;
KITTY_IMAGE = 15;
ITERM_IMAGE = 16;
QUERY_DEVICE_ATTRS = 17;
QUERY_CURSOR_POS = 18;
QUERY_COLOR = 19;
COLOR_DEPTH = 20..=22; }
impl {
pub const EMPTY: Self = Self::new();
pub const ANSI_BASE: Self = Self::new()
.with_keyboard(1)
.with_ansi(1)
.with_cursor(1)
.with_style(1)
.with_color_depth_enum(ColorDepth::Ansi4);
#[must_use]
pub const fn color_depth(self) -> ColorDepth {
ColorDepth::from_bits_trunc(self.get_color_depth() as u8)
}
pub const fn with_color_depth_enum(self, depth: ColorDepth) -> Self {
self.with_color_depth(depth as u32)
}
pub const fn set_color_depth_enum(&mut self, depth: ColorDepth) {
self.set_color_depth(depth as u32);
}
#[must_use]
pub const fn has(self, cap: TermCap) -> bool {
self.bits() & cap.bit() != 0
}
pub const fn set_cap(&mut self, cap: TermCap) {
*self = self.with_cap(cap);
}
pub const fn unset_cap(&mut self, cap: TermCap) {
*self = self.without_cap(cap);
}
pub const fn with_cap(self, cap: TermCap) -> Self {
Self::from_bits(self.bits() | cap.bit())
}
pub const fn without_cap(self, cap: TermCap) -> Self {
Self::from_bits(self.bits() & !cap.bit())
}
}
}