Skip to content

Commit

Permalink
Switch from vte to anstyle-parse (already used in dependencies) (#1638)
Browse files Browse the repository at this point in the history
delta already depends indirectly on anstyle-parse through clap. Switch
from vte to anstyle-parse to eliminate a few dependencies.
  • Loading branch information
joshtriplett committed Mar 2, 2024
1 parent 084a6d1 commit 037665b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 38 deletions.
33 changes: 3 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -20,6 +20,7 @@ chrono = "0.4.26"
chrono-humanize = "0.2.2"
ansi_colours = "1.2.1"
ansi_term = "0.12.1"
anstyle-parse = "0.2.3"
anyhow = "1.0.70"
bitflags = "2.2.1"
box_drawing = "0.1.2"
Expand All @@ -41,7 +42,6 @@ smol_str = "0.1.24"
syntect = "5.0.0"
unicode-segmentation = "1.10.1"
unicode-width = "0.1.10"
vte = "0.11.0"
xdg = "2.4.1"
clap_complete = "4.4.4"

Expand Down
14 changes: 7 additions & 7 deletions src/ansi/iterator.rs
@@ -1,14 +1,14 @@
use anstyle_parse::{Params, ParamsIter};
use core::str::Bytes;
use std::convert::TryFrom;
use std::iter;
use vte::{Params, ParamsIter};

pub struct AnsiElementIterator<'a> {
// The input bytes
bytes: Bytes<'a>,

// The state machine
machine: vte::Parser,
machine: anstyle_parse::Parser,

// Becomes non-None when the parser finishes parsing an ANSI sequence.
// This is never Element::Text.
Expand Down Expand Up @@ -61,7 +61,7 @@ impl Element {
impl<'a> AnsiElementIterator<'a> {
pub fn new(s: &'a str) -> Self {
Self {
machine: vte::Parser::new(),
machine: anstyle_parse::Parser::<anstyle_parse::DefaultCharAccumulator>::new(),
bytes: s.bytes(),
element: None,
text_length: 0,
Expand Down Expand Up @@ -120,13 +120,13 @@ impl<'a> Iterator for AnsiElementIterator<'a> {
}

// Based on https://github.com/alacritty/vte/blob/v0.9.0/examples/parselog.rs
impl vte::Perform for Performer {
fn csi_dispatch(&mut self, params: &Params, intermediates: &[u8], ignore: bool, c: char) {
impl anstyle_parse::Perform for Performer {
fn csi_dispatch(&mut self, params: &Params, intermediates: &[u8], ignore: bool, byte: u8) {
if ignore || intermediates.len() > 1 {
return;
}

let is_sgr = c == 'm' && intermediates.first().is_none();
let is_sgr = byte == b'm' && intermediates.first().is_none();
let element = if is_sgr {
if params.is_empty() {
// Attr::Reset
Expand Down Expand Up @@ -154,7 +154,7 @@ impl vte::Perform for Performer {
}
}

fn hook(&mut self, _params: &Params, _intermediates: &[u8], _ignore: bool, _c: char) {}
fn hook(&mut self, _params: &Params, _intermediates: &[u8], _ignore: bool, _byte: u8) {}

fn put(&mut self, _byte: u8) {}

Expand Down

0 comments on commit 037665b

Please sign in to comment.