aboutsummaryrefslogtreecommitdiff
path: root/examples/parselog.rs
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2020-08-05 00:36:41 +0000
committerGitHub <noreply@github.com>2020-08-05 00:36:41 +0000
commit4f44023dab081f7da74fee14bc53b10ee8f96a1e (patch)
tree4f85102557f2fd55b35cbec026dda172a8427907 /examples/parselog.rs
parent0310be12d3007e32be614c5df94653d29fcc1a8b (diff)
downloadr-alacritty-vte-4f44023dab081f7da74fee14bc53b10ee8f96a1e.tar.gz
r-alacritty-vte-4f44023dab081f7da74fee14bc53b10ee8f96a1e.tar.bz2
r-alacritty-vte-4f44023dab081f7da74fee14bc53b10ee8f96a1e.zip
Add CSI subparameter support
This adds support for CSI subparameters like `\x1b[38:2:255:0:255m`, which allows the combination of truecolor SGR commands together with other SGR parameters like bold text, without any ambiguity. This implements subparameters by storing them in a list together with all other parameters and having a separate slice to indicate which parameter is a subparameter and how long the subparameter list is. This allows for static memory allocation and good performance while still having the option for dynamic sizing of the parameters. Since the subparameters are now also counted as parameters, the number of allowed parameters has been increased from `16` to `32`. Since the existing structures combine the handling of parameters for CSI and DCS escape sequences, it is now also possible for DCS parameters to have subparameters, even though that is currently never used. Considering that DCS is rarely supported by terminal emulators, handling these separately would likely just cause unnecessary issues. The performance should also be better by using this existing subparam structure rather than having two separate structures for DCS and CSI parameters. The only API provided for accessing the list of parameters is using an iterator, this is intentional to make the internal structure clear and allow for easy optimizations downstream. Since it makes little sense to access parameters out of order, this limitation should not have any negative effects on performance. The main drawback is that direct access to the first parameter while ignoring all other subparameters is less efficient, since it requires indexing a slice after iterating to the element. However while this is often useful, it's mostly done for the first few parameters which significantly reduces the overhead to a negligible amount. At the same time this forces people to support subparameters or at least consider their existence, which should make it more difficult to implement things improperly downstream. Fixes #22.
Diffstat (limited to 'examples/parselog.rs')
-rw-r--r--examples/parselog.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/examples/parselog.rs b/examples/parselog.rs
index c310182..dfd0aee 100644
--- a/examples/parselog.rs
+++ b/examples/parselog.rs
@@ -1,12 +1,12 @@
//! Parse input from stdin and log actions on stdout
use std::io::{self, Read};
-use vte;
+use vte::{Params, Parser, Perform};
/// A type implementing Perform that just logs actions
struct Log;
-impl vte::Perform for Log {
+impl Perform for Log {
fn print(&mut self, c: char) {
println!("[print] {:?}", c);
}
@@ -15,7 +15,7 @@ impl vte::Perform for Log {
println!("[execute] {:02x}", byte);
}
- fn hook(&mut self, params: &[i64], intermediates: &[u8], ignore: bool, c: char) {
+ fn hook(&mut self, params: &Params, intermediates: &[u8], ignore: bool, c: char) {
println!(
"[hook] params={:?}, intermediates={:?}, ignore={:?}, char={:?}",
params, intermediates, ignore, c
@@ -34,9 +34,9 @@ impl vte::Perform for Log {
println!("[osc_dispatch] params={:?} bell_terminated={}", params, bell_terminated);
}
- fn csi_dispatch(&mut self, params: &[i64], intermediates: &[u8], ignore: bool, c: char) {
+ fn csi_dispatch(&mut self, params: &Params, intermediates: &[u8], ignore: bool, c: char) {
println!(
- "[csi_dispatch] params={:?}, intermediates={:?}, ignore={:?}, char={:?}",
+ "[csi_dispatch] params={:#?}, intermediates={:?}, ignore={:?}, char={:?}",
params, intermediates, ignore, c
);
}
@@ -53,7 +53,7 @@ fn main() {
let input = io::stdin();
let mut handle = input.lock();
- let mut statemachine = vte::Parser::new();
+ let mut statemachine = Parser::new();
let mut performer = Log;
let mut buf = [0; 2048];