#[derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[non_exhaustive]
pub struct Output {
pub width: usize,
pub height: usize,
pub cells: Vec<Cell>,
pub cursor: Cursor,
pub title: String,
pub mode: super::native::ScreenMode,
}
#[derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[non_exhaustive]
pub struct Cell {
pub text: String,
pub foreground: Color,
pub background: Color,
}
#[derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[non_exhaustive]
pub enum Color {
Default,
PaletteIndex(u8),
TrueColor((f32, f32, f32)),
}
#[derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Cursor {
pub position: (usize, usize),
pub shape: Option<termwiz::surface::CursorShape>,
pub visibility: termwiz::surface::CursorVisibility,
}
impl From<termwiz::color::ColorAttribute> for Color {
#[inline]
fn from(attribute: termwiz::color::ColorAttribute) -> Self {
match attribute {
termwiz::color::ColorAttribute::TrueColorWithPaletteFallback(srgba_tuple, _)
| termwiz::color::ColorAttribute::TrueColorWithDefaultFallback(srgba_tuple) => {
Self::TrueColor((srgba_tuple.0, srgba_tuple.1, srgba_tuple.2))
}
termwiz::color::ColorAttribute::PaletteIndex(index) => Self::PaletteIndex(index),
termwiz::color::ColorAttribute::Default => Self::Default,
}
}
}
impl Output {
#[inline]
pub fn convert_to_foreign(
native: super::native::CompleteSurface,
) -> Result<Self, crate::errors::ShadowTerminalError> {
let super::native::CompleteSurface::Screen(mut screen) = native else {
snafu::whatever!("Converting the scrollback hasn't been implemented yet");
};
let mut cells = Vec::<Cell>::new();
for line in screen.surface.screen_cells() {
for cell in line {
cells.push(Cell {
text: cell.str().to_owned(),
background: cell.attrs().foreground().into(),
foreground: cell.attrs().background().into(),
});
}
}
screen.surface.title();
Ok(Self {
width: screen.surface.dimensions().0,
height: screen.surface.dimensions().1,
cells,
cursor: Cursor {
shape: screen.surface.cursor_shape(),
visibility: screen.surface.cursor_visibility(),
position: screen.surface.cursor_position(),
},
title: screen.surface.title().to_owned(),
mode: screen.mode,
})
}
}