pub trait Cursor {
// Provided methods
fn set_cursor_visible(&mut self, _visible: bool) { ... }
fn set_cursor_position(&mut self, _position: Pos<u16>) { ... }
fn set_cursor_style(&mut self, _style: CursorStyle) { ... }
}Expand description
Shows, hides, and moves a text cursor.
Both methods default to a no-op so backends with no text cursor to manage (pixel/windowed
backends, where games draw their own cursor if they want one) can use an empty
impl Cursor for X {} instead of writing dead stub bodies by hand.
§Examples
use retroglyph_core::backend::Cursor;
use retroglyph_core::grid::Pos;
struct TrackedCursor {
visible: bool,
position: Pos,
}
impl Cursor for TrackedCursor {
fn set_cursor_visible(&mut self, visible: bool) {
self.visible = visible;
}
fn set_cursor_position(&mut self, position: Pos) {
self.position = position;
}
}Provided Methods§
Sourcefn set_cursor_visible(&mut self, _visible: bool)
fn set_cursor_visible(&mut self, _visible: bool)
Show or hide the cursor.
Sourcefn set_cursor_position(&mut self, _position: Pos<u16>)
fn set_cursor_position(&mut self, _position: Pos<u16>)
Move the cursor to a position.
Sourcefn set_cursor_style(&mut self, _style: CursorStyle)
fn set_cursor_style(&mut self, _style: CursorStyle)
Set the cursor’s shape (and blink behavior).
Defaults to a no-op, matching set_cursor_visible/
set_cursor_position: backends with no text cursor to
manage, or that render on a terminal emulator with no shape-changing escape sequence,
can ignore this via the default impl Cursor for X {}.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
§impl Cursor for SoftwareRenderer
impl Cursor for SoftwareRenderer
fn set_cursor_visible(&mut self, _visible: bool)
fn set_cursor_position(&mut self, _position: Pos<u16>)
Source§impl Cursor for TerminalWasm
impl Cursor for TerminalWasm
Source§fn set_cursor_style(&mut self, style: CursorStyle)
fn set_cursor_style(&mut self, style: CursorStyle)
Writes the DECSCUSR cursor-shape escape.
This is the standard VT100/ANSI (DEC private mode) cursor-shape sequence and is not one of
the areas where browser terminal emulators diverge: both xterm.js
(https://xtermjs.org/docs/api/vtfeatures/) and hterm/Terminalemulator
(https://chromium.googlesource.com/apps/libapps/+/HEAD/hterm/docs/ControlSequences.md)
implement CSI Ps SP q identically.
fn set_cursor_visible(&mut self, visible: bool)
fn set_cursor_position(&mut self, position: Pos<u16>)
impl<P> Cursor for WindowBackend<P>where
P: Presenter,
Source§impl<W> Cursor for Crossterm<W>where
W: Write,
impl<W> Cursor for Crossterm<W>where
W: Write,
Source§fn set_cursor_visible(&mut self, visible: bool)
fn set_cursor_visible(&mut self, visible: bool)
Queues the show/hide escape without flushing; the next Output::flush call drains it
along with everything else. A caller that hides the cursor and moves it in the same frame
(a common pattern right before a draw) would otherwise pay an extra flush per call on top
of the normal draw/flush pair, with no observable benefit since nothing reads the terminal
state in between.
Source§fn set_cursor_position(&mut self, position: Pos<u16>)
fn set_cursor_position(&mut self, position: Pos<u16>)
Queues the cursor-move escape without flushing; see set_cursor_visible’s
docs for why this is deferred to the next Output::flush instead of flushing here.
Source§fn set_cursor_style(&mut self, style: CursorStyle)
fn set_cursor_style(&mut self, style: CursorStyle)
Queues the DECSCUSR cursor-shape escape without flushing; see
set_cursor_visible’s docs for why this is deferred to the
next Output::flush instead of flushing here.