kkawakam / rustyline

Readline Implementation in Rust
https://crates.io/crates/rustyline/
MIT License
1.53k stars 176 forks source link

Refactor highlighting #799

Closed zao111222333 closed 2 weeks ago

zao111222333 commented 3 weeks ago

See https://github.com/kkawakam/rustyline/pull/795

  1. Use ansi-str-fork to introduce

    fn get_blocks<'a>(text: Cow<'a, str>) -> AnsiBlockIter<'a>

    (see more at ansitok-fork)

  2. Fix highlight_line function signature into:

    fn highlight_line<'l>(&self, line: &'l str, pos: usize) -> impl Iterator<Item = impl 'l+StyledBlock>
  3. The new highlight_line function signature conflicts to the Option<&dyn Highligher> due to https://doc.rust-lang.org/reference/items/traits.html#object-safety . So use generic <H: Highligher> + Option<&H> to replace Option<&dyn Highligher>