use crate::error::{Error, check};
use libghostty_vt_sys as sys;
use std::mem::MaybeUninit;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum CellWide {
Narrow,
Wide,
SpacerTail,
SpacerHead,
}
impl From<sys::GhosttyCellWide> for CellWide {
fn from(w: sys::GhosttyCellWide) -> Self {
match w {
sys::GhosttyCellWide::GHOSTTY_CELL_WIDE_NARROW => CellWide::Narrow,
sys::GhosttyCellWide::GHOSTTY_CELL_WIDE_WIDE => CellWide::Wide,
sys::GhosttyCellWide::GHOSTTY_CELL_WIDE_SPACER_TAIL => CellWide::SpacerTail,
sys::GhosttyCellWide::GHOSTTY_CELL_WIDE_SPACER_HEAD => CellWide::SpacerHead,
_ => CellWide::Narrow,
}
}
}
#[derive(Debug, Copy, Clone)]
pub struct RawCell(pub(crate) sys::GhosttyCell);
impl RawCell {
pub fn wide(&self) -> Result<CellWide, Error> {
let mut out = MaybeUninit::<sys::GhosttyCellWide>::uninit();
let r = unsafe {
sys::ghostty_cell_get(
self.0,
sys::GhosttyCellData::GHOSTTY_CELL_DATA_WIDE,
out.as_mut_ptr().cast(),
)
};
check(r)?;
Ok(unsafe { out.assume_init() }.into())
}
pub fn as_raw(&self) -> sys::GhosttyCell {
self.0
}
}