adding docs, updating Cargo.toml

This commit is contained in:
David Bittner
2019-04-26 22:12:39 -04:00
parent 7bab969b69
commit 29eb11a1e1
5 changed files with 31 additions and 7 deletions

View File

@@ -6,7 +6,6 @@ version = "0.1.0"
authors = ["David Bittner <bittneradave@gmail.com>"] authors = ["David Bittner <bittneradave@gmail.com>"]
edition = "2018" edition = "2018"
license = "GPL-3.0+"
license-file = "LICENSE" license-file = "LICENSE"
[dependencies] [dependencies]

View File

@@ -1,5 +1,6 @@
use num_derive::FromPrimitive; use num_derive::FromPrimitive;
///A list of available text attributes.
#[derive(Debug, PartialEq, FromPrimitive)] #[derive(Debug, PartialEq, FromPrimitive)]
pub enum TextAttribute { pub enum TextAttribute {
Off = 0, Off = 0,
@@ -10,6 +11,7 @@ pub enum TextAttribute {
Concealed = 8 Concealed = 8
} }
///The basic ANSI colors.
#[derive(Debug, PartialEq, FromPrimitive)] #[derive(Debug, PartialEq, FromPrimitive)]
pub enum Color { pub enum Color {
Black = 30, Black = 30,
@@ -22,6 +24,7 @@ pub enum Color {
White = 37 White = 37
} }
///The following are the implemented ANSI escape sequences. More to be added.
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub enum AnsiSequence { pub enum AnsiSequence {
CursorPos(u32, u32), CursorPos(u32, u32),
@@ -42,6 +45,9 @@ pub enum AnsiSequence {
ResetMode(u8), 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)] #[derive(Debug, PartialEq)]
pub enum Output<'a> { pub enum Output<'a> {
TextBlock(&'a str), TextBlock(&'a str),

View File

@@ -1,4 +1,21 @@
mod enums; mod enums;
mod parsers; 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 enums::*;
pub use parsers::{
ParserIterator
};

View File

@@ -246,9 +246,11 @@ impl<'a> Iterator for ParserIterator<'a> {
} }
} }
pub fn iterate_on<'a>(bytes: &'a str) -> ParserIterator<'a> { impl<'a> ParserIterator<'a> {
ParserIterator { pub fn new(string: &'a str) -> ParserIterator<'a> {
dat: bytes.as_bytes(), ParserIterator {
done: false dat: string.as_bytes(),
done: false
}
} }
} }

View File

@@ -35,8 +35,8 @@ fn test_reset_mode() {
fn test_parser_iterator() { fn test_parser_iterator() {
let parse_str = "Hello, world? How are \x27[=7lyou? I hope you're doing well."; 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(); .collect();
println!("{:#?}", strings); assert_eq!(strings.len(), 3);
} }