From 29eb11a1e1a7c9f132bd030d23281ea0121cbf93 Mon Sep 17 00:00:00 2001 From: David Bittner Date: Fri, 26 Apr 2019 22:12:39 -0400 Subject: [PATCH] adding docs, updating Cargo.toml --- Cargo.toml | 1 - src/enums.rs | 6 ++++++ src/lib.rs | 17 +++++++++++++++++ src/parsers.rs | 10 ++++++---- src/parsers/tests.rs | 4 ++-- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 36adeac..1f75242 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,6 @@ version = "0.1.0" authors = ["David Bittner "] edition = "2018" -license = "GPL-3.0+" license-file = "LICENSE" [dependencies] diff --git a/src/enums.rs b/src/enums.rs index aaeb6d9..70dbf1a 100644 --- a/src/enums.rs +++ b/src/enums.rs @@ -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), diff --git a/src/lib.rs b/src/lib.rs index 9dce930..55337d2 100644 --- a/src/lib.rs +++ b/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 +}; diff --git a/src/parsers.rs b/src/parsers.rs index 591957b..06be6c3 100644 --- a/src/parsers.rs +++ b/src/parsers.rs @@ -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 + } } } diff --git a/src/parsers/tests.rs b/src/parsers/tests.rs index eec8b40..b0aae14 100644 --- a/src/parsers/tests.rs +++ b/src/parsers/tests.rs @@ -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 = iterate_on(parse_str) + let strings: Vec = ParserIterator::new(parse_str) .collect(); - println!("{:#?}", strings); + assert_eq!(strings.len(), 3); }