use crate::cell::{Cell, CellFlags};
use crate::color::Color;
#[derive(Clone, Copy, Debug, Default)]
pub struct Pen {
pub fg: Color,
pub bg: Color,
pub flags: CellFlags,
pub underline_color: Color,
}
impl Pen {
pub fn reset(&mut self) {
*self = Pen::default();
}
pub fn cell(&self, c: char) -> Cell {
Cell::from_parts(c, self.fg, self.bg, self.flags)
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum CursorShape {
#[default]
Block,
Underline,
Bar,
}
#[derive(Clone, Copy, Debug)]
pub struct Cursor {
pub row: usize,
pub col: usize,
pub pending_wrap: bool,
pub pen: Pen,
pub visible: bool,
pub shape: CursorShape,
pub blink: bool,
}
impl Cursor {
pub(crate) fn point(&self) -> (usize, usize) {
(self.row, self.col)
}
pub(crate) fn set_point(&mut self, point: (usize, usize), rows: usize, cols: usize) {
self.row = point.0.min(rows - 1);
self.col = point.1.min(cols - 1);
}
}
impl Default for Cursor {
fn default() -> Self {
Cursor {
row: 0,
col: 0,
pending_wrap: false,
pen: Pen::default(),
visible: true,
shape: CursorShape::Block,
blink: false,
}
}
}