summaryrefslogtreecommitdiffstats
path: root/vendor/vte/examples/parselog.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:47:55 +0000
commit2aadc03ef15cb5ca5cc2af8a7c08e070742f0ac4 (patch)
tree033cc839730fda84ff08db877037977be94e5e3a /vendor/vte/examples/parselog.rs
parentInitial commit. (diff)
downloadcargo-2aadc03ef15cb5ca5cc2af8a7c08e070742f0ac4.tar.xz
cargo-2aadc03ef15cb5ca5cc2af8a7c08e070742f0ac4.zip
Adding upstream version 0.70.1+ds1.upstream/0.70.1+ds1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/vte/examples/parselog.rs')
-rw-r--r--vendor/vte/examples/parselog.rs75
1 files changed, 75 insertions, 0 deletions
diff --git a/vendor/vte/examples/parselog.rs b/vendor/vte/examples/parselog.rs
new file mode 100644
index 0000000..dfd0aee
--- /dev/null
+++ b/vendor/vte/examples/parselog.rs
@@ -0,0 +1,75 @@
+//! Parse input from stdin and log actions on stdout
+use std::io::{self, Read};
+
+use vte::{Params, Parser, Perform};
+
+/// A type implementing Perform that just logs actions
+struct Log;
+
+impl Perform for Log {
+ fn print(&mut self, c: char) {
+ println!("[print] {:?}", c);
+ }
+
+ fn execute(&mut self, byte: u8) {
+ println!("[execute] {:02x}", byte);
+ }
+
+ fn hook(&mut self, params: &Params, intermediates: &[u8], ignore: bool, c: char) {
+ println!(
+ "[hook] params={:?}, intermediates={:?}, ignore={:?}, char={:?}",
+ params, intermediates, ignore, c
+ );
+ }
+
+ fn put(&mut self, byte: u8) {
+ println!("[put] {:02x}", byte);
+ }
+
+ fn unhook(&mut self) {
+ println!("[unhook]");
+ }
+
+ fn osc_dispatch(&mut self, params: &[&[u8]], bell_terminated: bool) {
+ println!("[osc_dispatch] params={:?} bell_terminated={}", params, bell_terminated);
+ }
+
+ fn csi_dispatch(&mut self, params: &Params, intermediates: &[u8], ignore: bool, c: char) {
+ println!(
+ "[csi_dispatch] params={:#?}, intermediates={:?}, ignore={:?}, char={:?}",
+ params, intermediates, ignore, c
+ );
+ }
+
+ fn esc_dispatch(&mut self, intermediates: &[u8], ignore: bool, byte: u8) {
+ println!(
+ "[esc_dispatch] intermediates={:?}, ignore={:?}, byte={:02x}",
+ intermediates, ignore, byte
+ );
+ }
+}
+
+fn main() {
+ let input = io::stdin();
+ let mut handle = input.lock();
+
+ let mut statemachine = Parser::new();
+ let mut performer = Log;
+
+ let mut buf = [0; 2048];
+
+ loop {
+ match handle.read(&mut buf) {
+ Ok(0) => break,
+ Ok(n) => {
+ for byte in &buf[..n] {
+ statemachine.advance(&mut performer, *byte);
+ }
+ },
+ Err(err) => {
+ println!("err: {}", err);
+ break;
+ },
+ }
+ }
+}