adding docs, updating Cargo.toml
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use num_derive::FromPrimitive;
|
||||
|
||||
///A list of available text attributes.
|
||||
#[derive(Debug, PartialEq, FromPrimitive)]
|
||||
pub enum TextAttribute {
|
||||
Off = 0,
|
||||
@@ -10,6 +11,7 @@ pub enum TextAttribute {
|
||||
Concealed = 8
|
||||
}
|
||||
|
||||
///The basic ANSI colors.
|
||||
#[derive(Debug, PartialEq, FromPrimitive)]
|
||||
pub enum Color {
|
||||
Black = 30,
|
||||
@@ -22,6 +24,7 @@ pub enum Color {
|
||||
White = 37
|
||||
}
|
||||
|
||||
///The following are the implemented ANSI escape sequences. More to be added.
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum AnsiSequence {
|
||||
CursorPos(u32, u32),
|
||||
@@ -42,6 +45,9 @@ pub enum AnsiSequence {
|
||||
ResetMode(u8),
|
||||
}
|
||||
|
||||
///This is what is outputted by the parsing iterator.
|
||||
///Each block contains either straight-up text, or simply
|
||||
///an ANSI escape sequence.
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Output<'a> {
|
||||
TextBlock(&'a str),
|
||||
|
17
src/lib.rs
17
src/lib.rs
@@ -1,4 +1,21 @@
|
||||
mod enums;
|
||||
mod parsers;
|
||||
|
||||
///This is a library for parsing ANSI escape sequences. Currently all the basic escape sequences
|
||||
///are implemented:
|
||||
/// + Cursor Position
|
||||
/// + 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
|
||||
/// turns all of the ANSI sequences into enums and splits the string at every location that there
|
||||
/// was an ANSI Sequence.
|
||||
|
||||
pub use enums::*;
|
||||
pub use parsers::{
|
||||
ParserIterator
|
||||
};
|
||||
|
@@ -246,9 +246,11 @@ impl<'a> Iterator for ParserIterator<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn iterate_on<'a>(bytes: &'a str) -> ParserIterator<'a> {
|
||||
ParserIterator {
|
||||
dat: bytes.as_bytes(),
|
||||
done: false
|
||||
impl<'a> ParserIterator<'a> {
|
||||
pub fn new(string: &'a str) -> ParserIterator<'a> {
|
||||
ParserIterator {
|
||||
dat: string.as_bytes(),
|
||||
done: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -35,8 +35,8 @@ fn test_reset_mode() {
|
||||
fn test_parser_iterator() {
|
||||
let parse_str = "Hello, world? How are \x27[=7lyou? I hope you're doing well.";
|
||||
|
||||
let strings: Vec<Output> = iterate_on(parse_str)
|
||||
let strings: Vec<Output> = ParserIterator::new(parse_str)
|
||||
.collect();
|
||||
|
||||
println!("{:#?}", strings);
|
||||
assert_eq!(strings.len(), 3);
|
||||
}
|
||||
|
Reference in New Issue
Block a user