adding new sequences from the VT100 list

This commit is contained in:
David Bittner
2019-05-04 11:24:58 -04:00
parent f51c7a1e95
commit 8c1408cefe
5 changed files with 73 additions and 52 deletions

2
Cargo.lock generated
View File

@@ -2,7 +2,7 @@
# It is not intended for manual editing. # It is not intended for manual editing.
[[package]] [[package]]
name = "ansi-parser" name = "ansi-parser"
version = "0.5.1" version = "0.5.2"
dependencies = [ dependencies = [
"nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
] ]

View File

@@ -4,7 +4,7 @@ description = "A library using nom for parsing ANSI Escape Codes"
homepage = "https://gitlab.com/DavidBittner/ansi-parser" homepage = "https://gitlab.com/DavidBittner/ansi-parser"
authors = ["David Bittner <bittneradave@gmail.com>"] authors = ["David Bittner <bittneradave@gmail.com>"]
version = "0.5.2" version = "0.5.3"
license = "MPL-2.0" license = "MPL-2.0"
edition = "2018" edition = "2018"

View File

@@ -17,7 +17,18 @@ pub enum AnsiSequence {
SetMode(u8), SetMode(u8),
ResetMode(u8), ResetMode(u8),
HideCursor, HideCursor,
ShowCursor ShowCursor,
CursorToApp,
SetNewLineMode,
SetCol132,
SetSmoothScroll,
SetReverseVideo,
SetOriginRelative,
SetAutoWrap,
SetAutoRepeat,
SetInterlacing,
SetLineFeedMode,
SetCursorKeyToCursor,
} }
use std::fmt::Display; use std::fmt::Display;
@@ -61,7 +72,29 @@ impl Display for AnsiSequence {
ShowCursor ShowCursor
=> write!(formatter, "?25h"), => write!(formatter, "?25h"),
HideCursor HideCursor
=> write!(formatter, "?25l") => write!(formatter, "?25l"),
CursorToApp
=> write!(formatter, "?1h"),
SetNewLineMode
=> write!(formatter, "20h"),
SetCol132
=> write!(formatter, "?3h"),
SetSmoothScroll
=> write!(formatter, "?4h"),
SetReverseVideo
=> write!(formatter, "?5h"),
SetOriginRelative
=> write!(formatter, "?6h"),
SetAutoWrap
=> write!(formatter, "?7h"),
SetAutoRepeat
=> write!(formatter, "?8h"),
SetInterlacing
=> write!(formatter, "?9h"),
SetLineFeedMode
=> write!(formatter, "20l"),
SetCursorKeyToCursor
=> write!(formatter, "?1l")
} }
} }
} }

View File

@@ -6,6 +6,18 @@ use crate::{AnsiSequence, Output};
use std::convert::TryInto; use std::convert::TryInto;
use nom::*; use nom::*;
macro_rules! tag_parser {
($sig:ident, $tag:expr, $ret:expr) => {
named!(
$sig<&str, AnsiSequence>,
do_parse!(
tag!($tag) >>
($ret)
)
);
}
}
named!( named!(
parse_int<&str, u32>, parse_int<&str, u32>,
map_res!( map_res!(
@@ -64,38 +76,6 @@ named!(
) )
); );
named!(
cursor_save<&str, AnsiSequence>,
do_parse!(
tag!("s") >>
(AnsiSequence::CursorSave)
)
);
named!(
cursor_restore<&str, AnsiSequence>,
do_parse!(
tag!("u") >>
(AnsiSequence::CursorRestore)
)
);
named!(
erase_display<&str, AnsiSequence>,
do_parse!(
tag!("2J") >>
(AnsiSequence::EraseDisplay)
)
);
named!(
erase_line<&str, AnsiSequence>,
do_parse!(
tag!("K") >>
(AnsiSequence::EraseDisplay)
)
);
named!( named!(
graphics_mode1<&str, AnsiSequence>, graphics_mode1<&str, AnsiSequence>,
do_parse!( do_parse!(
@@ -159,21 +139,21 @@ named!(
) )
); );
named!( tag_parser!(cursor_save, "s", AnsiSequence::CursorSave);
hide_cursor<&str, AnsiSequence>, tag_parser!(cursor_restore, "u", AnsiSequence::CursorRestore);
do_parse!( tag_parser!(erase_display, "2J", AnsiSequence::EraseDisplay);
tag!("?25l") >> tag_parser!(erase_line, "K", AnsiSequence::EraseLine);
(AnsiSequence::HideCursor) tag_parser!(hide_cursor, "?25l", AnsiSequence::HideCursor);
) tag_parser!(show_cursor, "?25h", AnsiSequence::ShowCursor);
); tag_parser!(cursor_to_app, "?1h", AnsiSequence::CursorToApp);
tag_parser!(new_line_mode, "20h", AnsiSequence::SetNewLineMode);
named!( tag_parser!(col_132, "?3h", AnsiSequence::SetCol132);
show_cursor<&str, AnsiSequence>, tag_parser!(smooth_scroll, "?4h", AnsiSequence::SetSmoothScroll);
do_parse!( tag_parser!(reverse_video, "?5h", AnsiSequence::SetReverseVideo);
tag!("?25h") >> tag_parser!(origin_relative,"?6h", AnsiSequence::SetOriginRelative);
(AnsiSequence::ShowCursor) tag_parser!(auto_wrap, "?7h", AnsiSequence::SetAutoWrap);
) tag_parser!(auto_repeat, "?8h", AnsiSequence::SetAutoRepeat);
); tag_parser!(interlacing, "?9h", AnsiSequence::SetInterlacing);
named!( named!(
combined<&str, AnsiSequence>, combined<&str, AnsiSequence>,
@@ -192,6 +172,15 @@ named!(
| reset_mode | reset_mode
| hide_cursor | hide_cursor
| show_cursor | show_cursor
| cursor_to_app
| new_line_mode
| col_132
| smooth_scroll
| reverse_video
| origin_relative
| auto_wrap
| auto_repeat
| interlacing
) )
); );

View File

@@ -61,6 +61,5 @@ fn test_parser_iterator_failure() {
let strings: Vec<Output> = ParserIterator::new(parse_str) let strings: Vec<Output> = ParserIterator::new(parse_str)
.collect(); .collect();
println!("{:#?}", strings);
assert_eq!(strings.len(), 6); assert_eq!(strings.len(), 6);
} }