2016-06-30 03:56:12 +00:00
|
|
|
// Copyright 2016 Joe Wilm, The Alacritty Project Contributors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
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
|
|
|
//! ANSI Terminal Stream Parsing
|
2016-12-04 23:48:30 +00:00
|
|
|
use std::io;
|
2017-01-11 05:21:19 +00:00
|
|
|
use std::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};
|
|
|
|
|
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
|
|
|
|
2019-08-19 19:56:27 +00:00
|
|
|
// Parse colors in XParseColor format
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2019-08-19 19:56:27 +00:00
|
|
|
// Scale values instead of filling with `0`s
|
|
|
|
let scale = |input: &str| {
|
|
|
|
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)
|
|
|
|
};
|
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
|
|
|
|
2019-08-19 19:56:27 +00:00
|
|
|
// Parse colors in `#r(rrr)g(ggg)b(bbb)` format
|
|
|
|
fn parse_legacy_color(color: &[u8]) -> Option<Rgb> {
|
|
|
|
let item_len = color.len() / 3;
|
2017-07-28 22:14:18 +00:00
|
|
|
|
2019-08-19 19:56:27 +00:00
|
|
|
// Truncate/Fill to two byte precision
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2016-12-17 06:13:51 +00:00
|
|
|
/// The processor wraps a `vte::Parser` to ultimately call methods on a Handler
|
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
|
|
|
}
|
|
|
|
|
2016-09-18 18:17:44 +00:00
|
|
|
/// Internal state for VTE processor
|
2017-09-29 12:05:19 +00:00
|
|
|
struct ProcessorState {
|
2019-03-30 16:48:36 +00:00
|
|
|
preceding_char: Option<char>,
|
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`.
|
2018-12-10 17:53:56 +00:00
|
|
|
struct Performer<'a, H: Handler + TermInfo, W: io::Write> {
|
2019-10-05 00:29:26 +00:00
|
|
|
state: &'a mut ProcessorState,
|
2016-12-04 23:48:30 +00:00
|
|
|
handler: &'a mut H,
|
2019-03-30 16:48:36 +00:00
|
|
|
writer: &'a mut W,
|
2016-09-18 18:17:44 +00:00
|
|
|
}
|
|
|
|
|
2016-12-04 23:48:30 +00:00
|
|
|
impl<'a, H: Handler + TermInfo + 'a, W: io::Write> Performer<'a, H, W> {
|
2016-09-18 18:17:44 +00:00
|
|
|
/// Create a performer
|
|
|
|
#[inline]
|
2016-12-04 23:48:30 +00:00
|
|
|
pub fn new<'b>(
|
|
|
|
state: &'b mut ProcessorState,
|
|
|
|
handler: &'b mut H,
|
|
|
|
writer: &'b mut W,
|
|
|
|
) -> Performer<'b, H, W> {
|
2019-10-05 00:29:26 +00:00
|
|
|
Performer { state, handler, writer }
|
2016-09-18 18:17:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-17 06:13:51 +00:00
|
|
|
impl Default for Processor {
|
|
|
|
fn default() -> Processor {
|
2019-03-30 16:48:36 +00:00
|
|
|
Processor { state: ProcessorState { preceding_char: None }, parser: vte::Parser::new() }
|
2016-09-18 18:17:44 +00:00
|
|
|
}
|
2016-12-17 06:13:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Processor {
|
|
|
|
pub fn new() -> Processor {
|
|
|
|
Default::default()
|
|
|
|
}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
|
|
|
#[inline]
|
2019-03-30 16:48:36 +00:00
|
|
|
pub fn advance<H, W>(&mut self, handler: &mut H, byte: u8, writer: &mut W)
|
|
|
|
where
|
|
|
|
H: Handler + TermInfo,
|
|
|
|
W: io::Write,
|
2016-12-04 23:48:30 +00:00
|
|
|
{
|
|
|
|
let mut performer = Performer::new(&mut self.state, handler, writer);
|
2016-09-18 18:17:44 +00:00
|
|
|
self.parser.advance(&mut performer, byte);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-08 17:39:49 +00:00
|
|
|
/// Trait that provides properties of terminal
|
|
|
|
pub trait TermInfo {
|
2016-07-04 04:12:43 +00:00
|
|
|
fn lines(&self) -> Line;
|
|
|
|
fn cols(&self) -> Column;
|
2016-06-08 17:39:49 +00:00
|
|
|
}
|
|
|
|
|
2016-09-18 18:17:44 +00:00
|
|
|
/// Type that handles actions from the parser
|
|
|
|
///
|
|
|
|
/// XXX Should probably not provide default impls for everything, but it makes
|
|
|
|
/// writing specific handler impls for tests far easier.
|
|
|
|
pub trait Handler {
|
2017-01-11 05:21:19 +00:00
|
|
|
/// OSC to set window title
|
2018-12-10 17:53:56 +00:00
|
|
|
fn set_title(&mut self, _: &str) {}
|
2017-01-11 05:21:19 +00:00
|
|
|
|
2017-05-28 16:38:10 +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
|
|
|
|
2016-09-18 18:17:44 +00:00
|
|
|
/// A character to be displayed
|
|
|
|
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
|
|
|
|
2016-09-18 18:17:44 +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
|
|
|
|
|
|
|
/// 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
|
|
|
|
|
|
|
/// 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
|
|
|
|
|
|
|
/// Insert blank characters in current line starting from cursor
|
2018-12-10 17:53:56 +00:00
|
|
|
fn insert_blank(&mut self, _: Column) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
|
|
|
/// Move cursor up `rows`
|
2018-12-10 17:53:56 +00:00
|
|
|
fn move_up(&mut self, _: Line) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
|
|
|
/// Move cursor down `rows`
|
2018-12-10 17:53:56 +00:00
|
|
|
fn move_down(&mut self, _: Line) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
|
|
|
/// Identify the terminal (should write back to the pty stream)
|
2016-12-04 23:48:30 +00:00
|
|
|
///
|
|
|
|
/// TODO this should probably return an io::Result
|
2018-12-10 17:53:56 +00:00
|
|
|
fn identify_terminal<W: io::Write>(&mut self, _: &mut W) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
2017-05-07 20:08:23 +00:00
|
|
|
// Report device status
|
2018-12-10 17:53:56 +00:00
|
|
|
fn device_status<W: io::Write>(&mut self, _: &mut W, _: usize) {}
|
2017-05-07 20:08:23 +00:00
|
|
|
|
2016-09-18 18:17:44 +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
|
|
|
|
2016-09-18 18:17:44 +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
|
|
|
|
|
|
|
/// Move cursor down `rows` and set to column 1
|
2018-12-10 17:53:56 +00:00
|
|
|
fn move_down_and_cr(&mut self, _: Line) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
|
|
|
/// Move cursor up `rows` and set to column 1
|
2018-12-10 17:53:56 +00:00
|
|
|
fn move_up_and_cr(&mut self, _: Line) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
|
|
|
/// Put `count` tabs
|
|
|
|
fn put_tab(&mut self, _count: i64) {}
|
|
|
|
|
|
|
|
/// Backspace `count` characters
|
|
|
|
fn backspace(&mut self) {}
|
|
|
|
|
|
|
|
/// Carriage return
|
|
|
|
fn carriage_return(&mut self) {}
|
|
|
|
|
|
|
|
/// Linefeed
|
|
|
|
fn linefeed(&mut self) {}
|
|
|
|
|
|
|
|
/// Ring the bell
|
|
|
|
///
|
|
|
|
/// Hopefully this is never implemented
|
|
|
|
fn bell(&mut self) {}
|
|
|
|
|
|
|
|
/// Substitute char under cursor
|
|
|
|
fn substitute(&mut self) {}
|
|
|
|
|
|
|
|
/// Newline
|
|
|
|
fn newline(&mut self) {}
|
|
|
|
|
|
|
|
/// Set current position as a tabstop
|
|
|
|
fn set_horizontal_tabstop(&mut self) {}
|
|
|
|
|
|
|
|
/// Scroll up `rows` rows
|
2018-12-10 17:53:56 +00:00
|
|
|
fn scroll_up(&mut self, _: Line) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
|
|
|
/// Scroll down `rows` rows
|
2018-12-10 17:53:56 +00:00
|
|
|
fn scroll_down(&mut self, _: Line) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
|
|
|
/// Insert `count` blank lines
|
2018-12-10 17:53:56 +00:00
|
|
|
fn insert_blank_lines(&mut self, _: Line) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
|
|
|
/// Delete `count` lines
|
2018-12-10 17:53:56 +00:00
|
|
|
fn delete_lines(&mut self, _: Line) {}
|
2016-09-18 18:17:44 +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,
|
|
|
|
/// 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
|
|
|
|
2016-09-18 18:17:44 +00:00
|
|
|
/// Delete `count` chars
|
|
|
|
///
|
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.
|
2018-12-10 17:53:56 +00:00
|
|
|
fn delete_chars(&mut self, _: Column) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
|
|
|
/// Move backward `count` tabs
|
|
|
|
fn move_backward_tabs(&mut self, _count: i64) {}
|
|
|
|
|
|
|
|
/// Move forward `count` tabs
|
|
|
|
fn move_forward_tabs(&mut self, _count: i64) {}
|
|
|
|
|
|
|
|
/// Save current cursor position
|
|
|
|
fn save_cursor_position(&mut self) {}
|
|
|
|
|
|
|
|
/// Restore cursor position
|
|
|
|
fn restore_cursor_position(&mut self) {}
|
|
|
|
|
|
|
|
/// Clear current line
|
|
|
|
fn clear_line(&mut self, _mode: LineClearMode) {}
|
|
|
|
|
|
|
|
/// Clear screen
|
|
|
|
fn clear_screen(&mut self, _mode: ClearMode) {}
|
|
|
|
|
|
|
|
/// Clear tab stops
|
|
|
|
fn clear_tabs(&mut self, _mode: TabulationClearMode) {}
|
|
|
|
|
|
|
|
/// Reset terminal state
|
|
|
|
fn reset_state(&mut self) {}
|
|
|
|
|
|
|
|
/// Reverse Index
|
|
|
|
///
|
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
|
|
|
|
/// down is performed
|
2016-09-18 18:17:44 +00:00
|
|
|
fn reverse_index(&mut self) {}
|
|
|
|
|
|
|
|
/// set a terminal attribute
|
|
|
|
fn terminal_attribute(&mut self, _attr: Attr) {}
|
|
|
|
|
|
|
|
/// Set mode
|
|
|
|
fn set_mode(&mut self, _mode: Mode) {}
|
|
|
|
|
|
|
|
/// Unset mode
|
2018-12-10 17:53:56 +00:00
|
|
|
fn unset_mode(&mut self, _: Mode) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
|
|
|
/// DECSTBM - Set the terminal scrolling region
|
2019-09-26 12:44:59 +00:00
|
|
|
fn set_scrolling_region(&mut self, _top: usize, _bottom: usize) {}
|
2016-09-18 18:17:44 +00:00
|
|
|
|
|
|
|
/// DECKPAM - Set keypad to applications mode (ESCape instead of digits)
|
|
|
|
fn set_keypad_application_mode(&mut self) {}
|
|
|
|
|
2017-10-30 15:03:58 +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,
|
2017-01-09 20:07: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
|
|
|
|
|
|
|
/// Assign a graphic character set to G0, G1, G2 or G3
|
|
|
|
///
|
|
|
|
/// 'Designate' a graphic character set as one of G0 to G3, so that it can
|
|
|
|
/// 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
|
|
|
|
|
|
|
/// 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
|
|
|
|
2019-06-02 13:16:38 +00:00
|
|
|
/// Write a foreground/background color escape sequence with the current color
|
2020-01-31 00:00:23 +00:00
|
|
|
fn dynamic_color_sequence<W: io::Write>(&mut self, _: &mut W, _: u8, _: usize, _: &str) {}
|
2019-06-02 13:16:38 +00:00
|
|
|
|
2017-07-28 22:14:18 +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
|
|
|
|
2018-01-02 16:32:50 +00:00
|
|
|
/// Set the clipboard
|
2019-11-11 00:12:14 +00:00
|
|
|
fn set_clipboard(&mut self, _: u8, _: &[u8]) {}
|
|
|
|
|
|
|
|
/// Write clipboard data to child.
|
2020-01-31 00:00:23 +00:00
|
|
|
fn write_clipboard<W: io::Write>(&mut self, _: u8, _: &mut W, _: &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
|
|
|
|
|
|
|
/// Push a title onto the stack
|
|
|
|
fn push_title(&mut self) {}
|
|
|
|
|
|
|
|
/// Pop the last title from the stack
|
|
|
|
fn pop_title(&mut self) {}
|
2016-05-31 03:44:37 +00:00
|
|
|
}
|
|
|
|
|
2017-05-28 16:38:10 +00:00
|
|
|
/// Describes shape of cursor
|
2019-04-25 20:01:23 +00:00
|
|
|
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash, Deserialize)]
|
2017-05-28 16:38:10 +00:00
|
|
|
pub enum CursorStyle {
|
|
|
|
/// Cursor is a block like `▒`
|
|
|
|
Block,
|
|
|
|
|
|
|
|
/// Cursor is an underscore like `_`
|
|
|
|
Underline,
|
|
|
|
|
|
|
|
/// Cursor is a vertical bar `⎸`
|
|
|
|
Beam,
|
2018-01-06 01:42:55 +00:00
|
|
|
|
|
|
|
/// Cursor is a box like `☐`
|
2020-03-02 20:41:26 +00:00
|
|
|
#[serde(skip)]
|
2018-01-06 01:42:55 +00:00
|
|
|
HollowBlock,
|
2019-04-22 00:20:43 +00:00
|
|
|
|
|
|
|
/// Invisible cursor
|
2020-03-02 20:41:26 +00:00
|
|
|
#[serde(skip)]
|
2019-04-22 00:20:43 +00:00
|
|
|
Hidden,
|
2017-05-28 16:38:10 +00:00
|
|
|
}
|
|
|
|
|
2017-12-03 21:38:42 +00:00
|
|
|
impl Default for CursorStyle {
|
|
|
|
fn default() -> CursorStyle {
|
|
|
|
CursorStyle::Block
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-31 03:44:37 +00:00
|
|
|
/// Terminal modes
|
|
|
|
#[derive(Debug, Eq, PartialEq)]
|
|
|
|
pub enum Mode {
|
2016-06-08 04:13:08 +00:00
|
|
|
/// ?1
|
|
|
|
CursorKeys = 1,
|
2017-04-19 16:03:33 +00:00
|
|
|
/// Select 80 or 132 columns per page
|
|
|
|
///
|
|
|
|
/// CSI ? 3 h -> set 132 column font
|
|
|
|
/// CSI ? 3 l -> reset 80 column font
|
|
|
|
///
|
|
|
|
/// 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)
|
|
|
|
DECCOLM = 3,
|
2017-05-01 05:10:38 +00:00
|
|
|
/// IRM Insert Mode
|
|
|
|
///
|
|
|
|
/// NB should be part of non-private mode enum
|
|
|
|
///
|
|
|
|
/// * `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,
|
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 {
|
|
|
|
/// Create mode from a primitive
|
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
|
|
|
/// TODO lots of unhandled values..
|
2019-10-14 17:50:58 +00:00
|
|
|
pub fn from_primitive(intermediate: Option<&u8>, num: i64) -> Option<Mode> {
|
|
|
|
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,
|
2017-04-19 16:03:33 +00:00
|
|
|
3 => Mode::DECCOLM,
|
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,
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/// Mode for clearing line
|
|
|
|
///
|
|
|
|
/// Relative to cursor
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum LineClearMode {
|
|
|
|
/// Clear right of cursor
|
|
|
|
Right,
|
|
|
|
/// Clear left of cursor
|
|
|
|
Left,
|
|
|
|
/// Clear entire line
|
|
|
|
All,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Mode for clearing terminal
|
|
|
|
///
|
|
|
|
/// Relative to cursor
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum ClearMode {
|
|
|
|
/// Clear below cursor
|
|
|
|
Below,
|
|
|
|
/// Clear above cursor
|
|
|
|
Above,
|
|
|
|
/// Clear entire terminal
|
|
|
|
All,
|
2017-03-04 04:22:54 +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
|
|
|
}
|
|
|
|
|
|
|
|
/// Mode for clearing tab stops
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum TabulationClearMode {
|
|
|
|
/// Clear stop under cursor
|
|
|
|
Current,
|
|
|
|
/// Clear all stops
|
|
|
|
All,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Standard colors
|
|
|
|
///
|
|
|
|
/// The order here matters since the enum should be castable to a `usize` for
|
|
|
|
/// indexing a color list.
|
2016-11-20 00:16:20 +00:00
|
|
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
|
2016-12-04 19:14:27 +00:00
|
|
|
pub enum NamedColor {
|
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
|
|
|
|
Black = 0,
|
|
|
|
/// Red
|
|
|
|
Red,
|
|
|
|
/// Green
|
|
|
|
Green,
|
|
|
|
/// Yellow
|
|
|
|
Yellow,
|
|
|
|
/// Blue
|
|
|
|
Blue,
|
|
|
|
/// Magenta
|
|
|
|
Magenta,
|
|
|
|
/// Cyan
|
|
|
|
Cyan,
|
|
|
|
/// White
|
|
|
|
White,
|
|
|
|
/// Bright black
|
|
|
|
BrightBlack,
|
|
|
|
/// Bright red
|
|
|
|
BrightRed,
|
|
|
|
/// Bright green
|
|
|
|
BrightGreen,
|
|
|
|
/// Bright yellow
|
|
|
|
BrightYellow,
|
|
|
|
/// Bright blue
|
|
|
|
BrightBlue,
|
|
|
|
/// Bright magenta
|
|
|
|
BrightMagenta,
|
|
|
|
/// Bright cyan
|
|
|
|
BrightCyan,
|
|
|
|
/// Bright white
|
|
|
|
BrightWhite,
|
2016-10-23 22:37:06 +00:00
|
|
|
/// The foreground color
|
2016-12-04 19:14:27 +00:00
|
|
|
Foreground = 256,
|
2016-10-23 22:37:06 +00:00
|
|
|
/// The background color
|
|
|
|
Background,
|
2017-02-24 16:23:07 +00:00
|
|
|
/// Color for the cursor itself
|
|
|
|
Cursor,
|
2017-06-23 17:01:53 +00:00
|
|
|
/// Dim black
|
|
|
|
DimBlack,
|
|
|
|
/// Dim red
|
|
|
|
DimRed,
|
|
|
|
/// Dim green
|
|
|
|
DimGreen,
|
|
|
|
/// Dim yellow
|
|
|
|
DimYellow,
|
|
|
|
/// Dim blue
|
|
|
|
DimBlue,
|
|
|
|
/// Dim magenta
|
|
|
|
DimMagenta,
|
|
|
|
/// Dim cyan
|
|
|
|
DimCyan,
|
|
|
|
/// Dim white
|
|
|
|
DimWhite,
|
2018-07-15 19:47:07 +00:00
|
|
|
/// The bright foreground color
|
|
|
|
BrightForeground,
|
2018-07-23 16:48:27 +00:00
|
|
|
/// Dim foreground
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-04 19:14:27 +00:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
|
|
|
pub enum Color {
|
|
|
|
Named(NamedColor),
|
|
|
|
Spec(Rgb),
|
|
|
|
Indexed(u8),
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/// Terminal character attributes
|
|
|
|
#[derive(Debug, Eq, PartialEq)]
|
|
|
|
pub enum Attr {
|
|
|
|
/// Clear all special abilities
|
|
|
|
Reset,
|
|
|
|
/// Bold text
|
|
|
|
Bold,
|
|
|
|
/// Dim or secondary color
|
|
|
|
Dim,
|
|
|
|
/// Italic text
|
|
|
|
Italic,
|
2019-11-03 20:59:28 +00:00
|
|
|
/// Underline text
|
|
|
|
Underline,
|
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
|
|
|
/// Blink cursor slowly
|
|
|
|
BlinkSlow,
|
|
|
|
/// Blink cursor fast
|
|
|
|
BlinkFast,
|
|
|
|
/// Invert colors
|
|
|
|
Reverse,
|
|
|
|
/// Do not display characters
|
|
|
|
Hidden,
|
2018-12-22 17:16:54 +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,
|
2017-07-20 17:54:40 +00:00
|
|
|
/// Cancel bold
|
|
|
|
CancelBold,
|
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
|
|
|
/// Cancel bold and dim
|
|
|
|
CancelBoldDim,
|
|
|
|
/// Cancel italic
|
|
|
|
CancelItalic,
|
|
|
|
/// Cancel underline
|
|
|
|
CancelUnderline,
|
|
|
|
/// Cancel blink
|
|
|
|
CancelBlink,
|
|
|
|
/// Cancel inversion
|
|
|
|
CancelReverse,
|
|
|
|
/// Cancel text hiding
|
|
|
|
CancelHidden,
|
2018-12-22 17:16:54 +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,
|
|
|
|
/// Set indexed foreground color
|
|
|
|
Foreground(Color),
|
|
|
|
/// Set indexed background color
|
|
|
|
Background(Color),
|
|
|
|
}
|
|
|
|
|
2017-01-09 20:07:23 +00:00
|
|
|
/// Identifiers which can be assigned to a graphic character set
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
|
|
pub enum CharsetIndex {
|
|
|
|
/// Default set, is designated as ASCII at startup
|
|
|
|
G0,
|
|
|
|
G1,
|
|
|
|
G2,
|
|
|
|
G3,
|
|
|
|
}
|
|
|
|
|
2017-02-01 17:55:23 +00:00
|
|
|
impl Default for CharsetIndex {
|
|
|
|
fn default() -> Self {
|
|
|
|
CharsetIndex::G0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-09 20:07:23 +00:00
|
|
|
/// Standard or common character sets which can be designated as G0-G3
|
|
|
|
#[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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-04 23:48:30 +00:00
|
|
|
impl<'a, H, W> vte::Perform for Performer<'a, H, W>
|
2019-03-30 16:48:36 +00:00
|
|
|
where
|
|
|
|
H: Handler + TermInfo + 'a,
|
|
|
|
W: io::Write + '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]
|
2020-01-12 16:28:40 +00:00
|
|
|
fn hook(&mut self, params: &[i64], intermediates: &[u8], ignore: bool, _c: char) {
|
2019-03-30 16:48:36 +00:00
|
|
|
debug!(
|
|
|
|
"[unhandled hook] params={:?}, ints: {:?}, ignore: {:?}",
|
|
|
|
params, intermediates, ignore
|
|
|
|
);
|
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) {
|
2017-01-13 07:15:06 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-02-06 21:28:33 +00:00
|
|
|
// TODO replace OSC parsing with parser combinators
|
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) {
|
2019-06-02 13:16:38 +00:00
|
|
|
let writer = &mut self.writer;
|
2020-01-31 00:00:23 +00:00
|
|
|
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 {
|
|
|
|
buf.push_str("[");
|
|
|
|
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] {
|
2017-02-06 21:28:33 +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>>()
|
|
|
|
.join(";");
|
|
|
|
self.handler.set_title(&title);
|
|
|
|
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
|
|
|
|
2017-03-03 23:04:09 +00:00
|
|
|
// Set icon name
|
|
|
|
// This is ignored, since alacritty has no concept of tabs
|
2019-08-15 23:13:10 +00:00
|
|
|
b"1" => (),
|
2017-03-03 23:04:09 +00:00
|
|
|
|
2017-02-06 21:28:33 +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
|
|
|
|
2019-06-09 18:02:15 +00:00
|
|
|
// Get/set Foreground, Background, Cursor colors
|
|
|
|
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..] {
|
|
|
|
// 10 is the first dynamic color, also the foreground
|
|
|
|
let offset = dynamic_code as usize - 10;
|
|
|
|
let index = NamedColor::Foreground as usize + offset;
|
|
|
|
|
|
|
|
// End of setting dynamic colors
|
|
|
|
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(
|
|
|
|
writer,
|
|
|
|
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
|
|
|
|
2018-07-15 16:02:44 +00:00
|
|
|
// Set cursor style
|
|
|
|
b"50" => {
|
2019-03-30 16:48:36 +00:00
|
|
|
if params.len() >= 2
|
|
|
|
&& params[1].len() >= 13
|
|
|
|
&& params[1][0..12] == *b"CursorShape="
|
|
|
|
{
|
2018-07-15 16:02:44 +00:00
|
|
|
let style = match params[1][12] as char {
|
|
|
|
'0' => CursorStyle::Block,
|
|
|
|
'1' => CursorStyle::Beam,
|
|
|
|
'2' => CursorStyle::Underline,
|
|
|
|
_ => return unhandled(params),
|
|
|
|
};
|
|
|
|
self.handler.set_cursor_style(Some(style));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
unhandled(params);
|
2019-03-30 16:48:36 +00:00
|
|
|
},
|
2018-07-15 16:02:44 +00:00
|
|
|
|
2018-01-02 16:32:50 +00:00
|
|
|
// Set clipboard
|
|
|
|
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-01-31 00:00:23 +00:00
|
|
|
b"?" => self.handler.write_clipboard(*clipboard, writer, terminator),
|
2019-11-28 07:08:04 +00:00
|
|
|
base64 => self.handler.set_clipboard(*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
|
|
|
|
2017-11-12 03:11:21 +00:00
|
|
|
// Reset color index
|
|
|
|
b"104" => {
|
|
|
|
// Reset all color indexes when no parameters are given
|
|
|
|
if params.len() == 1 {
|
|
|
|
for i in 0..256 {
|
|
|
|
self.handler.reset_color(i);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset color indexes given as parameters
|
|
|
|
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
|
|
|
|
2017-07-28 22:14:18 +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
|
|
|
|
|
|
|
// 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
|
|
|
|
2017-11-12 03:11:21 +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,
|
|
|
|
args: &[i64],
|
|
|
|
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!(
|
|
|
|
"[Unhandled CSI] action={:?}, args={:?}, intermediates={:?}",
|
|
|
|
action, args, intermediates
|
|
|
|
);
|
|
|
|
}};
|
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
|
|
|
macro_rules! arg_or_default {
|
2016-09-18 18:17:44 +00:00
|
|
|
(idx: $idx:expr, default: $default:expr) => {
|
2019-03-30 16:48:36 +00:00
|
|
|
args.get($idx)
|
|
|
|
.and_then(|v| if *v == 0 { None } else { Some(*v) })
|
|
|
|
.unwrap_or($default)
|
|
|
|
};
|
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
|
|
|
}
|
|
|
|
|
|
|
|
let handler = &mut self.handler;
|
|
|
|
let writer = &mut self.writer;
|
|
|
|
|
|
|
|
match (action, intermediates.get(0)) {
|
2019-08-08 21:30:10 +00:00
|
|
|
('@', None) => {
|
|
|
|
handler.insert_blank(Column(arg_or_default!(idx: 0, default: 1) as usize))
|
|
|
|
},
|
2019-08-06 22:59:16 +00:00
|
|
|
('A', None) => {
|
2016-09-18 18:17:44 +00:00
|
|
|
handler.move_up(Line(arg_or_default!(idx: 0, default: 1) as usize));
|
2016-05-31 03:44:37 +00:00
|
|
|
},
|
2019-08-06 22:59:16 +00:00
|
|
|
('b', None) => {
|
2019-10-05 00:29:26 +00:00
|
|
|
if let Some(c) = self.state.preceding_char {
|
2017-09-29 12:05:19 +00:00
|
|
|
for _ in 0..arg_or_default!(idx: 0, default: 1) {
|
|
|
|
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
|
|
|
}
|
|
|
|
},
|
2019-08-08 21:30:10 +00:00
|
|
|
('B', None) | ('e', None) => {
|
|
|
|
handler.move_down(Line(arg_or_default!(idx: 0, default: 1) as usize))
|
|
|
|
},
|
2019-11-17 02:10:11 +00:00
|
|
|
('c', None) if arg_or_default!(idx: 0, default: 0) == 0 => {
|
|
|
|
handler.identify_terminal(writer)
|
|
|
|
},
|
2019-08-08 21:30:10 +00:00
|
|
|
('C', None) | ('a', None) => {
|
|
|
|
handler.move_forward(Column(arg_or_default!(idx: 0, default: 1) as usize))
|
|
|
|
},
|
|
|
|
('D', None) => {
|
|
|
|
handler.move_backward(Column(arg_or_default!(idx: 0, default: 1) as usize))
|
|
|
|
},
|
|
|
|
('E', None) => {
|
|
|
|
handler.move_down_and_cr(Line(arg_or_default!(idx: 0, default: 1) as usize))
|
|
|
|
},
|
|
|
|
('F', None) => {
|
|
|
|
handler.move_up_and_cr(Line(arg_or_default!(idx: 0, default: 1) as usize))
|
|
|
|
},
|
2019-08-06 22:59:16 +00:00
|
|
|
('g', None) => {
|
2016-09-18 18:17:44 +00:00
|
|
|
let mode = match arg_or_default!(idx: 0, default: 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
|
|
|
},
|
2019-08-08 21:30:10 +00:00
|
|
|
('G', None) | ('`', None) => {
|
|
|
|
handler.goto_col(Column(arg_or_default!(idx: 0, default: 1) as usize - 1))
|
|
|
|
},
|
2019-08-06 22:59:16 +00:00
|
|
|
('H', None) | ('f', None) => {
|
2016-09-18 18:17:44 +00:00
|
|
|
let y = arg_or_default!(idx: 0, default: 1) as usize;
|
|
|
|
let x = arg_or_default!(idx: 1, default: 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
|
|
|
},
|
2019-08-06 22:59:16 +00:00
|
|
|
('I', None) => handler.move_forward_tabs(arg_or_default!(idx: 0, default: 1)),
|
|
|
|
('J', None) => {
|
2016-09-18 18:17:44 +00:00
|
|
|
let mode = match arg_or_default!(idx: 0, default: 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
|
|
|
},
|
2019-08-06 22:59:16 +00:00
|
|
|
('K', None) => {
|
2016-09-18 18:17:44 +00:00
|
|
|
let mode = match arg_or_default!(idx: 0, default: 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
|
|
|
},
|
2019-08-06 22:59:16 +00:00
|
|
|
('S', None) => handler.scroll_up(Line(arg_or_default!(idx: 0, default: 1) as usize)),
|
2019-10-14 17:50:58 +00:00
|
|
|
('t', None) => match arg_or_default!(idx: 0, default: 1) as usize {
|
|
|
|
22 => handler.push_title(),
|
|
|
|
23 => handler.pop_title(),
|
|
|
|
_ => unhandled!(),
|
|
|
|
},
|
2019-08-06 22:59:16 +00:00
|
|
|
('T', None) => handler.scroll_down(Line(arg_or_default!(idx: 0, default: 1) as usize)),
|
2019-08-08 21:30:10 +00:00
|
|
|
('L', None) => {
|
|
|
|
handler.insert_blank_lines(Line(arg_or_default!(idx: 0, default: 1) as usize))
|
|
|
|
},
|
2019-08-06 22:59:16 +00:00
|
|
|
('l', intermediate) => {
|
2018-03-08 21:50:04 +00:00
|
|
|
for arg in args {
|
2019-10-14 17:50:58 +00:00
|
|
|
match Mode::from_primitive(intermediate, *arg) {
|
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
|
|
|
},
|
2019-08-06 22:59:16 +00:00
|
|
|
('M', None) => handler.delete_lines(Line(arg_or_default!(idx: 0, default: 1) as usize)),
|
2019-08-08 21:30:10 +00:00
|
|
|
('X', None) => {
|
|
|
|
handler.erase_chars(Column(arg_or_default!(idx: 0, default: 1) as usize))
|
|
|
|
},
|
|
|
|
('P', None) => {
|
|
|
|
handler.delete_chars(Column(arg_or_default!(idx: 0, default: 1) as usize))
|
|
|
|
},
|
2019-08-06 22:59:16 +00:00
|
|
|
('Z', None) => handler.move_backward_tabs(arg_or_default!(idx: 0, default: 1)),
|
2019-08-08 21:30:10 +00:00
|
|
|
('d', None) => {
|
|
|
|
handler.goto_line(Line(arg_or_default!(idx: 0, default: 1) as usize - 1))
|
|
|
|
},
|
2019-08-06 22:59:16 +00:00
|
|
|
('h', intermediate) => {
|
2018-03-08 21:50:04 +00:00
|
|
|
for arg in args {
|
2019-10-14 17:50:58 +00:00
|
|
|
match Mode::from_primitive(intermediate, *arg) {
|
2018-03-08 21:50:04 +00:00
|
|
|
Some(mode) => handler.set_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
|
|
|
},
|
2019-08-06 22:59:16 +00:00
|
|
|
('m', None) => {
|
2017-09-28 00:29:44 +00:00
|
|
|
if args.is_empty() {
|
2016-09-18 18:17:44 +00:00
|
|
|
handler.terminal_attribute(Attr::Reset);
|
2019-08-06 22:59:16 +00:00
|
|
|
} else {
|
|
|
|
for attr in attrs_from_sgr_parameters(args) {
|
|
|
|
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
|
|
|
},
|
2019-08-08 21:30:10 +00:00
|
|
|
('n', None) => {
|
|
|
|
handler.device_status(writer, arg_or_default!(idx: 0, default: 0) as usize)
|
|
|
|
},
|
2019-08-06 22:59:16 +00:00
|
|
|
('q', Some(b' ')) => {
|
|
|
|
// DECSCUSR (CSI Ps SP q) -- Set Cursor Style
|
|
|
|
let style = match arg_or_default!(idx: 0, default: 0) {
|
|
|
|
0 => None,
|
|
|
|
1 | 2 => Some(CursorStyle::Block),
|
|
|
|
3 | 4 => Some(CursorStyle::Underline),
|
|
|
|
5 | 6 => Some(CursorStyle::Beam),
|
2019-08-15 23:13:10 +00:00
|
|
|
_ => {
|
|
|
|
unhandled!();
|
|
|
|
return;
|
|
|
|
},
|
2019-08-06 22:59:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
handler.set_cursor_style(style);
|
|
|
|
},
|
|
|
|
('r', None) => {
|
2019-09-26 12:44:59 +00:00
|
|
|
let top = arg_or_default!(idx: 0, default: 1) as usize;
|
|
|
|
let bottom = arg_or_default!(idx: 1, default: handler.lines().0 as _) as usize;
|
|
|
|
|
|
|
|
handler.set_scrolling_region(top, bottom);
|
2016-06-08 17:39:49 +00:00
|
|
|
},
|
2019-08-06 22:59:16 +00:00
|
|
|
('s', None) => handler.save_cursor_position(),
|
|
|
|
('u', None) => handler.restore_cursor_position(),
|
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 {
|
2019-11-17 02:10:11 +00:00
|
|
|
($charset:path, $intermediate:expr) => {{
|
|
|
|
let index: CharsetIndex = match $intermediate {
|
2017-01-09 20:07:23 +00:00
|
|
|
Some(b'(') => CharsetIndex::G0,
|
|
|
|
Some(b')') => CharsetIndex::G1,
|
|
|
|
Some(b'*') => CharsetIndex::G2,
|
|
|
|
Some(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
|
|
|
}
|
|
|
|
|
2019-11-17 02:10:11 +00:00
|
|
|
match (byte, intermediates.get(0)) {
|
|
|
|
(b'B', intermediate) => configure_charset!(StandardCharset::Ascii, intermediate),
|
|
|
|
(b'D', None) => self.handler.linefeed(),
|
|
|
|
(b'E', None) => {
|
2017-04-18 17:42:29 +00:00
|
|
|
self.handler.linefeed();
|
|
|
|
self.handler.carriage_return();
|
2019-03-30 16:48:36 +00:00
|
|
|
},
|
2019-11-17 02:10:11 +00:00
|
|
|
(b'H', None) => self.handler.set_horizontal_tabstop(),
|
|
|
|
(b'M', None) => self.handler.reverse_index(),
|
|
|
|
(b'Z', None) => self.handler.identify_terminal(self.writer),
|
|
|
|
(b'c', None) => self.handler.reset_state(),
|
|
|
|
(b'0', intermediate) => {
|
|
|
|
configure_charset!(StandardCharset::SpecialCharacterAndLineDrawing, intermediate)
|
2019-03-30 16:48:36 +00:00
|
|
|
},
|
2019-11-17 02:10:11 +00:00
|
|
|
(b'7', None) => self.handler.save_cursor_position(),
|
|
|
|
(b'8', Some(b'#')) => self.handler.decaln(),
|
|
|
|
(b'8', None) => self.handler.restore_cursor_position(),
|
|
|
|
(b'=', None) => self.handler.set_keypad_application_mode(),
|
|
|
|
(b'>', None) => self.handler.unset_keypad_application_mode(),
|
|
|
|
// String terminator, do nothing (parser handles as string terminator)
|
|
|
|
(b'\\', None) => (),
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-06 22:59:16 +00:00
|
|
|
fn attrs_from_sgr_parameters(parameters: &[i64]) -> Vec<Option<Attr>> {
|
|
|
|
// Sometimes a C-style for loop is just what you need
|
|
|
|
let mut i = 0; // C-for initializer
|
|
|
|
let mut attrs = Vec::with_capacity(parameters.len());
|
|
|
|
loop {
|
|
|
|
if i >= parameters.len() {
|
|
|
|
// C-for condition
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
let attr = match parameters[i] {
|
|
|
|
0 => Some(Attr::Reset),
|
|
|
|
1 => Some(Attr::Bold),
|
|
|
|
2 => Some(Attr::Dim),
|
|
|
|
3 => Some(Attr::Italic),
|
2019-11-03 20:59:28 +00:00
|
|
|
4 => Some(Attr::Underline),
|
2019-08-06 22:59:16 +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 start = 0;
|
2019-08-19 19:56:27 +00:00
|
|
|
if let Some(color) = parse_sgr_color(¶meters[i..], &mut start) {
|
2019-08-06 22:59:16 +00:00
|
|
|
i += start;
|
|
|
|
Some(Attr::Foreground(color))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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 start = 0;
|
2019-08-19 19:56:27 +00:00
|
|
|
if let Some(color) = parse_sgr_color(¶meters[i..], &mut start) {
|
2019-08-06 22:59:16 +00:00
|
|
|
i += start;
|
|
|
|
Some(Attr::Background(color))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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))),
|
|
|
|
_ => None,
|
|
|
|
};
|
|
|
|
|
|
|
|
attrs.push(attr);
|
|
|
|
|
|
|
|
i += 1; // C-for expr
|
|
|
|
}
|
|
|
|
attrs
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/// Parse a color specifier from list of attributes
|
2019-08-19 19:56:27 +00:00
|
|
|
fn parse_sgr_color(attrs: &[i64], i: &mut usize) -> Option<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
|
|
|
if attrs.len() < 2 {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2019-03-30 16:48:36 +00:00
|
|
|
match attrs[*i + 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
|
|
|
2 => {
|
|
|
|
// RGB color spec
|
|
|
|
if attrs.len() < 5 {
|
2018-11-18 13:48:10 +00:00
|
|
|
debug!("Expected RGB color spec; got {:?}", attrs);
|
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
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2019-03-30 16:48:36 +00:00
|
|
|
let r = attrs[*i + 2];
|
|
|
|
let g = attrs[*i + 3];
|
|
|
|
let b = attrs[*i + 4];
|
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:13:51 +00:00
|
|
|
*i += 4;
|
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-07 00:26:31 +00:00
|
|
|
let range = 0..256;
|
2019-11-03 20:59:28 +00:00
|
|
|
if !range.contains(&r) || !range.contains(&g) || !range.contains(&b) {
|
2018-11-18 13:48:10 +00:00
|
|
|
debug!("Invalid RGB color spec: ({}, {}, {})", r, g, b);
|
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
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2019-03-30 16:48:36 +00:00
|
|
|
Some(Color::Spec(Rgb { r: r as u8, g: g as u8, b: b as u8 }))
|
2016-12-04 19:14:27 +00:00
|
|
|
},
|
|
|
|
5 => {
|
|
|
|
if attrs.len() < 3 {
|
2018-11-18 13:48:10 +00:00
|
|
|
debug!("Expected color index; got {:?}", attrs);
|
2016-12-04 19:14:27 +00:00
|
|
|
None
|
|
|
|
} else {
|
2016-12-17 06:13:51 +00:00
|
|
|
*i += 2;
|
2016-12-04 19:14:27 +00:00
|
|
|
let idx = attrs[*i];
|
|
|
|
match idx {
|
2019-03-30 16:48:36 +00:00
|
|
|
0..=255 => Some(Color::Indexed(idx as u8)),
|
2016-12-04 19:14:27 +00:00
|
|
|
_ => {
|
2018-11-18 13:48:10 +00:00
|
|
|
debug!("Invalid color index: {}", idx);
|
2016-12-04 19:14:27 +00:00
|
|
|
None
|
2019-03-30 16:48:36 +00:00
|
|
|
},
|
2016-12-04 19:14:27 +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
|
|
|
debug!("Unexpected color attr: {}", attrs[*i + 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
|
|
|
None
|
2019-03-30 16:48:36 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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 {
|
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
|
|
|
/// Null filler, terminal should ignore this character
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const NUL: u8 = 0x00;
|
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
|
|
|
/// Start of Header
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const SOH: u8 = 0x01;
|
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
|
|
|
/// Start of Text, implied end of header
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const STX: u8 = 0x02;
|
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
|
|
|
/// 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;
|
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
|
|
|
/// End of Transmission
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const EOT: u8 = 0x04;
|
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
|
|
|
/// Enquiry, causes terminal to send ANSWER-BACK ID
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const ENQ: u8 = 0x05;
|
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
|
|
|
/// Acknowledge, usually sent by terminal in response to ETX
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const ACK: u8 = 0x06;
|
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
|
|
|
/// Bell, triggers the bell, buzzer, or beeper on the terminal
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const BEL: u8 = 0x07;
|
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
|
|
|
/// Backspace, can be used to define overstruck characters
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const BS: u8 = 0x08;
|
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
|
|
|
/// Horizontal Tabulation, move to next predetermined position
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const HT: u8 = 0x09;
|
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
|
|
|
/// Linefeed, move to same position on next line (see also NL)
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const LF: u8 = 0x0A;
|
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
|
|
|
/// Vertical Tabulation, move to next predetermined line
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const VT: u8 = 0x0B;
|
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
|
|
|
/// Form Feed, move to next form or page
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const FF: u8 = 0x0C;
|
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
|
|
|
/// Carriage Return, move to first character of current line
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const CR: u8 = 0x0D;
|
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
|
|
|
/// Shift Out, switch to G1 (other half of character set)
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const SO: u8 = 0x0E;
|
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
|
|
|
/// Shift In, switch to G0 (normal half of character set)
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const SI: u8 = 0x0F;
|
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
|
|
|
/// Data Link Escape, interpret next control character specially
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const DLE: u8 = 0x10;
|
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
|
|
|
/// (DC1) Terminal is allowed to resume transmitting
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const XON: u8 = 0x11;
|
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
|
|
|
/// Device Control 2, causes ASR-33 to activate paper-tape reader
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const DC2: u8 = 0x12;
|
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
|
|
|
/// (DC2) Terminal must pause and refrain from transmitting
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const XOFF: u8 = 0x13;
|
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
|
|
|
/// Device Control 4, causes ASR-33 to deactivate paper-tape reader
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const DC4: u8 = 0x14;
|
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
|
|
|
/// Negative Acknowledge, used sometimes with ETX and ACK
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const NAK: u8 = 0x15;
|
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
|
|
|
/// Synchronous Idle, used to maintain timing in Sync communication
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const SYN: u8 = 0x16;
|
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
|
|
|
/// End of Transmission block
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const ETB: u8 = 0x17;
|
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
|
|
|
/// Cancel (makes VT100 abort current escape sequence if any)
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const CAN: u8 = 0x18;
|
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
|
|
|
/// End of Medium
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const EM: u8 = 0x19;
|
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
|
|
|
/// Substitute (VT100 uses this to display parity errors)
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const SUB: u8 = 0x1A;
|
2016-12-17 06:13:51 +00:00
|
|
|
/// Prefix to an escape sequence
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const ESC: u8 = 0x1B;
|
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
|
|
|
/// File Separator
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const FS: u8 = 0x1C;
|
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
|
|
|
/// Group Separator
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const GS: u8 = 0x1D;
|
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
|
|
|
/// Record Separator (sent by VT132 in block-transfer mode)
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const RS: u8 = 0x1E;
|
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
|
|
|
/// Unit Separator
|
2016-09-18 18:17:44 +00:00
|
|
|
pub const US: u8 = 0x1F;
|
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
|
|
|
/// 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
|
|
|
}
|
|
|
|
|
2016-07-30 01:01:10 +00:00
|
|
|
// Tests for parsing escape sequences
|
|
|
|
//
|
|
|
|
// 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 {
|
2019-03-30 16:48:36 +00:00
|
|
|
use super::{
|
2019-08-24 23:18:51 +00:00
|
|
|
parse_number, xparse_color, Attr, CharsetIndex, Color, Handler, Processor, StandardCharset,
|
|
|
|
TermInfo,
|
2019-03-30 16:48:36 +00:00
|
|
|
};
|
|
|
|
use crate::index::{Column, Line};
|
2019-02-07 22:36:45 +00:00
|
|
|
use crate::term::color::Rgb;
|
2019-03-30 16:48:36 +00:00
|
|
|
use std::io;
|
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
|
|
|
|
2019-11-17 02:10:11 +00:00
|
|
|
fn identify_terminal<W: io::Write>(&mut self, _: &mut W) {
|
|
|
|
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 TermInfo for MockHandler {
|
2016-07-04 04:12:43 +00:00
|
|
|
fn lines(&self) -> Line {
|
2019-11-17 02:10:11 +00:00
|
|
|
Line(200)
|
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-07-04 04:12:43 +00:00
|
|
|
fn cols(&self) -> Column {
|
2019-11-17 02:10:11 +00:00
|
|
|
Column(90)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-09-18 18:17:44 +00:00
|
|
|
for byte in &BYTES[..] {
|
2019-11-17 02:10:11 +00:00
|
|
|
parser.advance(&mut handler, *byte, &mut io::sink());
|
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
|
|
|
|
2019-11-17 02:10:11 +00:00
|
|
|
for byte in &bytes[..] {
|
|
|
|
parser.advance(&mut handler, *byte, &mut io::sink());
|
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'];
|
|
|
|
|
|
|
|
for byte in &bytes[..] {
|
|
|
|
parser.advance(&mut handler, *byte, &mut io::sink());
|
|
|
|
}
|
|
|
|
|
|
|
|
assert!(handler.identity_reported);
|
|
|
|
handler.reset_state();
|
|
|
|
|
|
|
|
let bytes: &[u8] = &[0x1b, b'[', b'0', b'c'];
|
|
|
|
|
|
|
|
for byte in &bytes[..] {
|
|
|
|
parser.advance(&mut handler, *byte, &mut io::sink());
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-11-17 02:10:11 +00:00
|
|
|
for byte in &bytes[..] {
|
|
|
|
parser.advance(&mut handler, *byte, &mut io::sink());
|
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
|
|
|
|
2019-11-17 02:10:11 +00:00
|
|
|
for byte in &bytes[..] {
|
|
|
|
parser.advance(&mut handler, *byte, &mut io::sink());
|
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();
|
|
|
|
|
|
|
|
for byte in &BYTES[..] {
|
|
|
|
parser.advance(&mut handler, *byte, &mut io::sink());
|
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
|
|
|
}
|
|
|
|
|
2019-11-17 02:10:11 +00:00
|
|
|
/// No exactly a test; useful for debugging
|
|
|
|
#[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();
|
|
|
|
|
|
|
|
for byte in &BYTES[..] {
|
|
|
|
parser.advance(&mut handler, *byte, &mut io::sink());
|
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
|
|
|
|
|
|
|
for byte in &BYTES[..] {
|
2019-11-17 02:10:11 +00:00
|
|
|
parser.advance(&mut handler, *byte, &mut io::sink());
|
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] {
|
2019-11-17 02:10:11 +00:00
|
|
|
parser.advance(&mut handler, *byte, &mut io::sink());
|
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();
|
|
|
|
parser.advance(&mut handler, BYTES[3], &mut io::sink());
|
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
|
|
|
}
|