Escaping the escape character
This commit is contained in:
@@ -4,6 +4,7 @@ mod tests;
|
|||||||
///The following are the implemented ANSI escape sequences. More to be added.
|
///The following are the implemented ANSI escape sequences. More to be added.
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum AnsiSequence {
|
pub enum AnsiSequence {
|
||||||
|
Escape,
|
||||||
CursorPos(u32, u32),
|
CursorPos(u32, u32),
|
||||||
CursorUp(u32),
|
CursorUp(u32),
|
||||||
CursorDown(u32),
|
CursorDown(u32),
|
||||||
@@ -61,6 +62,7 @@ impl Display for AnsiSequence {
|
|||||||
|
|
||||||
use AnsiSequence::*;
|
use AnsiSequence::*;
|
||||||
match self {
|
match self {
|
||||||
|
Escape => write!(formatter, "\u{1b}"),
|
||||||
CursorPos(line, col)
|
CursorPos(line, col)
|
||||||
=> write!(formatter, "[{};{}H", line, col),
|
=> write!(formatter, "[{};{}H", line, col),
|
||||||
CursorUp(amt)
|
CursorUp(amt)
|
||||||
|
@@ -51,6 +51,14 @@ named!(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
named!(
|
||||||
|
escape<&str, AnsiSequence>,
|
||||||
|
do_parse!(
|
||||||
|
tag!("\u{1b}") >>
|
||||||
|
(AnsiSequence::Escape)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
named!(
|
named!(
|
||||||
cursor_up<&str, AnsiSequence>,
|
cursor_up<&str, AnsiSequence>,
|
||||||
do_parse!(
|
do_parse!(
|
||||||
@@ -244,7 +252,8 @@ tag_parser!(set_single_shift3, "O", AnsiSequence::SetSingleShift3);
|
|||||||
named!(
|
named!(
|
||||||
combined<&str, AnsiSequence>,
|
combined<&str, AnsiSequence>,
|
||||||
alt!(
|
alt!(
|
||||||
cursor_pos
|
escape
|
||||||
|
| cursor_pos
|
||||||
| cursor_up
|
| cursor_up
|
||||||
| cursor_down
|
| cursor_down
|
||||||
| cursor_forward
|
| cursor_forward
|
||||||
|
@@ -133,3 +133,15 @@ fn test_default_value() {
|
|||||||
assert_eq!(strings[3], Output::TextBlock("\x1b[7asd;1234H"));
|
assert_eq!(strings[3], Output::TextBlock("\x1b[7asd;1234H"));
|
||||||
assert_eq!(strings[4], Output::TextBlock("\x1b[a;sd7H"));
|
assert_eq!(strings[4], Output::TextBlock("\x1b[a;sd7H"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_escape() {
|
||||||
|
let parts: Vec<_> = "\x1b\x1b[33mFoobar".ansi_parse().collect();
|
||||||
|
assert_eq!(
|
||||||
|
parts,
|
||||||
|
vec![
|
||||||
|
Output::Escape(AnsiSequence::Escape),
|
||||||
|
Output::TextBlock("[33mFoobar")
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user