mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-11 13:51:01 -05: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.
This commit is contained in:
parent
493a7fae7c
commit
70b0423a31
4 changed files with 1128 additions and 8 deletions
1103
src/ansi.rs
Normal file
1103
src/ansi.rs
Normal file
File diff suppressed because it is too large
Load diff
16
src/macros.rs
Normal file
16
src/macros.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
#[macro_export]
|
||||
macro_rules! die {
|
||||
($($arg:tt)*) => {
|
||||
println!($($arg)*);
|
||||
::std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! err_println {
|
||||
($($arg:tt)*) => {
|
||||
if let Err(_) = writeln!(&mut ::std::io::stderr(), $($arg)*) {
|
||||
die!("Cannot reach stderr");
|
||||
}
|
||||
}
|
||||
}
|
10
src/main.rs
10
src/main.rs
|
@ -1,5 +1,8 @@
|
|||
//! Alacritty - The GPU Enhanced Terminal
|
||||
#![feature(question_mark)]
|
||||
#![feature(range_contains)]
|
||||
#![feature(inclusive_range_syntax)]
|
||||
#![feature(io)]
|
||||
|
||||
extern crate fontconfig;
|
||||
extern crate freetype;
|
||||
|
@ -12,12 +15,16 @@ use std::collections::HashMap;
|
|||
|
||||
use std::io::{BufReader, Read, BufRead};
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
mod list_fonts;
|
||||
mod text;
|
||||
mod renderer;
|
||||
mod grid;
|
||||
mod meter;
|
||||
mod tty;
|
||||
mod ansi;
|
||||
|
||||
use renderer::{Glyph, QuadRenderer};
|
||||
use text::FontDesc;
|
||||
|
@ -86,7 +93,8 @@ fn main() {
|
|||
|
||||
::std::thread::spawn(move || {
|
||||
for byte in cmd.bytes() {
|
||||
println!("{:?}", byte);
|
||||
let b = byte.unwrap();
|
||||
println!("{:02x}, {:?}", b, ::std::char::from_u32(b as u32));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -9,13 +9,6 @@ use std::ptr;
|
|||
|
||||
use libc::{self, winsize, c_int, c_char};
|
||||
|
||||
macro_rules! die {
|
||||
($($arg:tt)*) => {
|
||||
println!($($arg)*);
|
||||
::std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
pub enum Error {
|
||||
/// TODO
|
||||
Unknown,
|
||||
|
|
Loading…
Reference in a new issue