//! Cursor style decision logic (`renderer/cursor.zig`). /// Terminal cursor styles (`terminal.CursorStyle`). // TODO(integration): replace with ghostty_terminal's CursorStyle. #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub enum TerminalCursorStyle { Bar, #[default] Block, BlockHollow, Underline, } /// The subset of `terminal.RenderState.cursor` that the cursor style /// decision needs. // TODO(integration): replace with `&ghostty_terminal::RenderState` (use its // `cursor` field) once the terminal crate is a dependency. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct RenderStateCursor { /// Viewport position of the cursor (`None` if it isn't in the viewport). pub viewport: Option<(u16, u16)>, /// Whether the terminal is at a password prompt. pub password_input: bool, /// Cursor visibility via terminal mode. pub visible: bool, /// Whether the cursor is blinking. pub blinking: bool, /// The visual style requested by the terminal. pub visual_style: TerminalCursorStyle, } /// Available cursor styles for drawing that renderers must support. /// This is a superset of terminal cursor styles since the renderer supports /// some additional cursor states such as the hollow block. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Style { // Typical cursor input styles Block, BlockHollow, Bar, Underline, // Special cursor styles Lock, } impl Style { /// Create a cursor style from the terminal style request. pub fn from_terminal(term: TerminalCursorStyle) -> Style { match term { TerminalCursorStyle::Bar => Style::Bar, TerminalCursorStyle::Block => Style::Block, TerminalCursorStyle::BlockHollow => Style::BlockHollow, TerminalCursorStyle::Underline => Style::Underline, } } } #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub struct StyleOptions { pub preedit: bool, pub focused: bool, pub blink_visible: bool, } /// Returns the cursor style to use for the current render state or None /// if a cursor should not be rendered at all. pub fn style(state: &RenderStateCursor, opts: StyleOptions) -> Option