use crate::profile::{ColorSlot, Rgb};
use crate::terminal::cell::{Color, EmuCell};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum CursorShape {
#[default]
Block,
Underline,
Bar,
}
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct KeyboardMode: u8 {
const DISAMBIGUATE_ESC_CODES = 1;
const REPORT_EVENT_TYPES = 1 << 1;
const REPORT_ALTERNATE_KEYS = 1 << 2;
const REPORT_ALL_KEYS_AS_ESC = 1 << 3;
const REPORT_ASSOCIATED_TEXT = 1 << 4;
}
}
pub trait Emulator: Send {
fn process(&mut self, bytes: &[u8]);
fn take_pending_writes(&mut self) -> Vec<u8>;
fn keyboard_mode(&self) -> KeyboardMode {
KeyboardMode::empty()
}
fn resize(&mut self, cols: u16, rows: u16);
fn size(&self) -> (u16, u16);
fn cursor(&self) -> (u16, u16);
fn title(&self) -> Option<String>;
fn cursor_visible(&self) -> bool;
fn cursor_shape(&self) -> CursorShape;
fn viewable_rows(&self) -> Vec<Vec<EmuCell>>;
fn full_rows(&self) -> Vec<Vec<EmuCell>>;
fn color(&self, slot: ColorSlot) -> Rgb;
fn resolve(&self, color: Option<Color>, is_fg: bool) -> Rgb {
match color {
None => self.color(if is_fg {
ColorSlot::Foreground
} else {
ColorSlot::Background
}),
Some(Color::Named(n)) => self.color(ColorSlot::Indexed(n.index())),
Some(Color::Idx(i)) => self.color(ColorSlot::Indexed(i)),
Some(Color::Rgb(r, g, b)) => Rgb::new(r, g, b),
}
}
}