From b9ca8048148dea6720e1e30668c856575912a8f4 Mon Sep 17 00:00:00 2001 From: David Bittner Date: Sat, 27 Apr 2019 17:07:57 -0400 Subject: [PATCH] used wrong escape code, whoops... --- src/enums.rs | 5 ++++- src/enums/tests.rs | 14 ++++++++++++++ src/parsers.rs | 4 ++-- src/parsers/tests.rs | 2 +- 4 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 src/enums/tests.rs diff --git a/src/enums.rs b/src/enums.rs index e19fae2..744abd3 100644 --- a/src/enums.rs +++ b/src/enums.rs @@ -1,3 +1,6 @@ +#[cfg(test)] +mod tests; + use num_derive::FromPrimitive; use num_derive::ToPrimitive; @@ -63,7 +66,7 @@ pub enum AnsiSequence { use std::fmt::Display; impl Display for AnsiSequence { fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(formatter, "\x27[")?; + write!(formatter, "\x1b[")?; use AnsiSequence::*; match self { diff --git a/src/enums/tests.rs b/src/enums/tests.rs new file mode 100644 index 0000000..de7dc85 --- /dev/null +++ b/src/enums/tests.rs @@ -0,0 +1,14 @@ +use super::*; + +use std::fmt::Write; + +#[test] +fn test_cursor_pos() { + let pos = AnsiSequence::CursorPos(5, 20); + let mut buff = String::new(); + + write!(&mut buff, "{}", pos) + .expect("failed to write"); + + assert_eq!(buff, "\x1b[5;20H"); +} diff --git a/src/parsers.rs b/src/parsers.rs index 06be6c3..797c727 100644 --- a/src/parsers.rs +++ b/src/parsers.rs @@ -190,7 +190,7 @@ named!( named!( parse_escape, do_parse!( - tag_s!("\x27[") >> + tag_s!("\x1b[") >> seq: combined >> (Output::Escape(seq)) ) @@ -200,7 +200,7 @@ named!( parse_str, do_parse!( text: map_res!( - take_until!("\x27["), + take_until!("\x1b["), std::str::from_utf8 ) >> (Output::TextBlock(text)) diff --git a/src/parsers/tests.rs b/src/parsers/tests.rs index b0aae14..8b656af 100644 --- a/src/parsers/tests.rs +++ b/src/parsers/tests.rs @@ -33,7 +33,7 @@ fn test_reset_mode() { #[test] 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 \x1b[=7lyou? I hope you're doing well."; let strings: Vec = ParserIterator::new(parse_str) .collect();