updating readme example
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -2,7 +2,7 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ansi-parser"
|
name = "ansi-parser"
|
||||||
version = "0.6.0"
|
version = "0.6.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
59
README.md
59
README.md
@@ -1,40 +1,47 @@
|
|||||||
   
|

|
||||||
|
[](https://docs.rs/ansi-parser/)
|
||||||
|

|
||||||
|

|
||||||
|
]
|
||||||
|
|
||||||
# Ansi Escape Sequence Parser
|
# Ansi Escape Sequence Parser
|
||||||
|
|
||||||
|
For a complete list of implemented sequences, see the [documentation](https://docs.rs/ansi-parser).
|
||||||
|
|
||||||
This is a library for parsing ANSI escape sequences. Currently all the basic escape sequences
|
This is done through a pulldown type parser, where an iterator is exposed. This essentially
|
||||||
are implemented:
|
turns all of the ANSI sequences into enums and splits the string at every location that there
|
||||||
+ Cursor Position
|
was an ANSI Sequence.
|
||||||
+ Cursor {Up, Down, Forward, Backward}
|
|
||||||
+ Cursor {Save, Restore}
|
|
||||||
+ Erase Display
|
|
||||||
+ Erase Line
|
|
||||||
+ Set Graphics mode
|
|
||||||
+ Set and Reset Text Mode
|
|
||||||
|
|
||||||
This is done through a pulldown type parser, where an iterator is exposed. This essentially
|
Example:
|
||||||
turns all of the ANSI sequences into enums and splits the string at every location that there
|
|
||||||
was an ANSI Sequence.
|
|
||||||
|
|
||||||
Example:
|
```rust
|
||||||
|
use ansi_parser::{Output, AnsiParser};
|
||||||
```rust
|
use ansi_parser::AnsiSequence;
|
||||||
|
|
||||||
use ansi_parser::{Output, ParserIterator};
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
//Your input string here
|
//Parse the first two blocks in the list
|
||||||
let string = "...";
|
//By parsing it this way, it allows you to iterate over the
|
||||||
let parsed: Vec<Output> = ParserIterator::new(&string)
|
//elements returned.
|
||||||
//Because it implements Iterator, you can use whatever
|
//
|
||||||
//your favorite iterator functions are.
|
//The parser only every holds a reference to the data,
|
||||||
.take(4)
|
//so there is no allocation.
|
||||||
|
let parsed: Vec<Output> = "This is \u{1b}[3Asome text!"
|
||||||
|
.ansi_parse()
|
||||||
|
.take(2)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
vec![
|
||||||
|
Output::TextBlock("This is "),
|
||||||
|
Output::Escape(AnsiSequence::CursorUp(3))
|
||||||
|
],
|
||||||
|
parsed
|
||||||
|
);
|
||||||
|
|
||||||
for block in parsed.into_iter() {
|
for block in parsed.into_iter() {
|
||||||
match block {
|
match block {
|
||||||
TextBlock(text) => println!("{}", text),
|
Output::TextBlock(text) => println!("{}", text),
|
||||||
AnsiSequence(seq) => println!("{}", seq)
|
Output::Escape(seq) => println!("{}", seq)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user