Files
LLeMbas-TTY/term/src/lib.rs
T
Wez Furlong 5abc4e543e rendering now respects cursor visibility
This commit adds some plumbing for describing the cursor shape
(block, line, blinking etc) and visibility, and feeds that through
the mux and render layers.

The renderer now knows to omit the cursor when it is not visible.
2019-12-22 08:52:51 -08:00

101 lines
3.2 KiB
Rust

//! Terminal model
use serde_derive::*;
use anyhow::Error;
use std::ops::{Deref, DerefMut, Range};
use std::str;
pub mod config;
pub use config::TerminalConfiguration;
pub mod input;
pub use crate::input::*;
pub use termwiz::cell::{self, *};
pub use termwiz::surface::line::*;
pub mod screen;
pub use crate::screen::*;
pub mod selection;
use crate::selection::{SelectionCoordinate, SelectionRange};
use termwiz::hyperlink::Hyperlink;
pub mod terminal;
pub use crate::terminal::*;
pub mod terminalstate;
pub use crate::terminalstate::*;
/// Represents the index into screen.lines. Index 0 is the top of
/// the scrollback (if any). The index of the top of the visible screen
/// depends on the terminal dimensions and the scrollback size.
pub type PhysRowIndex = usize;
/// Represents an index into the visible portion of the screen.
/// Value 0 is the first visible row. `VisibleRowIndex` needs to be
/// resolved into a `PhysRowIndex` to obtain an actual row. It is not
/// valid to have a negative `VisibleRowIndex` value so this type logically
/// should be unsigned, however, having a different sign is helpful to
/// have the compiler catch accidental arithmetic performed between
/// `PhysRowIndex` and `VisibleRowIndex`. We could define our own type with
/// its own `Add` and `Sub` operators, but then we'd not be able to iterate
/// over `Ranges` of these types without also laboriously implementing an
/// iterator `Skip` trait that is currently only in unstable rust.
pub type VisibleRowIndex = i64;
/// Like `VisibleRowIndex` above, but can index backwards into scrollback.
/// This is deliberately a differently sized signed type to catch
/// accidentally blending together the wrong types of indices.
/// This is explicitly 32-bit rather than 64-bit as it seems unreasonable
/// to want to scroll back or select more than ~2billion lines of scrollback.
pub type ScrollbackOrVisibleRowIndex = i32;
/// Returns true if r1 intersects r2
pub fn intersects_range<T: Ord + Copy>(r1: Range<T>, r2: Range<T>) -> bool {
use std::cmp::{max, min};
let start = max(r1.start, r2.start);
let end = min(r1.end, r2.end);
end > start
}
/// Position allows referring to an absolute visible row number
/// or a position relative to some existing row number (typically
/// where the cursor is located). Both of the cases are represented
/// as signed numbers so that the math and error checking for out
/// of range values can be deferred to the point where we execute
/// the request.
#[derive(Debug)]
pub enum Position {
Absolute(VisibleRowIndex),
Relative(i64),
}
/// Describes the location of the cursor in the visible portion
/// of the screen.
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Deserialize, Serialize)]
pub struct CursorPosition {
pub x: usize,
pub y: VisibleRowIndex,
pub shape: termwiz::surface::CursorShape,
}
pub mod color;
#[cfg(test)]
mod test;
/// The response we given when queries for device attributes.
/// This particular string says "we are a VT102".
/// TODO: Consider VT220 extended response which can advertise
/// certain feature sets.
pub const DEVICE_IDENT: &[u8] = b"\x1b[?6c";
pub const CSI: &[u8] = b"\x1b[";
pub const OSC: &[u8] = b"\x1b]";
pub const ST: &[u8] = b"\x1b\\";
pub const DCS: &[u8] = b"\x1bP";