use libghostty_vt_sys as sys;
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Default)]
pub struct RgbColor {
pub r: u8,
pub g: u8,
pub b: u8,
}
impl From<sys::GhosttyColorRgb> for RgbColor {
fn from(c: sys::GhosttyColorRgb) -> Self {
RgbColor {
r: c.r,
g: c.g,
b: c.b,
}
}
}
impl From<RgbColor> for sys::GhosttyColorRgb {
fn from(c: RgbColor) -> Self {
sys::GhosttyColorRgb {
r: c.r,
g: c.g,
b: c.b,
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Default)]
pub enum Underline {
#[default]
None,
Single,
Double,
Curly,
Dotted,
Dashed,
}
impl Underline {
fn from_sgr_int(v: std::os::raw::c_int) -> Self {
#[allow(clippy::unnecessary_cast)]
match sys::GhosttySgrUnderline(v as _) {
sys::GhosttySgrUnderline::GHOSTTY_SGR_UNDERLINE_NONE => Underline::None,
sys::GhosttySgrUnderline::GHOSTTY_SGR_UNDERLINE_SINGLE => Underline::Single,
sys::GhosttySgrUnderline::GHOSTTY_SGR_UNDERLINE_DOUBLE => Underline::Double,
sys::GhosttySgrUnderline::GHOSTTY_SGR_UNDERLINE_CURLY => Underline::Curly,
sys::GhosttySgrUnderline::GHOSTTY_SGR_UNDERLINE_DOTTED => Underline::Dotted,
sys::GhosttySgrUnderline::GHOSTTY_SGR_UNDERLINE_DASHED => Underline::Dashed,
_ => Underline::None,
}
}
}
#[derive(Debug, Copy, Clone, Default)]
pub struct Style {
pub bold: bool,
pub italic: bool,
pub faint: bool,
pub blink: bool,
pub inverse: bool,
pub invisible: bool,
pub strikethrough: bool,
pub overline: bool,
pub underline: Underline,
}
impl From<sys::GhosttyStyle> for Style {
fn from(s: sys::GhosttyStyle) -> Self {
Style {
bold: s.bold,
italic: s.italic,
faint: s.faint,
blink: s.blink,
inverse: s.inverse,
invisible: s.invisible,
strikethrough: s.strikethrough,
overline: s.overline,
underline: Underline::from_sgr_int(s.underline),
}
}
}
impl Style {
pub(crate) fn default_sys() -> sys::GhosttyStyle {
let mut s = std::mem::MaybeUninit::<sys::GhosttyStyle>::zeroed();
unsafe {
let ptr = s.as_mut_ptr();
(*ptr).size = std::mem::size_of::<sys::GhosttyStyle>();
sys::ghostty_style_default(ptr);
s.assume_init()
}
}
}