2020-05-05 22:50:23 +00:00
|
|
|
//! ANSI Terminal Stream Parsing.
|
2020-06-06 18:49:14 +00:00
|
|
|
|
2020-08-07 22:37:23 +00:00
|
|
|
use std::convert::TryFrom;
|
2021-01-25 21:23:08 +00:00
|
|
|
use std::time::{Duration, Instant};
|
2021-04-17 23:20:13 +00:00
|
|
|
use std::{iter, str};
|
2016-07-04 04:58:35 +00:00
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
use log::{debug, trace};
|
|
|
|
use serde::{Deserialize, Serialize};
|
2020-08-07 22:37:23 +00:00
|
|
|
use vte::{Params, ParamsIter};
|
2019-10-05 00:29:26 +00:00
|
|
|
|
2020-12-31 05:52:45 +00:00
|
|
|
use alacritty_config_derive::ConfigDeserialize;
|
|
|
|
|
2019-11-03 20:59:28 +00:00
|
|
|
use crate::index::{Column, Line};
|
2019-02-07 22:36:45 +00:00
|
|
|
use crate::term::color::Rgb;
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
|
2021-01-25 21:23:08 +00:00
|
|
|
/// Maximum time before a synchronized update is aborted.
|
|
|
|
const SYNC_UPDATE_TIMEOUT: Duration = Duration::from_millis(150);
|
|
|
|
|
|
|
|
/// Maximum number of bytes read in one synchronized update (2MiB).
|
|
|
|
const SYNC_BUFFER_SIZE: usize = 0x20_0000;
|
|
|
|
|
|
|
|
/// Number of bytes in the synchronized update DCS sequence before the passthrough parameters.
|
|
|
|
const SYNC_ESCAPE_START_LEN: usize = 5;
|
|
|
|
|
|
|
|
/// Start of the DCS sequence for beginning synchronized updates.
|
|
|
|
const SYNC_START_ESCAPE_START: [u8; SYNC_ESCAPE_START_LEN] = [b'\x1b', b'P', b'=', b'1', b's'];
|
|
|
|
|
|
|
|
/// Start of the DCS sequence for terminating synchronized updates.
|
|
|
|
const SYNC_END_ESCAPE_START: [u8; SYNC_ESCAPE_START_LEN] = [b'\x1b', b'P', b'=', b'2', b's'];
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Parse colors in XParseColor format.
|
2019-08-19 19:56:27 +00:00
|
|
|
fn xparse_color(color: &[u8]) -> Option<Rgb> {
|
|
|
|
if !color.is_empty() && color[0] == b'#' {
|
2019-08-28 00:35:34 +00:00
|
|
|
parse_legacy_color(&color[1..])
|
2019-08-19 19:56:27 +00:00
|
|
|
} else if color.len() >= 4 && &color[..4] == b"rgb:" {
|
2019-08-28 00:35:34 +00:00
|
|
|
parse_rgb_color(&color[4..])
|
2019-08-19 19:56:27 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Parse colors in `rgb:r(rrr)/g(ggg)/b(bbb)` format.
|
2017-07-28 22:14:18 +00:00
|
|
|
fn parse_rgb_color(color: &[u8]) -> Option<Rgb> {
|
2019-08-19 19:56:27 +00:00
|
|
|
let colors = str::from_utf8(color).ok()?.split('/').collect::<Vec<_>>();
|
2017-07-28 22:14:18 +00:00
|
|
|
|
2019-08-19 19:56:27 +00:00
|
|
|
if colors.len() != 3 {
|
|
|
|
return None;
|
2017-07-28 22:14:18 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Scale values instead of filling with `0`s.
|
2019-08-19 19:56:27 +00:00
|
|
|
let scale = |input: &str| {
|
2020-11-26 00:57:44 +00:00
|
|
|
if input.len() > 4 {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
let max = u32::pow(16, input.len() as u32) - 1;
|
|
|
|
let value = u32::from_str_radix(input, 16).ok()?;
|
|
|
|
Some((255 * value / max) as u8)
|
|
|
|
}
|
2019-08-19 19:56:27 +00:00
|
|
|
};
|
2017-07-28 22:14:18 +00:00
|
|
|
|
2019-08-24 23:18:51 +00:00
|
|
|
Some(Rgb { r: scale(colors[0])?, g: scale(colors[1])?, b: scale(colors[2])? })
|
2019-08-19 19:56:27 +00:00
|
|
|
}
|
2017-07-28 22:14:18 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Parse colors in `#r(rrr)g(ggg)b(bbb)` format.
|
2019-08-19 19:56:27 +00:00
|
|
|
fn parse_legacy_color(color: &[u8]) -> Option<Rgb> {
|
|
|
|
let item_len = color.len() / 3;
|
2017-07-28 22:14:18 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Truncate/Fill to two byte precision.
|
2019-08-19 19:56:27 +00:00
|
|
|
let color_from_slice = |slice: &[u8]| {
|
|
|
|
let col = usize::from_str_radix(str::from_utf8(slice).ok()?, 16).ok()? << 4;
|
|
|
|
Some((col >> (4 * slice.len().saturating_sub(1))) as u8)
|
|
|
|
};
|
2017-07-28 22:14:18 +00:00
|
|
|
|
2019-08-19 19:56:27 +00:00
|
|
|
Some(Rgb {
|
|
|
|
r: color_from_slice(&color[0..item_len])?,
|
|
|
|
g: color_from_slice(&color[item_len..item_len * 2])?,
|
|
|
|
b: color_from_slice(&color[item_len * 2..])?,
|
|
|
|
})
|
2017-07-28 22:14:18 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 03:11:21 +00:00
|
|
|
fn parse_number(input: &[u8]) -> Option<u8> {
|
|
|
|
if input.is_empty() {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
let mut num: u8 = 0;
|
|
|
|
for c in input {
|
|
|
|
let c = *c as char;
|
|
|
|
if let Some(digit) = c.to_digit(10) {
|
|
|
|
num = match num.checked_mul(10).and_then(|v| v.checked_add(digit as u8)) {
|
|
|
|
Some(v) => v,
|
|
|
|
None => return None,
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Some(num)
|
|
|
|
}
|
|
|
|
|
2021-01-25 21:23:08 +00:00
|
|
|
/// Internal state for VTE processor.
|
|
|
|
#[derive(Debug, Default)]
|
|
|
|
struct ProcessorState {
|
|
|
|
/// Last processed character for repetition.
|
|
|
|
preceding_char: Option<char>,
|
|
|
|
|
|
|
|
/// DCS sequence waiting for termination.
|
|
|
|
dcs: Option<Dcs>,
|
|
|
|
|
|
|
|
/// State for synchronized terminal updates.
|
|
|
|
sync_state: SyncState,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
struct SyncState {
|
|
|
|
/// Expiration time of the synchronized update.
|
|
|
|
timeout: Option<Instant>,
|
|
|
|
|
|
|
|
/// Sync DCS waiting for termination sequence.
|
|
|
|
pending_dcs: Option<Dcs>,
|
|
|
|
|
|
|
|
/// Bytes read during the synchronized update.
|
|
|
|
buffer: Vec<u8>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for SyncState {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self { buffer: Vec::with_capacity(SYNC_BUFFER_SIZE), pending_dcs: None, timeout: None }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Pending DCS sequence.
|
|
|
|
#[derive(Debug)]
|
|
|
|
enum Dcs {
|
|
|
|
/// Begin of the synchronized update.
|
|
|
|
SyncStart,
|
|
|
|
|
|
|
|
/// End of the synchronized update.
|
|
|
|
SyncEnd,
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// The processor wraps a `vte::Parser` to ultimately call methods on a Handler.
|
2021-01-25 21:23:08 +00:00
|
|
|
#[derive(Default)]
|
2016-09-18 18:17:44 +00:00
|
|
|
pub struct Processor {
|
|
|
|
state: ProcessorState,
|
|
|
|
parser: vte::Parser,
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
}
|
|
|
|
|
2021-01-25 21:23:08 +00:00
|
|
|
impl Processor {
|
|
|
|
#[inline]
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self::default()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Process a new byte from the PTY.
|
|
|
|
#[inline]
|
2021-04-17 23:20:13 +00:00
|
|
|
pub fn advance<H>(&mut self, handler: &mut H, byte: u8)
|
2021-01-25 21:23:08 +00:00
|
|
|
where
|
|
|
|
H: Handler,
|
|
|
|
{
|
|
|
|
if self.state.sync_state.timeout.is_none() {
|
2021-04-17 23:20:13 +00:00
|
|
|
let mut performer = Performer::new(&mut self.state, handler);
|
2021-01-25 21:23:08 +00:00
|
|
|
self.parser.advance(&mut performer, byte);
|
|
|
|
} else {
|
2021-04-17 23:20:13 +00:00
|
|
|
self.advance_sync(handler, byte);
|
2021-01-25 21:23:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// End a synchronized update.
|
2021-04-17 23:20:13 +00:00
|
|
|
pub fn stop_sync<H>(&mut self, handler: &mut H)
|
2021-01-25 21:23:08 +00:00
|
|
|
where
|
|
|
|
H: Handler,
|
|
|
|
{
|
|
|
|
// Process all synchronized bytes.
|
|
|
|
for i in 0..self.state.sync_state.buffer.len() {
|
|
|
|
let byte = self.state.sync_state.buffer[i];
|
2021-04-17 23:20:13 +00:00
|
|
|
let mut performer = Performer::new(&mut self.state, handler);
|
2021-01-25 21:23:08 +00:00
|
|
|
self.parser.advance(&mut performer, byte);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resetting state after processing makes sure we don't interpret buffered sync escapes.
|
|
|
|
self.state.sync_state.buffer.clear();
|
|
|
|
self.state.sync_state.timeout = None;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Synchronized update expiration time.
|
|
|
|
#[inline]
|
|
|
|
pub fn sync_timeout(&self) -> Option<&Instant> {
|
|
|
|
self.state.sync_state.timeout.as_ref()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Number of bytes in the synchronization buffer.
|
|
|
|
#[inline]
|
|
|
|
pub fn sync_bytes_count(&self) -> usize {
|
|
|
|
self.state.sync_state.buffer.len()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Process a new byte during a synchronized update.
|
|
|
|
#[cold]
|
2021-04-17 23:20:13 +00:00
|
|
|
fn advance_sync<H>(&mut self, handler: &mut H, byte: u8)
|
2021-01-25 21:23:08 +00:00
|
|
|
where
|
|
|
|
H: Handler,
|
|
|
|
{
|
|
|
|
self.state.sync_state.buffer.push(byte);
|
|
|
|
|
|
|
|
// Handle sync DCS escape sequences.
|
|
|
|
match self.state.sync_state.pending_dcs {
|
2021-04-17 23:20:13 +00:00
|
|
|
Some(_) => self.advance_sync_dcs_end(handler, byte),
|
2021-01-25 21:23:08 +00:00
|
|
|
None => self.advance_sync_dcs_start(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Find the start of sync DCS sequences.
|
|
|
|
fn advance_sync_dcs_start(&mut self) {
|
|
|
|
// Get the last few bytes for comparison.
|
|
|
|
let len = self.state.sync_state.buffer.len();
|
|
|
|
let offset = len.saturating_sub(SYNC_ESCAPE_START_LEN);
|
|
|
|
let end = &self.state.sync_state.buffer[offset..];
|
|
|
|
|
|
|
|
// Check for extension/termination of the synchronized update.
|
|
|
|
if end == SYNC_START_ESCAPE_START {
|
|
|
|
self.state.sync_state.pending_dcs = Some(Dcs::SyncStart);
|
|
|
|
} else if end == SYNC_END_ESCAPE_START || len >= SYNC_BUFFER_SIZE - 1 {
|
|
|
|
self.state.sync_state.pending_dcs = Some(Dcs::SyncEnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Parse the DCS termination sequence for synchronized updates.
|
2021-04-17 23:20:13 +00:00
|
|
|
fn advance_sync_dcs_end<H>(&mut self, handler: &mut H, byte: u8)
|
2021-01-25 21:23:08 +00:00
|
|
|
where
|
|
|
|
H: Handler,
|
|
|
|
{
|
|
|
|
match byte {
|
|
|
|
// Ignore DCS passthrough characters.
|
|
|
|
0x00..=0x17 | 0x19 | 0x1c..=0x7f | 0xa0..=0xff => (),
|
|
|
|
// Cancel the DCS sequence.
|
|
|
|
0x18 | 0x1a | 0x80..=0x9f => self.state.sync_state.pending_dcs = None,
|
|
|
|
// Dispatch on ESC.
|
|
|
|
0x1b => match self.state.sync_state.pending_dcs.take() {
|
|
|
|
Some(Dcs::SyncStart) => {
|
|
|
|
self.state.sync_state.timeout = Some(Instant::now() + SYNC_UPDATE_TIMEOUT);
|
|
|
|
},
|
2021-04-17 23:20:13 +00:00
|
|
|
Some(Dcs::SyncEnd) => self.stop_sync(handler),
|
2021-01-25 21:23:08 +00:00
|
|
|
None => (),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2017-09-29 12:05:19 +00:00
|
|
|
}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
2016-12-17 06:13:51 +00:00
|
|
|
/// Helper type that implements `vte::Perform`.
|
2016-09-18 18:17:44 +00:00
|
|
|
///
|
|
|
|
/// Processor creates a Performer when running advance and passes the Performer
|
2016-12-17 06:13:51 +00:00
|
|
|
/// to `vte::Parser`.
|
2021-04-17 23:20:13 +00:00
|
|
|
struct Performer<'a, H: Handler> {
|
2019-10-05 00:29:26 +00:00
|
|
|
state: &'a mut ProcessorState,
|
2016-12-04 23:48:30 +00:00
|
|
|
handler: &'a mut H,
|
2016-09-18 18:17:44 +00:00
|
|
|
}
|
|
|
|
|
2021-04-17 23:20:13 +00:00
|
|
|
impl<'a, H: Handler + 'a> Performer<'a, H> {
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Create a performer.
|
2016-09-18 18:17:44 +00:00
|
|
|
#[inline]
|
2021-04-17 23:20:13 +00:00
|
|
|
pub fn new<'b>(state: &'b mut ProcessorState, handler: &'b mut H) -> Performer<'b, H> {
|
|
|
|
Performer { state, handler }
|
2016-09-18 18:17:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Type that handles actions from the parser.
|
2016-09-18 18:17:44 +00:00
|
|
|
///
|
|
|
|
/// XXX Should probably not provide default impls for everything, but it makes
|
|
|
|
/// writing specific handler impls for tests far easier.
|
|
|
|
pub trait Handler {
|
2020-05-05 22:50:23 +00:00
|
|
|
/// OSC to set window title.
|
2020-03-14 15:09:10 +00:00
|
|
|
fn set_title(&mut self, _: Option<String>) {}
|
2017-01-11 05:21:19 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Set the cursor style.
|
2017-12-03 21:38:42 +00:00
|
|
|
fn set_cursor_style(&mut self, _: Option<CursorStyle>) {}
|
2017-05-28 16:38:10 +00:00
|
|
|
|
2020-11-23 23:11:03 +00:00
|
|
|
/// Set the cursor shape.
|
|
|
|
fn set_cursor_shape(&mut self, _shape: CursorShape) {}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// A character to be displayed.
|
2016-09-18 18:17:44 +00:00
|
|
|
fn input(&mut self, _c: char) {}
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Set cursor to position.
|
2018-12-10 17:53:56 +00:00
|
|
|
fn goto(&mut self, _: Line, _: Column) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Set cursor to specific row.
|
2018-12-10 17:53:56 +00:00
|
|
|
fn goto_line(&mut self, _: Line) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Set cursor to specific column.
|
2018-12-10 17:53:56 +00:00
|
|
|
fn goto_col(&mut self, _: Column) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Insert blank characters in current line starting from cursor.
|
2021-03-30 23:25:38 +00:00
|
|
|
fn insert_blank(&mut self, _: usize) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Move cursor up `rows`.
|
2021-03-30 23:25:38 +00:00
|
|
|
fn move_up(&mut self, _: usize) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Move cursor down `rows`.
|
2021-03-30 23:25:38 +00:00
|
|
|
fn move_down(&mut self, _: usize) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Identify the terminal (should write back to the pty stream).
|
2021-04-17 23:20:13 +00:00
|
|
|
fn identify_terminal(&mut self, _intermediate: Option<char>) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Report device status.
|
2021-04-17 23:20:13 +00:00
|
|
|
fn device_status(&mut self, _: usize) {}
|
2017-05-07 20:08:23 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Move cursor forward `cols`.
|
2018-12-10 17:53:56 +00:00
|
|
|
fn move_forward(&mut self, _: Column) {}
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Move cursor backward `cols`.
|
2018-12-10 17:53:56 +00:00
|
|
|
fn move_backward(&mut self, _: Column) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Move cursor down `rows` and set to column 1.
|
2021-03-30 23:25:38 +00:00
|
|
|
fn move_down_and_cr(&mut self, _: usize) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Move cursor up `rows` and set to column 1.
|
2021-03-30 23:25:38 +00:00
|
|
|
fn move_up_and_cr(&mut self, _: usize) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Put `count` tabs.
|
2020-11-26 00:57:44 +00:00
|
|
|
fn put_tab(&mut self, _count: u16) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Backspace `count` characters.
|
2016-09-18 18:17:44 +00:00
|
|
|
fn backspace(&mut self) {}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Carriage return.
|
2016-09-18 18:17:44 +00:00
|
|
|
fn carriage_return(&mut self) {}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Linefeed.
|
2016-09-18 18:17:44 +00:00
|
|
|
fn linefeed(&mut self) {}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Ring the bell.
|
2016-09-18 18:17:44 +00:00
|
|
|
///
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Hopefully this is never implemented.
|
2016-09-18 18:17:44 +00:00
|
|
|
fn bell(&mut self) {}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Substitute char under cursor.
|
2016-09-18 18:17:44 +00:00
|
|
|
fn substitute(&mut self) {}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Newline.
|
2016-09-18 18:17:44 +00:00
|
|
|
fn newline(&mut self) {}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Set current position as a tabstop.
|
2016-09-18 18:17:44 +00:00
|
|
|
fn set_horizontal_tabstop(&mut self) {}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Scroll up `rows` rows.
|
2021-03-30 23:25:38 +00:00
|
|
|
fn scroll_up(&mut self, _: usize) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Scroll down `rows` rows.
|
2021-03-30 23:25:38 +00:00
|
|
|
fn scroll_down(&mut self, _: usize) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Insert `count` blank lines.
|
2021-03-30 23:25:38 +00:00
|
|
|
fn insert_blank_lines(&mut self, _: usize) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Delete `count` lines.
|
2021-03-30 23:25:38 +00:00
|
|
|
fn delete_lines(&mut self, _: usize) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Erase `count` chars in current line following cursor.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
///
|
2016-12-17 06:48:04 +00:00
|
|
|
/// Erase means resetting to the default state (default colors, no content,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// no mode flags).
|
2018-12-10 17:53:56 +00:00
|
|
|
fn erase_chars(&mut self, _: Column) {}
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Delete `count` chars.
|
2016-09-18 18:17:44 +00:00
|
|
|
///
|
2016-12-17 06:48:04 +00:00
|
|
|
/// Deleting a character is like the delete key on the keyboard - everything
|
|
|
|
/// to the right of the deleted things is shifted left.
|
2021-03-30 23:25:38 +00:00
|
|
|
fn delete_chars(&mut self, _: usize) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Move backward `count` tabs.
|
2020-11-26 00:57:44 +00:00
|
|
|
fn move_backward_tabs(&mut self, _count: u16) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Move forward `count` tabs.
|
2020-11-26 00:57:44 +00:00
|
|
|
fn move_forward_tabs(&mut self, _count: u16) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Save current cursor position.
|
2016-09-18 18:17:44 +00:00
|
|
|
fn save_cursor_position(&mut self) {}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Restore cursor position.
|
2016-09-18 18:17:44 +00:00
|
|
|
fn restore_cursor_position(&mut self) {}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Clear current line.
|
2016-09-18 18:17:44 +00:00
|
|
|
fn clear_line(&mut self, _mode: LineClearMode) {}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Clear screen.
|
2016-09-18 18:17:44 +00:00
|
|
|
fn clear_screen(&mut self, _mode: ClearMode) {}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Clear tab stops.
|
2016-09-18 18:17:44 +00:00
|
|
|
fn clear_tabs(&mut self, _mode: TabulationClearMode) {}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Reset terminal state.
|
2016-09-18 18:17:44 +00:00
|
|
|
fn reset_state(&mut self) {}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Reverse Index.
|
2016-09-18 18:17:44 +00:00
|
|
|
///
|
2016-12-17 06:48:04 +00:00
|
|
|
/// Move the active position to the same horizontal position on the
|
|
|
|
/// preceding line. If the active position is at the top margin, a scroll
|
2020-05-05 22:50:23 +00:00
|
|
|
/// down is performed.
|
2016-09-18 18:17:44 +00:00
|
|
|
fn reverse_index(&mut self) {}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Set a terminal attribute.
|
2016-09-18 18:17:44 +00:00
|
|
|
fn terminal_attribute(&mut self, _attr: Attr) {}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Set mode.
|
2016-09-18 18:17:44 +00:00
|
|
|
fn set_mode(&mut self, _mode: Mode) {}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Unset mode.
|
2018-12-10 17:53:56 +00:00
|
|
|
fn unset_mode(&mut self, _: Mode) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// DECSTBM - Set the terminal scrolling region.
|
2020-07-09 21:45:22 +00:00
|
|
|
fn set_scrolling_region(&mut self, _top: usize, _bottom: Option<usize>) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// DECKPAM - Set keypad to applications mode (ESCape instead of digits).
|
2016-09-18 18:17:44 +00:00
|
|
|
fn set_keypad_application_mode(&mut self) {}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// DECKPNM - Set keypad to numeric mode (digits instead of ESCape seq).
|
2016-09-18 18:17:44 +00:00
|
|
|
fn unset_keypad_application_mode(&mut self) {}
|
2017-01-09 20:07:23 +00:00
|
|
|
|
|
|
|
/// Set one of the graphic character sets, G0 to G3, as the active charset.
|
|
|
|
///
|
2017-10-30 15:03:58 +00:00
|
|
|
/// 'Invoke' one of G0 to G3 in the GL area. Also referred to as shift in,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// shift out and locking shift depending on the set being activated.
|
2018-12-10 17:53:56 +00:00
|
|
|
fn set_active_charset(&mut self, _: CharsetIndex) {}
|
2017-01-09 20:07:23 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Assign a graphic character set to G0, G1, G2 or G3.
|
2017-01-09 20:07:23 +00:00
|
|
|
///
|
|
|
|
/// 'Designate' a graphic character set as one of G0 to G3, so that it can
|
2020-05-05 22:50:23 +00:00
|
|
|
/// later be 'invoked' by `set_active_charset`.
|
2018-12-10 17:53:56 +00:00
|
|
|
fn configure_charset(&mut self, _: CharsetIndex, _: StandardCharset) {}
|
2017-02-06 21:28:33 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Set an indexed color value.
|
2018-12-10 17:53:56 +00:00
|
|
|
fn set_color(&mut self, _: usize, _: Rgb) {}
|
2017-04-18 17:42:29 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Write a foreground/background color escape sequence with the current color.
|
2021-01-24 21:45:36 +00:00
|
|
|
fn dynamic_color_sequence(&mut self, _: u8, _: usize, _: &str) {}
|
2019-06-02 13:16:38 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Reset an indexed color to original value.
|
2018-12-10 17:53:56 +00:00
|
|
|
fn reset_color(&mut self, _: usize) {}
|
2017-07-28 22:14:18 +00:00
|
|
|
|
2020-06-06 21:33:20 +00:00
|
|
|
/// Store data into clipboard.
|
|
|
|
fn clipboard_store(&mut self, _: u8, _: &[u8]) {}
|
2019-11-11 00:12:14 +00:00
|
|
|
|
2020-06-06 21:33:20 +00:00
|
|
|
/// Load data from clipboard.
|
|
|
|
fn clipboard_load(&mut self, _: u8, _: &str) {}
|
2018-01-02 16:32:50 +00:00
|
|
|
|
2019-11-17 00:04:16 +00:00
|
|
|
/// Run the decaln routine.
|
|
|
|
fn decaln(&mut self) {}
|
2019-10-14 17:50:58 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Push a title onto the stack.
|
2019-10-14 17:50:58 +00:00
|
|
|
fn push_title(&mut self) {}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Pop the last title from the stack.
|
2019-10-14 17:50:58 +00:00
|
|
|
fn pop_title(&mut self) {}
|
2020-08-28 22:26:03 +00:00
|
|
|
|
|
|
|
/// Report text area size in pixels.
|
2021-04-17 23:20:13 +00:00
|
|
|
fn text_area_size_pixels(&mut self) {}
|
2020-08-28 22:26:03 +00:00
|
|
|
|
|
|
|
/// Report text area size in characters.
|
2021-04-17 23:20:13 +00:00
|
|
|
fn text_area_size_chars(&mut self) {}
|
2016-05-31 03:44:37 +00:00
|
|
|
}
|
|
|
|
|
2020-11-23 23:11:03 +00:00
|
|
|
/// Terminal cursor configuration.
|
2020-12-31 05:52:45 +00:00
|
|
|
#[derive(ConfigDeserialize, Default, Debug, Eq, PartialEq, Copy, Clone, Hash)]
|
2020-11-23 23:11:03 +00:00
|
|
|
pub struct CursorStyle {
|
|
|
|
pub shape: CursorShape,
|
|
|
|
pub blinking: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Terminal cursor shape.
|
2020-12-31 05:52:45 +00:00
|
|
|
#[derive(ConfigDeserialize, Debug, Eq, PartialEq, Copy, Clone, Hash)]
|
2020-11-23 23:11:03 +00:00
|
|
|
pub enum CursorShape {
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Cursor is a block like `▒`.
|
2017-05-28 16:38:10 +00:00
|
|
|
Block,
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Cursor is an underscore like `_`.
|
2017-05-28 16:38:10 +00:00
|
|
|
Underline,
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Cursor is a vertical bar `⎸`.
|
2017-05-28 16:38:10 +00:00
|
|
|
Beam,
|
2018-01-06 01:42:55 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Cursor is a box like `☐`.
|
2020-12-31 05:52:45 +00:00
|
|
|
#[config(skip)]
|
2018-01-06 01:42:55 +00:00
|
|
|
HollowBlock,
|
2019-04-22 00:20:43 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Invisible cursor.
|
2020-12-31 05:52:45 +00:00
|
|
|
#[config(skip)]
|
2019-04-22 00:20:43 +00:00
|
|
|
Hidden,
|
2017-05-28 16:38:10 +00:00
|
|
|
}
|
|
|
|
|
2020-11-23 23:11:03 +00:00
|
|
|
impl Default for CursorShape {
|
|
|
|
fn default() -> CursorShape {
|
|
|
|
CursorShape::Block
|
2017-12-03 21:38:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Terminal modes.
|
2016-05-31 03:44:37 +00:00
|
|
|
#[derive(Debug, Eq, PartialEq)]
|
|
|
|
pub enum Mode {
|
2016-06-08 04:13:08 +00:00
|
|
|
/// ?1
|
|
|
|
CursorKeys = 1,
|
2021-02-13 18:15:57 +00:00
|
|
|
/// Select 80 or 132 columns per page (DECCOLM).
|
2017-04-19 16:03:33 +00:00
|
|
|
///
|
2020-05-05 22:50:23 +00:00
|
|
|
/// CSI ? 3 h -> set 132 column font.
|
|
|
|
/// CSI ? 3 l -> reset 80 column font.
|
2017-04-19 16:03:33 +00:00
|
|
|
///
|
|
|
|
/// Additionally,
|
|
|
|
///
|
|
|
|
/// * set margins to default positions
|
|
|
|
/// * erases all data in page memory
|
|
|
|
/// * resets DECLRMM to unavailable
|
|
|
|
/// * clears data from the status line (if set to host-writable)
|
2021-02-13 18:15:57 +00:00
|
|
|
ColumnMode = 3,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// IRM Insert Mode.
|
2017-05-01 05:10:38 +00:00
|
|
|
///
|
2020-05-05 22:50:23 +00:00
|
|
|
/// NB should be part of non-private mode enum.
|
2017-05-01 05:10:38 +00:00
|
|
|
///
|
|
|
|
/// * `CSI 4 h` change to insert mode
|
|
|
|
/// * `CSI 4 l` reset to replacement mode
|
|
|
|
Insert = 4,
|
2016-08-20 03:34:33 +00:00
|
|
|
/// ?6
|
|
|
|
Origin = 6,
|
2017-01-12 03:00:29 +00:00
|
|
|
/// ?7
|
|
|
|
LineWrap = 7,
|
2016-06-08 04:13:08 +00:00
|
|
|
/// ?12
|
|
|
|
BlinkingCursor = 12,
|
2017-04-18 17:41:11 +00:00
|
|
|
/// 20
|
|
|
|
///
|
|
|
|
/// NB This is actually a private mode. We should consider adding a second
|
|
|
|
/// enumeration for public/private modesets.
|
|
|
|
LineFeedNewLine = 20,
|
2016-08-20 03:34:33 +00:00
|
|
|
/// ?25
|
|
|
|
ShowCursor = 25,
|
2016-11-24 04:25:37 +00:00
|
|
|
/// ?1000
|
|
|
|
ReportMouseClicks = 1000,
|
2017-01-02 02:28:49 +00:00
|
|
|
/// ?1002
|
2017-12-24 20:15:42 +00:00
|
|
|
ReportCellMouseMotion = 1002,
|
|
|
|
/// ?1003
|
|
|
|
ReportAllMouseMotion = 1003,
|
2017-05-29 16:51:49 +00:00
|
|
|
/// ?1004
|
|
|
|
ReportFocusInOut = 1004,
|
2019-11-04 19:41:13 +00:00
|
|
|
/// ?1005
|
|
|
|
Utf8Mouse = 1005,
|
2017-01-02 02:28:49 +00:00
|
|
|
/// ?1006
|
|
|
|
SgrMouse = 1006,
|
2019-10-15 19:13:58 +00:00
|
|
|
/// ?1007
|
|
|
|
AlternateScroll = 1007,
|
2020-10-10 21:24:40 +00:00
|
|
|
/// ?1042
|
|
|
|
UrgencyHints = 1042,
|
2016-06-08 04:13:08 +00:00
|
|
|
/// ?1049
|
2016-05-31 03:44:37 +00:00
|
|
|
SwapScreenAndSetRestoreCursor = 1049,
|
2016-11-28 22:39:37 +00:00
|
|
|
/// ?2004
|
|
|
|
BracketedPaste = 2004,
|
2016-05-31 03:44:37 +00:00
|
|
|
}
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
|
2016-05-31 03:44:37 +00:00
|
|
|
impl Mode {
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Create mode from a primitive.
|
2020-11-26 00:57:44 +00:00
|
|
|
pub fn from_primitive(intermediate: Option<&u8>, num: u16) -> Option<Mode> {
|
2019-10-14 17:50:58 +00:00
|
|
|
let private = match intermediate {
|
|
|
|
Some(b'?') => true,
|
|
|
|
None => false,
|
|
|
|
_ => return None,
|
|
|
|
};
|
|
|
|
|
2016-06-08 04:13:08 +00:00
|
|
|
if private {
|
|
|
|
Some(match num {
|
|
|
|
1 => Mode::CursorKeys,
|
2021-02-13 18:15:57 +00:00
|
|
|
3 => Mode::ColumnMode,
|
2016-08-20 03:34:33 +00:00
|
|
|
6 => Mode::Origin,
|
2017-01-12 03:00:29 +00:00
|
|
|
7 => Mode::LineWrap,
|
2016-06-08 04:13:08 +00:00
|
|
|
12 => Mode::BlinkingCursor,
|
2016-06-23 16:42:00 +00:00
|
|
|
25 => Mode::ShowCursor,
|
2016-11-24 04:25:37 +00:00
|
|
|
1000 => Mode::ReportMouseClicks,
|
2017-12-24 20:15:42 +00:00
|
|
|
1002 => Mode::ReportCellMouseMotion,
|
|
|
|
1003 => Mode::ReportAllMouseMotion,
|
2017-05-29 16:51:49 +00:00
|
|
|
1004 => Mode::ReportFocusInOut,
|
2019-11-04 19:41:13 +00:00
|
|
|
1005 => Mode::Utf8Mouse,
|
2017-01-02 02:28:49 +00:00
|
|
|
1006 => Mode::SgrMouse,
|
2019-10-15 19:13:58 +00:00
|
|
|
1007 => Mode::AlternateScroll,
|
2020-10-10 21:24:40 +00:00
|
|
|
1042 => Mode::UrgencyHints,
|
2016-06-08 04:13:08 +00:00
|
|
|
1049 => Mode::SwapScreenAndSetRestoreCursor,
|
2016-11-28 22:39:37 +00:00
|
|
|
2004 => Mode::BracketedPaste,
|
2017-12-24 20:15:42 +00:00
|
|
|
_ => {
|
2019-01-07 00:06:57 +00:00
|
|
|
trace!("[unimplemented] primitive mode: {}", num);
|
2019-03-30 16:48:36 +00:00
|
|
|
return None;
|
|
|
|
},
|
2016-06-08 04:13:08 +00:00
|
|
|
})
|
|
|
|
} else {
|
2017-04-18 17:41:11 +00:00
|
|
|
Some(match num {
|
2017-05-01 05:10:38 +00:00
|
|
|
4 => Mode::Insert,
|
2017-04-18 17:41:11 +00:00
|
|
|
20 => Mode::LineFeedNewLine,
|
2019-03-30 16:48:36 +00:00
|
|
|
_ => return None,
|
2017-04-18 17:41:11 +00:00
|
|
|
})
|
2016-06-08 04:13:08 +00:00
|
|
|
}
|
2016-05-31 03:44:37 +00:00
|
|
|
}
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Mode for clearing line.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
///
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Relative to cursor.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum LineClearMode {
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Clear right of cursor.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
Right,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Clear left of cursor.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
Left,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Clear entire line.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
All,
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Mode for clearing terminal.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
///
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Relative to cursor.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum ClearMode {
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Clear below cursor.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
Below,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Clear above cursor.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
Above,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Clear entire terminal.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
All,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Clear 'saved' lines (scrollback).
|
2019-03-30 16:48:36 +00:00
|
|
|
Saved,
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Mode for clearing tab stops.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum TabulationClearMode {
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Clear stop under cursor.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
Current,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Clear all stops.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
All,
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Standard colors.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
///
|
|
|
|
/// The order here matters since the enum should be castable to a `usize` for
|
|
|
|
/// indexing a color list.
|
2020-12-31 05:52:45 +00:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord)]
|
2016-12-04 19:14:27 +00:00
|
|
|
pub enum NamedColor {
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Black.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
Black = 0,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Red.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
Red,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Green.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
Green,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Yellow.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
Yellow,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Blue.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
Blue,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Magenta.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
Magenta,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Cyan.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
Cyan,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// White.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
White,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Bright black.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
BrightBlack,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Bright red.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
BrightRed,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Bright green.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
BrightGreen,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Bright yellow.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
BrightYellow,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Bright blue.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
BrightBlue,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Bright magenta.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
BrightMagenta,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Bright cyan.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
BrightCyan,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Bright white.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
BrightWhite,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// The foreground color.
|
2016-12-04 19:14:27 +00:00
|
|
|
Foreground = 256,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// The background color.
|
2016-10-23 22:37:06 +00:00
|
|
|
Background,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Color for the cursor itself.
|
2017-02-24 16:23:07 +00:00
|
|
|
Cursor,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Dim black.
|
2017-06-23 17:01:53 +00:00
|
|
|
DimBlack,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Dim red.
|
2017-06-23 17:01:53 +00:00
|
|
|
DimRed,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Dim green.
|
2017-06-23 17:01:53 +00:00
|
|
|
DimGreen,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Dim yellow.
|
2017-06-23 17:01:53 +00:00
|
|
|
DimYellow,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Dim blue.
|
2017-06-23 17:01:53 +00:00
|
|
|
DimBlue,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Dim magenta.
|
2017-06-23 17:01:53 +00:00
|
|
|
DimMagenta,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Dim cyan.
|
2017-06-23 17:01:53 +00:00
|
|
|
DimCyan,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Dim white.
|
2017-06-23 17:01:53 +00:00
|
|
|
DimWhite,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// The bright foreground color.
|
2018-07-15 19:47:07 +00:00
|
|
|
BrightForeground,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Dim foreground.
|
2018-07-23 16:48:27 +00:00
|
|
|
DimForeground,
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
}
|
|
|
|
|
2016-12-04 21:13:44 +00:00
|
|
|
impl NamedColor {
|
2018-07-01 16:31:46 +00:00
|
|
|
pub fn to_bright(self) -> Self {
|
|
|
|
match self {
|
2018-07-15 19:47:07 +00:00
|
|
|
NamedColor::Foreground => NamedColor::BrightForeground,
|
2016-12-04 21:13:44 +00:00
|
|
|
NamedColor::Black => NamedColor::BrightBlack,
|
|
|
|
NamedColor::Red => NamedColor::BrightRed,
|
|
|
|
NamedColor::Green => NamedColor::BrightGreen,
|
|
|
|
NamedColor::Yellow => NamedColor::BrightYellow,
|
|
|
|
NamedColor::Blue => NamedColor::BrightBlue,
|
|
|
|
NamedColor::Magenta => NamedColor::BrightMagenta,
|
|
|
|
NamedColor::Cyan => NamedColor::BrightCyan,
|
|
|
|
NamedColor::White => NamedColor::BrightWhite,
|
2018-07-23 16:48:27 +00:00
|
|
|
NamedColor::DimForeground => NamedColor::Foreground,
|
2017-06-23 17:01:53 +00:00
|
|
|
NamedColor::DimBlack => NamedColor::Black,
|
|
|
|
NamedColor::DimRed => NamedColor::Red,
|
|
|
|
NamedColor::DimGreen => NamedColor::Green,
|
|
|
|
NamedColor::DimYellow => NamedColor::Yellow,
|
|
|
|
NamedColor::DimBlue => NamedColor::Blue,
|
|
|
|
NamedColor::DimMagenta => NamedColor::Magenta,
|
|
|
|
NamedColor::DimCyan => NamedColor::Cyan,
|
|
|
|
NamedColor::DimWhite => NamedColor::White,
|
2019-03-30 16:48:36 +00:00
|
|
|
val => val,
|
2017-06-23 17:01:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-01 16:31:46 +00:00
|
|
|
pub fn to_dim(self) -> Self {
|
|
|
|
match self {
|
2017-06-23 17:01:53 +00:00
|
|
|
NamedColor::Black => NamedColor::DimBlack,
|
|
|
|
NamedColor::Red => NamedColor::DimRed,
|
|
|
|
NamedColor::Green => NamedColor::DimGreen,
|
|
|
|
NamedColor::Yellow => NamedColor::DimYellow,
|
|
|
|
NamedColor::Blue => NamedColor::DimBlue,
|
|
|
|
NamedColor::Magenta => NamedColor::DimMagenta,
|
|
|
|
NamedColor::Cyan => NamedColor::DimCyan,
|
|
|
|
NamedColor::White => NamedColor::DimWhite,
|
2018-07-23 16:48:27 +00:00
|
|
|
NamedColor::Foreground => NamedColor::DimForeground,
|
2017-06-23 17:01:53 +00:00
|
|
|
NamedColor::BrightBlack => NamedColor::Black,
|
|
|
|
NamedColor::BrightRed => NamedColor::Red,
|
|
|
|
NamedColor::BrightGreen => NamedColor::Green,
|
|
|
|
NamedColor::BrightYellow => NamedColor::Yellow,
|
|
|
|
NamedColor::BrightBlue => NamedColor::Blue,
|
|
|
|
NamedColor::BrightMagenta => NamedColor::Magenta,
|
|
|
|
NamedColor::BrightCyan => NamedColor::Cyan,
|
|
|
|
NamedColor::BrightWhite => NamedColor::White,
|
2018-07-23 16:48:27 +00:00
|
|
|
NamedColor::BrightForeground => NamedColor::Foreground,
|
2019-03-30 16:48:36 +00:00
|
|
|
val => val,
|
2016-12-04 21:13:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-31 05:52:45 +00:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
|
2016-12-04 19:14:27 +00:00
|
|
|
pub enum Color {
|
|
|
|
Named(NamedColor),
|
|
|
|
Spec(Rgb),
|
|
|
|
Indexed(u8),
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Terminal character attributes.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
#[derive(Debug, Eq, PartialEq)]
|
|
|
|
pub enum Attr {
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Clear all special abilities.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
Reset,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Bold text.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
Bold,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Dim or secondary color.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
Dim,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Italic text.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
Italic,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Underline text.
|
2019-11-03 20:59:28 +00:00
|
|
|
Underline,
|
2020-08-12 16:05:22 +00:00
|
|
|
/// Underlined twice.
|
|
|
|
DoubleUnderline,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Blink cursor slowly.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
BlinkSlow,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Blink cursor fast.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
BlinkFast,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Invert colors.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
Reverse,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Do not display characters.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
Hidden,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Strikeout text.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
Strike,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Cancel bold.
|
2017-07-20 17:54:40 +00:00
|
|
|
CancelBold,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Cancel bold and dim.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
CancelBoldDim,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Cancel italic.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
CancelItalic,
|
2020-08-12 16:05:22 +00:00
|
|
|
/// Cancel all underlines.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
CancelUnderline,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Cancel blink.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
CancelBlink,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Cancel inversion.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
CancelReverse,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Cancel text hiding.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
CancelHidden,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Cancel strikeout.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
CancelStrike,
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Set indexed foreground color.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
Foreground(Color),
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Set indexed background color.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
Background(Color),
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Identifiers which can be assigned to a graphic character set.
|
2017-01-09 20:07:23 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
|
|
pub enum CharsetIndex {
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Default set, is designated as ASCII at startup.
|
2017-01-09 20:07:23 +00:00
|
|
|
G0,
|
|
|
|
G1,
|
|
|
|
G2,
|
|
|
|
G3,
|
|
|
|
}
|
|
|
|
|
2017-02-01 17:55:23 +00:00
|
|
|
impl Default for CharsetIndex {
|
|
|
|
fn default() -> Self {
|
|
|
|
CharsetIndex::G0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Standard or common character sets which can be designated as G0-G3.
|
2017-01-09 20:07:23 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
|
|
pub enum StandardCharset {
|
|
|
|
Ascii,
|
|
|
|
SpecialCharacterAndLineDrawing,
|
|
|
|
}
|
|
|
|
|
2017-02-01 17:55:23 +00:00
|
|
|
impl Default for StandardCharset {
|
|
|
|
fn default() -> Self {
|
|
|
|
StandardCharset::Ascii
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 20:45:44 +00:00
|
|
|
impl StandardCharset {
|
|
|
|
/// Switch/Map character to the active charset. Ascii is the common case and
|
|
|
|
/// for that we want to do as little as possible.
|
|
|
|
#[inline]
|
|
|
|
pub fn map(self, c: char) -> char {
|
|
|
|
match self {
|
|
|
|
StandardCharset::Ascii => c,
|
|
|
|
StandardCharset::SpecialCharacterAndLineDrawing => match c {
|
|
|
|
'`' => '◆',
|
|
|
|
'a' => '▒',
|
|
|
|
'b' => '\t',
|
|
|
|
'c' => '\u{000c}',
|
|
|
|
'd' => '\r',
|
|
|
|
'e' => '\n',
|
|
|
|
'f' => '°',
|
|
|
|
'g' => '±',
|
|
|
|
'h' => '\u{2424}',
|
|
|
|
'i' => '\u{000b}',
|
|
|
|
'j' => '┘',
|
|
|
|
'k' => '┐',
|
|
|
|
'l' => '┌',
|
|
|
|
'm' => '└',
|
|
|
|
'n' => '┼',
|
|
|
|
'o' => '⎺',
|
|
|
|
'p' => '⎻',
|
|
|
|
'q' => '─',
|
|
|
|
'r' => '⎼',
|
|
|
|
's' => '⎽',
|
|
|
|
't' => '├',
|
|
|
|
'u' => '┤',
|
|
|
|
'v' => '┴',
|
|
|
|
'w' => '┬',
|
|
|
|
'x' => '│',
|
|
|
|
'y' => '≤',
|
|
|
|
'z' => '≥',
|
|
|
|
'{' => 'π',
|
|
|
|
'|' => '≠',
|
|
|
|
'}' => '£',
|
|
|
|
'~' => '·',
|
|
|
|
_ => c,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-17 23:20:13 +00:00
|
|
|
impl<'a, H> vte::Perform for Performer<'a, H>
|
2019-03-30 16:48:36 +00:00
|
|
|
where
|
2020-07-09 21:45:22 +00:00
|
|
|
H: Handler + 'a,
|
2016-12-04 23:48:30 +00:00
|
|
|
{
|
2016-09-18 18:17:44 +00:00
|
|
|
#[inline]
|
|
|
|
fn print(&mut self, c: char) {
|
|
|
|
self.handler.input(c);
|
2019-10-05 00:29:26 +00:00
|
|
|
self.state.preceding_char = Some(c);
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
}
|
|
|
|
|
2016-09-18 18:17:44 +00:00
|
|
|
#[inline]
|
|
|
|
fn execute(&mut self, byte: u8) {
|
|
|
|
match byte {
|
|
|
|
C0::HT => self.handler.put_tab(1),
|
|
|
|
C0::BS => self.handler.backspace(),
|
|
|
|
C0::CR => self.handler.carriage_return(),
|
|
|
|
C0::LF | C0::VT | C0::FF => self.handler.linefeed(),
|
|
|
|
C0::BEL => self.handler.bell(),
|
|
|
|
C0::SUB => self.handler.substitute(),
|
2017-01-09 20:07:23 +00:00
|
|
|
C0::SI => self.handler.set_active_charset(CharsetIndex::G0),
|
|
|
|
C0::SO => self.handler.set_active_charset(CharsetIndex::G1),
|
2019-03-30 16:48:36 +00:00
|
|
|
_ => debug!("[unhandled] execute byte={:02x}", byte),
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-18 18:17:44 +00:00
|
|
|
#[inline]
|
2021-01-24 21:45:36 +00:00
|
|
|
fn hook(&mut self, params: &Params, intermediates: &[u8], ignore: bool, action: char) {
|
2021-01-25 21:23:08 +00:00
|
|
|
match (action, intermediates) {
|
|
|
|
('s', [b'=']) => {
|
|
|
|
// Start a synchronized update. The end is handled with a separate parser.
|
|
|
|
if params.iter().next().map_or(false, |param| param[0] == 1) {
|
|
|
|
self.state.dcs = Some(Dcs::SyncStart);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_ => debug!(
|
|
|
|
"[unhandled hook] params={:?}, ints: {:?}, ignore: {:?}, action: {:?}",
|
|
|
|
params, intermediates, ignore, action
|
|
|
|
),
|
|
|
|
}
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
}
|
|
|
|
|
2016-09-18 18:17:44 +00:00
|
|
|
#[inline]
|
|
|
|
fn put(&mut self, byte: u8) {
|
2017-01-13 07:15:06 +00:00
|
|
|
debug!("[unhandled put] byte={:?}", byte);
|
2016-06-07 00:41:03 +00:00
|
|
|
}
|
|
|
|
|
2016-09-18 18:17:44 +00:00
|
|
|
#[inline]
|
2017-01-11 05:21:19 +00:00
|
|
|
fn unhook(&mut self) {
|
2021-01-25 21:23:08 +00:00
|
|
|
match self.state.dcs {
|
|
|
|
Some(Dcs::SyncStart) => {
|
|
|
|
self.state.sync_state.timeout = Some(Instant::now() + SYNC_UPDATE_TIMEOUT);
|
|
|
|
},
|
|
|
|
Some(Dcs::SyncEnd) => (),
|
|
|
|
_ => debug!("[unhandled unhook]"),
|
|
|
|
}
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
}
|
|
|
|
|
2016-09-18 18:17:44 +00:00
|
|
|
#[inline]
|
2020-01-31 00:00:23 +00:00
|
|
|
fn osc_dispatch(&mut self, params: &[&[u8]], bell_terminated: bool) {
|
|
|
|
let terminator = if bell_terminated { "\x07" } else { "\x1b\\" };
|
2019-06-02 13:16:38 +00:00
|
|
|
|
2018-01-06 01:42:55 +00:00
|
|
|
fn unhandled(params: &[&[u8]]) {
|
|
|
|
let mut buf = String::new();
|
|
|
|
for items in params {
|
2020-09-27 22:36:08 +00:00
|
|
|
buf.push('[');
|
2018-01-06 01:42:55 +00:00
|
|
|
for item in *items {
|
|
|
|
buf.push_str(&format!("{:?},", *item as char));
|
2017-01-11 05:21:19 +00:00
|
|
|
}
|
2018-01-06 01:42:55 +00:00
|
|
|
buf.push_str("],");
|
|
|
|
}
|
2018-11-18 13:48:10 +00:00
|
|
|
debug!("[unhandled osc_dispatch]: [{}] at line {}", &buf, line!());
|
2017-01-11 05:21:19 +00:00
|
|
|
}
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
|
2017-02-06 21:28:33 +00:00
|
|
|
if params.is_empty() || params[0].is_empty() {
|
2017-01-11 05:21:19 +00:00
|
|
|
return;
|
|
|
|
}
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
|
2017-07-28 22:14:18 +00:00
|
|
|
match params[0] {
|
2020-05-05 22:50:23 +00:00
|
|
|
// Set window title.
|
2017-07-28 22:14:18 +00:00
|
|
|
b"0" | b"2" => {
|
2018-01-06 01:42:55 +00:00
|
|
|
if params.len() >= 2 {
|
2019-09-28 16:59:27 +00:00
|
|
|
let title = params[1..]
|
|
|
|
.iter()
|
|
|
|
.flat_map(|x| str::from_utf8(x))
|
|
|
|
.collect::<Vec<&str>>()
|
2020-03-14 15:09:10 +00:00
|
|
|
.join(";")
|
|
|
|
.trim()
|
|
|
|
.to_owned();
|
|
|
|
self.handler.set_title(Some(title));
|
2019-09-28 16:59:27 +00:00
|
|
|
return;
|
2017-01-11 05:21:19 +00:00
|
|
|
}
|
2018-01-06 01:42:55 +00:00
|
|
|
unhandled(params);
|
2017-01-11 05:21:19 +00:00
|
|
|
},
|
2017-02-06 21:28:33 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Set color index.
|
2017-07-28 22:14:18 +00:00
|
|
|
b"4" => {
|
2018-01-06 01:42:55 +00:00
|
|
|
if params.len() > 1 && params.len() % 2 != 0 {
|
|
|
|
for chunk in params[1..].chunks(2) {
|
|
|
|
let index = parse_number(chunk[0]);
|
2019-08-19 19:56:27 +00:00
|
|
|
let color = xparse_color(chunk[1]);
|
2018-01-06 01:42:55 +00:00
|
|
|
if let (Some(i), Some(c)) = (index, color) {
|
|
|
|
self.handler.set_color(i as usize, c);
|
|
|
|
return;
|
2017-02-06 21:28:33 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-28 22:14:18 +00:00
|
|
|
}
|
2018-01-06 01:42:55 +00:00
|
|
|
unhandled(params);
|
2019-03-30 16:48:36 +00:00
|
|
|
},
|
2017-02-06 21:28:33 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Get/set Foreground, Background, Cursor colors.
|
2019-06-09 18:02:15 +00:00
|
|
|
b"10" | b"11" | b"12" => {
|
2018-01-06 01:42:55 +00:00
|
|
|
if params.len() >= 2 {
|
2019-06-09 18:02:15 +00:00
|
|
|
if let Some(mut dynamic_code) = parse_number(params[0]) {
|
|
|
|
for param in ¶ms[1..] {
|
2020-05-05 22:50:23 +00:00
|
|
|
// 10 is the first dynamic color, also the foreground.
|
2019-06-09 18:02:15 +00:00
|
|
|
let offset = dynamic_code as usize - 10;
|
|
|
|
let index = NamedColor::Foreground as usize + offset;
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// End of setting dynamic colors.
|
2019-06-09 18:02:15 +00:00
|
|
|
if index > NamedColor::Cursor as usize {
|
|
|
|
unhandled(params);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-08-19 19:56:27 +00:00
|
|
|
if let Some(color) = xparse_color(param) {
|
2019-06-09 18:02:15 +00:00
|
|
|
self.handler.set_color(index, color);
|
|
|
|
} else if param == b"?" {
|
2020-01-31 00:00:23 +00:00
|
|
|
self.handler.dynamic_color_sequence(
|
|
|
|
dynamic_code,
|
|
|
|
index,
|
|
|
|
terminator,
|
|
|
|
);
|
2019-06-09 18:02:15 +00:00
|
|
|
} else {
|
|
|
|
unhandled(params);
|
|
|
|
}
|
|
|
|
dynamic_code += 1;
|
|
|
|
}
|
2018-01-06 01:42:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-11-12 03:11:21 +00:00
|
|
|
}
|
2018-01-06 01:42:55 +00:00
|
|
|
unhandled(params);
|
2019-03-30 16:48:36 +00:00
|
|
|
},
|
2017-11-12 03:11:21 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Set cursor style.
|
2018-07-15 16:02:44 +00:00
|
|
|
b"50" => {
|
2019-03-30 16:48:36 +00:00
|
|
|
if params.len() >= 2
|
|
|
|
&& params[1].len() >= 13
|
|
|
|
&& params[1][0..12] == *b"CursorShape="
|
|
|
|
{
|
2020-11-23 23:11:03 +00:00
|
|
|
let shape = match params[1][12] as char {
|
|
|
|
'0' => CursorShape::Block,
|
|
|
|
'1' => CursorShape::Beam,
|
|
|
|
'2' => CursorShape::Underline,
|
2018-07-15 16:02:44 +00:00
|
|
|
_ => return unhandled(params),
|
|
|
|
};
|
2020-11-23 23:11:03 +00:00
|
|
|
self.handler.set_cursor_shape(shape);
|
2018-07-15 16:02:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
unhandled(params);
|
2019-03-30 16:48:36 +00:00
|
|
|
},
|
2018-07-15 16:02:44 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Set clipboard.
|
2018-01-02 16:32:50 +00:00
|
|
|
b"52" => {
|
2019-11-28 07:08:04 +00:00
|
|
|
if params.len() < 3 {
|
2018-01-06 01:42:55 +00:00
|
|
|
return unhandled(params);
|
2018-01-02 16:32:50 +00:00
|
|
|
}
|
|
|
|
|
2019-11-28 07:08:04 +00:00
|
|
|
let clipboard = params[1].get(0).unwrap_or(&b'c');
|
2018-01-02 16:32:50 +00:00
|
|
|
match params[2] {
|
2020-06-06 21:33:20 +00:00
|
|
|
b"?" => self.handler.clipboard_load(*clipboard, terminator),
|
|
|
|
base64 => self.handler.clipboard_store(*clipboard, base64),
|
2018-01-02 16:32:50 +00:00
|
|
|
}
|
2019-03-30 16:48:36 +00:00
|
|
|
},
|
2018-01-02 16:32:50 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Reset color index.
|
2017-11-12 03:11:21 +00:00
|
|
|
b"104" => {
|
2020-05-05 22:50:23 +00:00
|
|
|
// Reset all color indexes when no parameters are given.
|
2017-11-12 03:11:21 +00:00
|
|
|
if params.len() == 1 {
|
|
|
|
for i in 0..256 {
|
|
|
|
self.handler.reset_color(i);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Reset color indexes given as parameters.
|
2017-11-12 03:11:21 +00:00
|
|
|
for param in ¶ms[1..] {
|
|
|
|
match parse_number(param) {
|
|
|
|
Some(index) => self.handler.reset_color(index as usize),
|
2018-01-06 01:42:55 +00:00
|
|
|
None => unhandled(params),
|
2017-11-12 03:11:21 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-30 16:48:36 +00:00
|
|
|
},
|
2017-11-12 03:11:21 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Reset foreground color.
|
2018-01-06 01:42:55 +00:00
|
|
|
b"110" => self.handler.reset_color(NamedColor::Foreground as usize),
|
2017-07-28 22:14:18 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Reset background color.
|
2018-01-06 01:42:55 +00:00
|
|
|
b"111" => self.handler.reset_color(NamedColor::Background as usize),
|
2017-07-28 22:14:18 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Reset text cursor color.
|
2018-01-06 01:42:55 +00:00
|
|
|
b"112" => self.handler.reset_color(NamedColor::Cursor as usize),
|
2017-11-12 03:11:21 +00:00
|
|
|
|
2018-01-06 01:42:55 +00:00
|
|
|
_ => unhandled(params),
|
2017-01-11 05:21:19 +00:00
|
|
|
}
|
2016-09-18 18:17:44 +00:00
|
|
|
}
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
|
2020-02-15 20:00:53 +00:00
|
|
|
#[allow(clippy::cognitive_complexity)]
|
2016-09-18 18:17:44 +00:00
|
|
|
#[inline]
|
2019-08-08 21:30:10 +00:00
|
|
|
fn csi_dispatch(
|
|
|
|
&mut self,
|
2020-08-07 22:37:23 +00:00
|
|
|
params: &Params,
|
2019-08-08 21:30:10 +00:00
|
|
|
intermediates: &[u8],
|
|
|
|
has_ignored_intermediates: bool,
|
|
|
|
action: char,
|
|
|
|
) {
|
2016-05-31 03:44:37 +00:00
|
|
|
macro_rules! unhandled {
|
|
|
|
() => {{
|
2019-03-30 16:48:36 +00:00
|
|
|
debug!(
|
2020-08-07 22:37:23 +00:00
|
|
|
"[Unhandled CSI] action={:?}, params={:?}, intermediates={:?}",
|
|
|
|
action, params, intermediates
|
2019-03-30 16:48:36 +00:00
|
|
|
);
|
|
|
|
}};
|
2016-05-31 03:44:37 +00:00
|
|
|
}
|
|
|
|
|
2019-08-06 22:59:16 +00:00
|
|
|
if has_ignored_intermediates || intermediates.len() > 1 {
|
|
|
|
unhandled!();
|
2019-08-15 23:13:10 +00:00
|
|
|
return;
|
2019-08-06 22:59:16 +00:00
|
|
|
}
|
|
|
|
|
2020-08-07 22:37:23 +00:00
|
|
|
let mut params_iter = params.iter();
|
2019-08-06 22:59:16 +00:00
|
|
|
let handler = &mut self.handler;
|
|
|
|
|
2020-11-26 00:57:44 +00:00
|
|
|
let mut next_param_or = |default: u16| {
|
2020-08-07 22:37:23 +00:00
|
|
|
params_iter.next().map(|param| param[0]).filter(|¶m| param != 0).unwrap_or(default)
|
|
|
|
};
|
|
|
|
|
2021-01-24 23:42:54 +00:00
|
|
|
match (action, intermediates) {
|
2021-03-30 23:25:38 +00:00
|
|
|
('@', []) => handler.insert_blank(next_param_or(1) as usize),
|
|
|
|
('A', []) => handler.move_up(next_param_or(1) as usize),
|
|
|
|
('B', []) | ('e', []) => handler.move_down(next_param_or(1) as usize),
|
2021-01-24 23:42:54 +00:00
|
|
|
('b', []) => {
|
2019-10-05 00:29:26 +00:00
|
|
|
if let Some(c) = self.state.preceding_char {
|
2020-08-07 22:37:23 +00:00
|
|
|
for _ in 0..next_param_or(1) {
|
2017-09-29 12:05:19 +00:00
|
|
|
handler.input(c);
|
|
|
|
}
|
2019-03-30 16:48:36 +00:00
|
|
|
} else {
|
2018-11-18 13:48:10 +00:00
|
|
|
debug!("tried to repeat with no preceding char");
|
2017-09-29 12:05:19 +00:00
|
|
|
}
|
|
|
|
},
|
2021-01-24 23:42:54 +00:00
|
|
|
('C', []) | ('a', []) => handler.move_forward(Column(next_param_or(1) as usize)),
|
|
|
|
('c', intermediates) if next_param_or(0) == 0 => {
|
2021-04-17 23:20:13 +00:00
|
|
|
handler.identify_terminal(intermediates.get(0).map(|&i| i as char))
|
2019-11-17 02:10:11 +00:00
|
|
|
},
|
2021-01-24 23:42:54 +00:00
|
|
|
('D', []) => handler.move_backward(Column(next_param_or(1) as usize)),
|
2021-03-30 23:25:38 +00:00
|
|
|
('d', []) => handler.goto_line(Line(next_param_or(1) as i32 - 1)),
|
|
|
|
('E', []) => handler.move_down_and_cr(next_param_or(1) as usize),
|
|
|
|
('F', []) => handler.move_up_and_cr(next_param_or(1) as usize),
|
2021-01-24 23:42:54 +00:00
|
|
|
('G', []) | ('`', []) => handler.goto_col(Column(next_param_or(1) as usize - 1)),
|
|
|
|
('g', []) => {
|
2020-08-07 22:37:23 +00:00
|
|
|
let mode = match next_param_or(0) {
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
0 => TabulationClearMode::Current,
|
|
|
|
3 => TabulationClearMode::All,
|
2019-08-15 23:13:10 +00:00
|
|
|
_ => {
|
|
|
|
unhandled!();
|
|
|
|
return;
|
|
|
|
},
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
};
|
|
|
|
|
2016-05-31 03:44:37 +00:00
|
|
|
handler.clear_tabs(mode);
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
},
|
2021-01-24 23:42:54 +00:00
|
|
|
('H', []) | ('f', []) => {
|
2021-03-30 23:25:38 +00:00
|
|
|
let y = next_param_or(1) as i32;
|
2020-08-07 22:37:23 +00:00
|
|
|
let x = next_param_or(1) as usize;
|
2016-07-04 15:28:14 +00:00
|
|
|
handler.goto(Line(y - 1), Column(x - 1));
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
},
|
2021-01-24 23:42:54 +00:00
|
|
|
('h', intermediates) => {
|
2020-08-07 22:37:23 +00:00
|
|
|
for param in params_iter.map(|param| param[0]) {
|
2021-01-24 23:42:54 +00:00
|
|
|
match Mode::from_primitive(intermediates.get(0), param) {
|
2020-07-03 20:27:18 +00:00
|
|
|
Some(mode) => handler.set_mode(mode),
|
|
|
|
None => unhandled!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-01-24 23:42:54 +00:00
|
|
|
('I', []) => handler.move_forward_tabs(next_param_or(1)),
|
|
|
|
('J', []) => {
|
2020-08-07 22:37:23 +00:00
|
|
|
let mode = match next_param_or(0) {
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
0 => ClearMode::Below,
|
|
|
|
1 => ClearMode::Above,
|
|
|
|
2 => ClearMode::All,
|
2017-03-04 04:22:54 +00:00
|
|
|
3 => ClearMode::Saved,
|
2019-08-15 23:13:10 +00:00
|
|
|
_ => {
|
|
|
|
unhandled!();
|
|
|
|
return;
|
|
|
|
},
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
};
|
|
|
|
|
2016-05-31 03:44:37 +00:00
|
|
|
handler.clear_screen(mode);
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
},
|
2021-01-24 23:42:54 +00:00
|
|
|
('K', []) => {
|
2020-08-07 22:37:23 +00:00
|
|
|
let mode = match next_param_or(0) {
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
0 => LineClearMode::Right,
|
|
|
|
1 => LineClearMode::Left,
|
|
|
|
2 => LineClearMode::All,
|
2019-08-15 23:13:10 +00:00
|
|
|
_ => {
|
|
|
|
unhandled!();
|
|
|
|
return;
|
|
|
|
},
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
};
|
|
|
|
|
2016-05-31 03:44:37 +00:00
|
|
|
handler.clear_line(mode);
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
},
|
2021-03-30 23:25:38 +00:00
|
|
|
('L', []) => handler.insert_blank_lines(next_param_or(1) as usize),
|
2021-01-24 23:42:54 +00:00
|
|
|
('l', intermediates) => {
|
2020-08-07 22:37:23 +00:00
|
|
|
for param in params_iter.map(|param| param[0]) {
|
2021-01-24 23:42:54 +00:00
|
|
|
match Mode::from_primitive(intermediates.get(0), param) {
|
2018-03-08 21:50:04 +00:00
|
|
|
Some(mode) => handler.unset_mode(mode),
|
2020-02-15 20:00:53 +00:00
|
|
|
None => unhandled!(),
|
2018-03-08 21:50:04 +00:00
|
|
|
}
|
2016-05-31 03:44:37 +00:00
|
|
|
}
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
},
|
2021-03-30 23:25:38 +00:00
|
|
|
('M', []) => handler.delete_lines(next_param_or(1) as usize),
|
2021-01-24 23:42:54 +00:00
|
|
|
('m', []) => {
|
2020-08-07 22:37:23 +00:00
|
|
|
if params.is_empty() {
|
2016-09-18 18:17:44 +00:00
|
|
|
handler.terminal_attribute(Attr::Reset);
|
2019-08-06 22:59:16 +00:00
|
|
|
} else {
|
2020-08-07 22:37:23 +00:00
|
|
|
for attr in attrs_from_sgr_parameters(&mut params_iter) {
|
2019-08-06 22:59:16 +00:00
|
|
|
match attr {
|
|
|
|
Some(attr) => handler.terminal_attribute(attr),
|
2020-02-15 20:00:53 +00:00
|
|
|
None => unhandled!(),
|
2019-08-06 22:59:16 +00:00
|
|
|
}
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-30 16:48:36 +00:00
|
|
|
},
|
2021-04-17 23:20:13 +00:00
|
|
|
('n', []) => handler.device_status(next_param_or(0) as usize),
|
2021-03-30 23:25:38 +00:00
|
|
|
('P', []) => handler.delete_chars(next_param_or(1) as usize),
|
2021-01-24 23:42:54 +00:00
|
|
|
('q', [b' ']) => {
|
2020-05-05 22:50:23 +00:00
|
|
|
// DECSCUSR (CSI Ps SP q) -- Set Cursor Style.
|
2020-11-23 23:11:03 +00:00
|
|
|
let cursor_style_id = next_param_or(0);
|
|
|
|
let shape = match cursor_style_id {
|
2019-08-06 22:59:16 +00:00
|
|
|
0 => None,
|
2020-11-23 23:11:03 +00:00
|
|
|
1 | 2 => Some(CursorShape::Block),
|
|
|
|
3 | 4 => Some(CursorShape::Underline),
|
|
|
|
5 | 6 => Some(CursorShape::Beam),
|
2019-08-15 23:13:10 +00:00
|
|
|
_ => {
|
|
|
|
unhandled!();
|
|
|
|
return;
|
|
|
|
},
|
2019-08-06 22:59:16 +00:00
|
|
|
};
|
2020-11-23 23:11:03 +00:00
|
|
|
let cursor_style =
|
|
|
|
shape.map(|shape| CursorStyle { shape, blinking: cursor_style_id % 2 == 1 });
|
2019-08-06 22:59:16 +00:00
|
|
|
|
2020-11-23 23:11:03 +00:00
|
|
|
handler.set_cursor_style(cursor_style);
|
2019-08-06 22:59:16 +00:00
|
|
|
},
|
2021-01-24 23:42:54 +00:00
|
|
|
('r', []) => {
|
2020-08-07 22:37:23 +00:00
|
|
|
let top = next_param_or(1) as usize;
|
|
|
|
let bottom =
|
|
|
|
params_iter.next().map(|param| param[0] as usize).filter(|¶m| param != 0);
|
2019-09-26 12:44:59 +00:00
|
|
|
|
|
|
|
handler.set_scrolling_region(top, bottom);
|
2016-06-08 17:39:49 +00:00
|
|
|
},
|
2021-03-30 23:25:38 +00:00
|
|
|
('S', []) => handler.scroll_up(next_param_or(1) as usize),
|
2021-01-24 23:42:54 +00:00
|
|
|
('s', []) => handler.save_cursor_position(),
|
2021-03-30 23:25:38 +00:00
|
|
|
('T', []) => handler.scroll_down(next_param_or(1) as usize),
|
2021-01-24 23:42:54 +00:00
|
|
|
('t', []) => match next_param_or(1) as usize {
|
2021-04-17 23:20:13 +00:00
|
|
|
14 => handler.text_area_size_pixels(),
|
|
|
|
18 => handler.text_area_size_chars(),
|
2020-07-03 20:27:18 +00:00
|
|
|
22 => handler.push_title(),
|
|
|
|
23 => handler.pop_title(),
|
|
|
|
_ => unhandled!(),
|
|
|
|
},
|
2021-01-24 23:42:54 +00:00
|
|
|
('u', []) => handler.restore_cursor_position(),
|
|
|
|
('X', []) => handler.erase_chars(Column(next_param_or(1) as usize)),
|
|
|
|
('Z', []) => handler.move_backward_tabs(next_param_or(1)),
|
2016-09-18 18:17:44 +00:00
|
|
|
_ => unhandled!(),
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-18 18:17:44 +00:00
|
|
|
#[inline]
|
2020-02-11 23:50:20 +00:00
|
|
|
fn esc_dispatch(&mut self, intermediates: &[u8], _ignore: bool, byte: u8) {
|
2017-01-09 20:07:23 +00:00
|
|
|
macro_rules! unhandled {
|
|
|
|
() => {{
|
2019-03-30 16:48:36 +00:00
|
|
|
debug!(
|
2020-02-11 23:50:20 +00:00
|
|
|
"[unhandled] esc_dispatch ints={:?}, byte={:?} ({:02x})",
|
|
|
|
intermediates, byte as char, byte
|
2019-03-30 16:48:36 +00:00
|
|
|
);
|
|
|
|
}};
|
2017-01-09 20:07:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! configure_charset {
|
2020-12-17 01:05:40 +00:00
|
|
|
($charset:path, $intermediates:expr) => {{
|
|
|
|
let index: CharsetIndex = match $intermediates {
|
|
|
|
[b'('] => CharsetIndex::G0,
|
|
|
|
[b')'] => CharsetIndex::G1,
|
|
|
|
[b'*'] => CharsetIndex::G2,
|
|
|
|
[b'+'] => CharsetIndex::G3,
|
2019-08-15 23:13:10 +00:00
|
|
|
_ => {
|
|
|
|
unhandled!();
|
|
|
|
return;
|
|
|
|
},
|
2017-01-09 20:07:23 +00:00
|
|
|
};
|
|
|
|
self.handler.configure_charset(index, $charset)
|
2019-03-30 16:48:36 +00:00
|
|
|
}};
|
2017-01-09 20:07:23 +00:00
|
|
|
}
|
|
|
|
|
2020-12-17 01:05:40 +00:00
|
|
|
match (byte, intermediates) {
|
|
|
|
(b'B', intermediates) => configure_charset!(StandardCharset::Ascii, intermediates),
|
|
|
|
(b'D', []) => self.handler.linefeed(),
|
|
|
|
(b'E', []) => {
|
2017-04-18 17:42:29 +00:00
|
|
|
self.handler.linefeed();
|
|
|
|
self.handler.carriage_return();
|
2019-03-30 16:48:36 +00:00
|
|
|
},
|
2020-12-17 01:05:40 +00:00
|
|
|
(b'H', []) => self.handler.set_horizontal_tabstop(),
|
|
|
|
(b'M', []) => self.handler.reverse_index(),
|
2021-04-17 23:20:13 +00:00
|
|
|
(b'Z', []) => self.handler.identify_terminal(None),
|
2020-12-17 01:05:40 +00:00
|
|
|
(b'c', []) => self.handler.reset_state(),
|
|
|
|
(b'0', intermediates) => {
|
|
|
|
configure_charset!(StandardCharset::SpecialCharacterAndLineDrawing, intermediates)
|
2019-03-30 16:48:36 +00:00
|
|
|
},
|
2020-12-17 01:05:40 +00:00
|
|
|
(b'7', []) => self.handler.save_cursor_position(),
|
|
|
|
(b'8', [b'#']) => self.handler.decaln(),
|
|
|
|
(b'8', []) => self.handler.restore_cursor_position(),
|
|
|
|
(b'=', []) => self.handler.set_keypad_application_mode(),
|
|
|
|
(b'>', []) => self.handler.unset_keypad_application_mode(),
|
2020-05-05 22:50:23 +00:00
|
|
|
// String terminator, do nothing (parser handles as string terminator).
|
2020-12-17 01:05:40 +00:00
|
|
|
(b'\\', []) => (),
|
2017-01-09 20:07:23 +00:00
|
|
|
_ => unhandled!(),
|
2016-09-18 18:17:44 +00:00
|
|
|
}
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-25 21:23:08 +00:00
|
|
|
#[inline]
|
2020-10-29 04:17:33 +00:00
|
|
|
fn attrs_from_sgr_parameters(params: &mut ParamsIter<'_>) -> Vec<Option<Attr>> {
|
2020-08-07 22:37:23 +00:00
|
|
|
let mut attrs = Vec::with_capacity(params.size_hint().0);
|
|
|
|
|
|
|
|
while let Some(param) = params.next() {
|
|
|
|
let attr = match param {
|
|
|
|
[0] => Some(Attr::Reset),
|
|
|
|
[1] => Some(Attr::Bold),
|
|
|
|
[2] => Some(Attr::Dim),
|
|
|
|
[3] => Some(Attr::Italic),
|
2020-08-12 16:05:22 +00:00
|
|
|
[4, 0] => Some(Attr::CancelUnderline),
|
|
|
|
[4, 2] => Some(Attr::DoubleUnderline),
|
|
|
|
[4, ..] => Some(Attr::Underline),
|
2020-08-07 22:37:23 +00:00
|
|
|
[5] => Some(Attr::BlinkSlow),
|
|
|
|
[6] => Some(Attr::BlinkFast),
|
|
|
|
[7] => Some(Attr::Reverse),
|
|
|
|
[8] => Some(Attr::Hidden),
|
|
|
|
[9] => Some(Attr::Strike),
|
|
|
|
[21] => Some(Attr::CancelBold),
|
|
|
|
[22] => Some(Attr::CancelBoldDim),
|
|
|
|
[23] => Some(Attr::CancelItalic),
|
|
|
|
[24] => Some(Attr::CancelUnderline),
|
|
|
|
[25] => Some(Attr::CancelBlink),
|
|
|
|
[27] => Some(Attr::CancelReverse),
|
|
|
|
[28] => Some(Attr::CancelHidden),
|
|
|
|
[29] => Some(Attr::CancelStrike),
|
|
|
|
[30] => Some(Attr::Foreground(Color::Named(NamedColor::Black))),
|
|
|
|
[31] => Some(Attr::Foreground(Color::Named(NamedColor::Red))),
|
|
|
|
[32] => Some(Attr::Foreground(Color::Named(NamedColor::Green))),
|
|
|
|
[33] => Some(Attr::Foreground(Color::Named(NamedColor::Yellow))),
|
|
|
|
[34] => Some(Attr::Foreground(Color::Named(NamedColor::Blue))),
|
|
|
|
[35] => Some(Attr::Foreground(Color::Named(NamedColor::Magenta))),
|
|
|
|
[36] => Some(Attr::Foreground(Color::Named(NamedColor::Cyan))),
|
|
|
|
[37] => Some(Attr::Foreground(Color::Named(NamedColor::White))),
|
|
|
|
[38] => {
|
|
|
|
let mut iter = params.map(|param| param[0]);
|
|
|
|
parse_sgr_color(&mut iter).map(Attr::Foreground)
|
|
|
|
},
|
|
|
|
[38, params @ ..] => {
|
|
|
|
let rgb_start = if params.len() > 4 { 2 } else { 1 };
|
|
|
|
let rgb_iter = params[rgb_start..].iter().copied();
|
|
|
|
let mut iter = iter::once(params[0]).chain(rgb_iter);
|
2019-08-06 22:59:16 +00:00
|
|
|
|
2020-08-07 22:37:23 +00:00
|
|
|
parse_sgr_color(&mut iter).map(Attr::Foreground)
|
2019-08-06 22:59:16 +00:00
|
|
|
},
|
2020-08-07 22:37:23 +00:00
|
|
|
[39] => Some(Attr::Foreground(Color::Named(NamedColor::Foreground))),
|
|
|
|
[40] => Some(Attr::Background(Color::Named(NamedColor::Black))),
|
|
|
|
[41] => Some(Attr::Background(Color::Named(NamedColor::Red))),
|
|
|
|
[42] => Some(Attr::Background(Color::Named(NamedColor::Green))),
|
|
|
|
[43] => Some(Attr::Background(Color::Named(NamedColor::Yellow))),
|
|
|
|
[44] => Some(Attr::Background(Color::Named(NamedColor::Blue))),
|
|
|
|
[45] => Some(Attr::Background(Color::Named(NamedColor::Magenta))),
|
|
|
|
[46] => Some(Attr::Background(Color::Named(NamedColor::Cyan))),
|
|
|
|
[47] => Some(Attr::Background(Color::Named(NamedColor::White))),
|
|
|
|
[48] => {
|
|
|
|
let mut iter = params.map(|param| param[0]);
|
|
|
|
parse_sgr_color(&mut iter).map(Attr::Background)
|
2019-08-06 22:59:16 +00:00
|
|
|
},
|
2020-08-07 22:37:23 +00:00
|
|
|
[48, params @ ..] => {
|
|
|
|
let rgb_start = if params.len() > 4 { 2 } else { 1 };
|
|
|
|
let rgb_iter = params[rgb_start..].iter().copied();
|
|
|
|
let mut iter = iter::once(params[0]).chain(rgb_iter);
|
|
|
|
|
|
|
|
parse_sgr_color(&mut iter).map(Attr::Background)
|
|
|
|
},
|
|
|
|
[49] => Some(Attr::Background(Color::Named(NamedColor::Background))),
|
|
|
|
[90] => Some(Attr::Foreground(Color::Named(NamedColor::BrightBlack))),
|
|
|
|
[91] => Some(Attr::Foreground(Color::Named(NamedColor::BrightRed))),
|
|
|
|
[92] => Some(Attr::Foreground(Color::Named(NamedColor::BrightGreen))),
|
|
|
|
[93] => Some(Attr::Foreground(Color::Named(NamedColor::BrightYellow))),
|
|
|
|
[94] => Some(Attr::Foreground(Color::Named(NamedColor::BrightBlue))),
|
|
|
|
[95] => Some(Attr::Foreground(Color::Named(NamedColor::BrightMagenta))),
|
|
|
|
[96] => Some(Attr::Foreground(Color::Named(NamedColor::BrightCyan))),
|
|
|
|
[97] => Some(Attr::Foreground(Color::Named(NamedColor::BrightWhite))),
|
|
|
|
[100] => Some(Attr::Background(Color::Named(NamedColor::BrightBlack))),
|
|
|
|
[101] => Some(Attr::Background(Color::Named(NamedColor::BrightRed))),
|
|
|
|
[102] => Some(Attr::Background(Color::Named(NamedColor::BrightGreen))),
|
|
|
|
[103] => Some(Attr::Background(Color::Named(NamedColor::BrightYellow))),
|
|
|
|
[104] => Some(Attr::Background(Color::Named(NamedColor::BrightBlue))),
|
|
|
|
[105] => Some(Attr::Background(Color::Named(NamedColor::BrightMagenta))),
|
|
|
|
[106] => Some(Attr::Background(Color::Named(NamedColor::BrightCyan))),
|
|
|
|
[107] => Some(Attr::Background(Color::Named(NamedColor::BrightWhite))),
|
2019-08-06 22:59:16 +00:00
|
|
|
_ => None,
|
|
|
|
};
|
|
|
|
attrs.push(attr);
|
|
|
|
}
|
2020-08-07 22:37:23 +00:00
|
|
|
|
2019-08-06 22:59:16 +00:00
|
|
|
attrs
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Parse a color specifier from list of attributes.
|
2020-11-26 00:57:44 +00:00
|
|
|
fn parse_sgr_color(params: &mut dyn Iterator<Item = u16>) -> Option<Color> {
|
2020-08-07 22:37:23 +00:00
|
|
|
match params.next() {
|
|
|
|
Some(2) => Some(Color::Spec(Rgb {
|
|
|
|
r: u8::try_from(params.next()?).ok()?,
|
|
|
|
g: u8::try_from(params.next()?).ok()?,
|
|
|
|
b: u8::try_from(params.next()?).ok()?,
|
|
|
|
})),
|
|
|
|
Some(5) => Some(Color::Indexed(u8::try_from(params.next()?).ok()?)),
|
|
|
|
_ => None,
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// C0 set of 7-bit control characters (from ANSI X3.4-1977).
|
2016-06-09 15:30:55 +00:00
|
|
|
#[allow(non_snake_case)]
|
|
|
|
pub mod C0 {
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Null filler, terminal should ignore this character.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const NUL: u8 = 0x00;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Start of Header.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const SOH: u8 = 0x01;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Start of Text, implied end of header.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const STX: u8 = 0x02;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// End of Text, causes some terminal to respond with ACK or NAK.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const ETX: u8 = 0x03;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// End of Transmission.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const EOT: u8 = 0x04;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Enquiry, causes terminal to send ANSWER-BACK ID.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const ENQ: u8 = 0x05;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Acknowledge, usually sent by terminal in response to ETX.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const ACK: u8 = 0x06;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Bell, triggers the bell, buzzer, or beeper on the terminal.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const BEL: u8 = 0x07;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Backspace, can be used to define overstruck characters.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const BS: u8 = 0x08;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Horizontal Tabulation, move to next predetermined position.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const HT: u8 = 0x09;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Linefeed, move to same position on next line (see also NL).
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const LF: u8 = 0x0A;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Vertical Tabulation, move to next predetermined line.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const VT: u8 = 0x0B;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Form Feed, move to next form or page.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const FF: u8 = 0x0C;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Carriage Return, move to first character of current line.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const CR: u8 = 0x0D;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Shift Out, switch to G1 (other half of character set).
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const SO: u8 = 0x0E;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Shift In, switch to G0 (normal half of character set).
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const SI: u8 = 0x0F;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Data Link Escape, interpret next control character specially.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const DLE: u8 = 0x10;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// (DC1) Terminal is allowed to resume transmitting.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const XON: u8 = 0x11;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Device Control 2, causes ASR-33 to activate paper-tape reader.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const DC2: u8 = 0x12;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// (DC2) Terminal must pause and refrain from transmitting.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const XOFF: u8 = 0x13;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Device Control 4, causes ASR-33 to deactivate paper-tape reader.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const DC4: u8 = 0x14;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Negative Acknowledge, used sometimes with ETX and ACK.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const NAK: u8 = 0x15;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Synchronous Idle, used to maintain timing in Sync communication.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const SYN: u8 = 0x16;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// End of Transmission block.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const ETB: u8 = 0x17;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Cancel (makes VT100 abort current escape sequence if any).
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const CAN: u8 = 0x18;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// End of Medium.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const EM: u8 = 0x19;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Substitute (VT100 uses this to display parity errors).
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const SUB: u8 = 0x1A;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Prefix to an escape sequence.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const ESC: u8 = 0x1B;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// File Separator.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const FS: u8 = 0x1C;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Group Separator.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const GS: u8 = 0x1D;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Record Separator (sent by VT132 in block-transfer mode).
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const RS: u8 = 0x1E;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Unit Separator.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const US: u8 = 0x1F;
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Delete, should be ignored by terminal.
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const DEL: u8 = 0x7f;
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Tests for parsing escape sequences.
|
2016-07-30 01:01:10 +00:00
|
|
|
//
|
|
|
|
// Byte sequences used in these tests are recording of pty stdout.
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2021-04-17 23:20:13 +00:00
|
|
|
use super::*;
|
|
|
|
|
2019-02-07 22:36:45 +00:00
|
|
|
use crate::term::color::Rgb;
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
|
2019-11-17 02:10:11 +00:00
|
|
|
struct MockHandler {
|
|
|
|
index: CharsetIndex,
|
|
|
|
charset: StandardCharset,
|
|
|
|
attr: Option<Attr>,
|
|
|
|
identity_reported: bool,
|
|
|
|
}
|
2016-12-04 23:48:30 +00:00
|
|
|
|
2019-11-17 02:10:11 +00:00
|
|
|
impl Handler for MockHandler {
|
|
|
|
fn terminal_attribute(&mut self, attr: Attr) {
|
|
|
|
self.attr = Some(attr);
|
2016-12-04 23:48:30 +00:00
|
|
|
}
|
|
|
|
|
2019-11-17 02:10:11 +00:00
|
|
|
fn configure_charset(&mut self, index: CharsetIndex, charset: StandardCharset) {
|
|
|
|
self.index = index;
|
|
|
|
self.charset = charset;
|
2016-12-04 23:48:30 +00:00
|
|
|
}
|
|
|
|
|
2019-11-17 02:10:11 +00:00
|
|
|
fn set_active_charset(&mut self, index: CharsetIndex) {
|
|
|
|
self.index = index;
|
|
|
|
}
|
2016-06-08 17:39:49 +00:00
|
|
|
|
2021-04-17 23:20:13 +00:00
|
|
|
fn identify_terminal(&mut self, _intermediate: Option<char>) {
|
2019-11-17 02:10:11 +00:00
|
|
|
self.identity_reported = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn reset_state(&mut self) {
|
|
|
|
*self = Self::default();
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
}
|
2016-06-08 17:39:49 +00:00
|
|
|
}
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
|
2019-11-17 02:10:11 +00:00
|
|
|
impl Default for MockHandler {
|
|
|
|
fn default() -> MockHandler {
|
|
|
|
MockHandler {
|
|
|
|
index: CharsetIndex::G0,
|
|
|
|
charset: StandardCharset::Ascii,
|
|
|
|
attr: None,
|
|
|
|
identity_reported: false,
|
|
|
|
}
|
2016-06-08 17:39:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_control_attribute() {
|
2019-11-17 02:10:11 +00:00
|
|
|
static BYTES: &[u8] = &[0x1b, b'[', b'1', b'm'];
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
|
2016-09-18 18:17:44 +00:00
|
|
|
let mut parser = Processor::new();
|
2019-11-17 02:10:11 +00:00
|
|
|
let mut handler = MockHandler::default();
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
|
2021-02-13 18:15:57 +00:00
|
|
|
for byte in BYTES {
|
2021-04-17 23:20:13 +00:00
|
|
|
parser.advance(&mut handler, *byte);
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
}
|
|
|
|
|
2016-05-31 03:44:37 +00:00
|
|
|
assert_eq!(handler.attr, Some(Attr::Bold));
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-17 02:10:11 +00:00
|
|
|
fn parse_terminal_identity_csi() {
|
|
|
|
let bytes: &[u8] = &[0x1b, b'[', b'1', b'c'];
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
|
2016-09-18 18:17:44 +00:00
|
|
|
let mut parser = Processor::new();
|
2019-11-17 02:10:11 +00:00
|
|
|
let mut handler = MockHandler::default();
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
|
2021-02-13 18:15:57 +00:00
|
|
|
for byte in bytes {
|
2021-04-17 23:20:13 +00:00
|
|
|
parser.advance(&mut handler, *byte);
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
}
|
|
|
|
|
2019-11-17 02:10:11 +00:00
|
|
|
assert!(!handler.identity_reported);
|
|
|
|
handler.reset_state();
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
|
2019-11-17 02:10:11 +00:00
|
|
|
let bytes: &[u8] = &[0x1b, b'[', b'c'];
|
|
|
|
|
2021-02-13 18:15:57 +00:00
|
|
|
for byte in bytes {
|
2021-04-17 23:20:13 +00:00
|
|
|
parser.advance(&mut handler, *byte);
|
2019-11-17 02:10:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert!(handler.identity_reported);
|
|
|
|
handler.reset_state();
|
|
|
|
|
|
|
|
let bytes: &[u8] = &[0x1b, b'[', b'0', b'c'];
|
|
|
|
|
2021-02-13 18:15:57 +00:00
|
|
|
for byte in bytes {
|
2021-04-17 23:20:13 +00:00
|
|
|
parser.advance(&mut handler, *byte);
|
2019-11-17 02:10:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert!(handler.identity_reported);
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-11-17 02:10:11 +00:00
|
|
|
fn parse_terminal_identity_esc() {
|
|
|
|
let bytes: &[u8] = &[0x1b, b'Z'];
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
|
2016-09-18 18:17:44 +00:00
|
|
|
let mut parser = Processor::new();
|
2019-11-17 02:10:11 +00:00
|
|
|
let mut handler = MockHandler::default();
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
|
2021-02-13 18:15:57 +00:00
|
|
|
for byte in bytes {
|
2021-04-17 23:20:13 +00:00
|
|
|
parser.advance(&mut handler, *byte);
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
}
|
2017-01-09 20:07:23 +00:00
|
|
|
|
2019-11-17 02:10:11 +00:00
|
|
|
assert!(handler.identity_reported);
|
|
|
|
handler.reset_state();
|
|
|
|
|
|
|
|
let bytes: &[u8] = &[0x1b, b'#', b'Z'];
|
|
|
|
|
|
|
|
let mut parser = Processor::new();
|
|
|
|
let mut handler = MockHandler::default();
|
2017-01-09 20:07:23 +00:00
|
|
|
|
2021-02-13 18:15:57 +00:00
|
|
|
for byte in bytes {
|
2021-04-17 23:20:13 +00:00
|
|
|
parser.advance(&mut handler, *byte);
|
2017-01-09 20:07:23 +00:00
|
|
|
}
|
2019-11-17 02:10:11 +00:00
|
|
|
|
|
|
|
assert!(!handler.identity_reported);
|
|
|
|
handler.reset_state();
|
2017-01-09 20:07:23 +00:00
|
|
|
}
|
|
|
|
|
2019-11-17 02:10:11 +00:00
|
|
|
#[test]
|
|
|
|
fn parse_truecolor_attr() {
|
|
|
|
static BYTES: &[u8] = &[
|
|
|
|
0x1b, b'[', b'3', b'8', b';', b'2', b';', b'1', b'2', b'8', b';', b'6', b'6', b';',
|
|
|
|
b'2', b'5', b'5', b'm',
|
|
|
|
];
|
2017-01-09 20:07:23 +00:00
|
|
|
|
2019-11-17 02:10:11 +00:00
|
|
|
let mut parser = Processor::new();
|
|
|
|
let mut handler = MockHandler::default();
|
|
|
|
|
2021-02-13 18:15:57 +00:00
|
|
|
for byte in BYTES {
|
2021-04-17 23:20:13 +00:00
|
|
|
parser.advance(&mut handler, *byte);
|
2017-01-09 20:07:23 +00:00
|
|
|
}
|
2019-11-17 02:10:11 +00:00
|
|
|
|
|
|
|
let spec = Rgb { r: 128, g: 66, b: 255 };
|
|
|
|
|
|
|
|
assert_eq!(handler.attr, Some(Attr::Foreground(Color::Spec(spec))));
|
2017-01-09 20:07:23 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// No exactly a test; useful for debugging.
|
2019-11-17 02:10:11 +00:00
|
|
|
#[test]
|
|
|
|
fn parse_zsh_startup() {
|
|
|
|
static BYTES: &[u8] = &[
|
|
|
|
0x1b, b'[', b'1', b'm', 0x1b, b'[', b'7', b'm', b'%', 0x1b, b'[', b'2', b'7', b'm',
|
|
|
|
0x1b, b'[', b'1', b'm', 0x1b, b'[', b'0', b'm', b' ', b' ', b' ', b' ', b' ', b' ',
|
|
|
|
b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ',
|
|
|
|
b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ',
|
|
|
|
b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ',
|
|
|
|
b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ',
|
|
|
|
b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ', b' ',
|
|
|
|
b' ', b' ', b' ', b'\r', b' ', b'\r', b'\r', 0x1b, b'[', b'0', b'm', 0x1b, b'[', b'2',
|
|
|
|
b'7', b'm', 0x1b, b'[', b'2', b'4', b'm', 0x1b, b'[', b'J', b'j', b'w', b'i', b'l',
|
|
|
|
b'm', b'@', b'j', b'w', b'i', b'l', b'm', b'-', b'd', b'e', b's', b'k', b' ', 0x1b,
|
|
|
|
b'[', b'0', b'1', b';', b'3', b'2', b'm', 0xe2, 0x9e, 0x9c, b' ', 0x1b, b'[', b'0',
|
|
|
|
b'1', b';', b'3', b'2', b'm', b' ', 0x1b, b'[', b'3', b'6', b'm', b'~', b'/', b'c',
|
|
|
|
b'o', b'd', b'e',
|
|
|
|
];
|
2019-03-30 16:48:36 +00:00
|
|
|
|
2019-11-17 02:10:11 +00:00
|
|
|
let mut handler = MockHandler::default();
|
|
|
|
let mut parser = Processor::new();
|
|
|
|
|
2021-02-13 18:15:57 +00:00
|
|
|
for byte in BYTES {
|
2021-04-17 23:20:13 +00:00
|
|
|
parser.advance(&mut handler, *byte);
|
2019-03-30 16:48:36 +00:00
|
|
|
}
|
2017-01-09 20:07:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_designate_g0_as_line_drawing() {
|
2019-06-18 21:23:03 +00:00
|
|
|
static BYTES: &[u8] = &[0x1b, b'(', b'0'];
|
2017-01-09 20:07:23 +00:00
|
|
|
let mut parser = Processor::new();
|
2019-11-17 02:10:11 +00:00
|
|
|
let mut handler = MockHandler::default();
|
2017-01-09 20:07:23 +00:00
|
|
|
|
2021-02-13 18:15:57 +00:00
|
|
|
for byte in BYTES {
|
2021-04-17 23:20:13 +00:00
|
|
|
parser.advance(&mut handler, *byte);
|
2017-01-09 20:07:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert_eq!(handler.index, CharsetIndex::G0);
|
|
|
|
assert_eq!(handler.charset, StandardCharset::SpecialCharacterAndLineDrawing);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_designate_g1_as_line_drawing_and_invoke() {
|
2019-11-17 02:10:11 +00:00
|
|
|
static BYTES: &[u8] = &[0x1b, b')', b'0', 0x0e];
|
2017-01-09 20:07:23 +00:00
|
|
|
let mut parser = Processor::new();
|
2019-11-17 02:10:11 +00:00
|
|
|
let mut handler = MockHandler::default();
|
2017-01-09 20:07:23 +00:00
|
|
|
|
|
|
|
for byte in &BYTES[..3] {
|
2021-04-17 23:20:13 +00:00
|
|
|
parser.advance(&mut handler, *byte);
|
2017-01-09 20:07:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert_eq!(handler.index, CharsetIndex::G1);
|
|
|
|
assert_eq!(handler.charset, StandardCharset::SpecialCharacterAndLineDrawing);
|
|
|
|
|
2019-11-17 02:10:11 +00:00
|
|
|
let mut handler = MockHandler::default();
|
2021-04-17 23:20:13 +00:00
|
|
|
parser.advance(&mut handler, BYTES[3]);
|
2017-01-09 20:07:23 +00:00
|
|
|
|
|
|
|
assert_eq!(handler.index, CharsetIndex::G1);
|
|
|
|
}
|
2017-07-28 22:14:18 +00:00
|
|
|
|
|
|
|
#[test]
|
2019-08-19 19:56:27 +00:00
|
|
|
fn parse_valid_rgb_colors() {
|
2019-08-28 00:35:34 +00:00
|
|
|
assert_eq!(xparse_color(b"rgb:f/e/d"), Some(Rgb { r: 0xff, g: 0xee, b: 0xdd }));
|
|
|
|
assert_eq!(xparse_color(b"rgb:11/aa/ff"), Some(Rgb { r: 0x11, g: 0xaa, b: 0xff }));
|
|
|
|
assert_eq!(xparse_color(b"rgb:f/ed1/cb23"), Some(Rgb { r: 0xff, g: 0xec, b: 0xca }));
|
|
|
|
assert_eq!(xparse_color(b"rgb:ffff/0/0"), Some(Rgb { r: 0xff, g: 0x0, b: 0x0 }));
|
2019-08-19 19:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_valid_legacy_rgb_colors() {
|
2019-08-28 00:35:34 +00:00
|
|
|
assert_eq!(xparse_color(b"#1af"), Some(Rgb { r: 0x10, g: 0xa0, b: 0xf0 }));
|
|
|
|
assert_eq!(xparse_color(b"#11aaff"), Some(Rgb { r: 0x11, g: 0xaa, b: 0xff }));
|
|
|
|
assert_eq!(xparse_color(b"#110aa0ff0"), Some(Rgb { r: 0x11, g: 0xaa, b: 0xff }));
|
|
|
|
assert_eq!(xparse_color(b"#1100aa00ff00"), Some(Rgb { r: 0x11, g: 0xaa, b: 0xff }));
|
2019-08-19 19:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_invalid_rgb_colors() {
|
2019-08-28 00:35:34 +00:00
|
|
|
assert_eq!(xparse_color(b"rgb:0//"), None);
|
|
|
|
assert_eq!(xparse_color(b"rgb://///"), None);
|
2017-07-28 22:14:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-08-19 19:56:27 +00:00
|
|
|
fn parse_invalid_legacy_rgb_colors() {
|
2019-08-28 00:35:34 +00:00
|
|
|
assert_eq!(xparse_color(b"#"), None);
|
|
|
|
assert_eq!(xparse_color(b"#f"), None);
|
2017-07-28 22:14:18 +00:00
|
|
|
}
|
2017-11-12 03:11:21 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_invalid_number() {
|
|
|
|
assert_eq!(parse_number(b"1abc"), None);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_valid_number() {
|
|
|
|
assert_eq!(parse_number(b"123"), Some(123));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_number_too_large() {
|
|
|
|
assert_eq!(parse_number(b"321"), None);
|
|
|
|
}
|
Initial ANSI parser implementation
This is the initial terminal stream parsing implementation for
Alacritty. There are currently several TODOs, FIXMEs, and unimplemented!
things scattered about still, but what's here is good enough to
correctly parse my zsh startup.
The `Parser` implementation is largely based on the suck-less _simple
terminal_ parser. Because this is Rust and Rust has a fantastic type
system, some improvements are possible. First, `Parser` is a struct, and
its data is stored internally instead of statically. Second, there's no
terminal updates hard-coded into the parser. Instead, `Parser` is
generic over a `Handler` type which has methods for all of the actions
supported by the parser. Because Parser is generic, it should be
possible (with proper inlining) to have equivalent performance to the
hard-coded version.
In addition to using _simple terminal_ as a reference, there's a doc in
Alacritty's repository `docs/ansicode.txt`, a summary of the ANSI
terminal protocol, which has been referenced extensively.
There's probably a large number escapes we don't handle, and that's ok.
There's a lot that aren't necessary for everyday terminal usage. If you
feel like something that's not supported should be, feel free to add it.
Please try not to become overzealous and adding support for sequences
only used by folks trapped in 1988.
2016-05-29 05:09:25 +00:00
|
|
|
}
|