adding new sequences from the VT100 list
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -2,7 +2,7 @@
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "ansi-parser"
|
||||
version = "0.5.1"
|
||||
version = "0.5.2"
|
||||
dependencies = [
|
||||
"nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@@ -4,7 +4,7 @@ description = "A library using nom for parsing ANSI Escape Codes"
|
||||
homepage = "https://gitlab.com/DavidBittner/ansi-parser"
|
||||
authors = ["David Bittner <bittneradave@gmail.com>"]
|
||||
|
||||
version = "0.5.2"
|
||||
version = "0.5.3"
|
||||
license = "MPL-2.0"
|
||||
|
||||
edition = "2018"
|
||||
|
37
src/enums.rs
37
src/enums.rs
@@ -17,7 +17,18 @@ pub enum AnsiSequence {
|
||||
SetMode(u8),
|
||||
ResetMode(u8),
|
||||
HideCursor,
|
||||
ShowCursor
|
||||
ShowCursor,
|
||||
CursorToApp,
|
||||
SetNewLineMode,
|
||||
SetCol132,
|
||||
SetSmoothScroll,
|
||||
SetReverseVideo,
|
||||
SetOriginRelative,
|
||||
SetAutoWrap,
|
||||
SetAutoRepeat,
|
||||
SetInterlacing,
|
||||
SetLineFeedMode,
|
||||
SetCursorKeyToCursor,
|
||||
}
|
||||
|
||||
use std::fmt::Display;
|
||||
@@ -61,7 +72,29 @@ impl Display for AnsiSequence {
|
||||
ShowCursor
|
||||
=> write!(formatter, "?25h"),
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,18 @@ use crate::{AnsiSequence, Output};
|
||||
use std::convert::TryInto;
|
||||
use nom::*;
|
||||
|
||||
macro_rules! tag_parser {
|
||||
($sig:ident, $tag:expr, $ret:expr) => {
|
||||
named!(
|
||||
$sig<&str, AnsiSequence>,
|
||||
do_parse!(
|
||||
tag!($tag) >>
|
||||
($ret)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
named!(
|
||||
parse_int<&str, u32>,
|
||||
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!(
|
||||
graphics_mode1<&str, AnsiSequence>,
|
||||
do_parse!(
|
||||
@@ -159,21 +139,21 @@ named!(
|
||||
)
|
||||
);
|
||||
|
||||
named!(
|
||||
hide_cursor<&str, AnsiSequence>,
|
||||
do_parse!(
|
||||
tag!("?25l") >>
|
||||
(AnsiSequence::HideCursor)
|
||||
)
|
||||
);
|
||||
|
||||
named!(
|
||||
show_cursor<&str, AnsiSequence>,
|
||||
do_parse!(
|
||||
tag!("?25h") >>
|
||||
(AnsiSequence::ShowCursor)
|
||||
)
|
||||
);
|
||||
tag_parser!(cursor_save, "s", AnsiSequence::CursorSave);
|
||||
tag_parser!(cursor_restore, "u", AnsiSequence::CursorRestore);
|
||||
tag_parser!(erase_display, "2J", AnsiSequence::EraseDisplay);
|
||||
tag_parser!(erase_line, "K", AnsiSequence::EraseLine);
|
||||
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);
|
||||
tag_parser!(col_132, "?3h", AnsiSequence::SetCol132);
|
||||
tag_parser!(smooth_scroll, "?4h", AnsiSequence::SetSmoothScroll);
|
||||
tag_parser!(reverse_video, "?5h", AnsiSequence::SetReverseVideo);
|
||||
tag_parser!(origin_relative,"?6h", AnsiSequence::SetOriginRelative);
|
||||
tag_parser!(auto_wrap, "?7h", AnsiSequence::SetAutoWrap);
|
||||
tag_parser!(auto_repeat, "?8h", AnsiSequence::SetAutoRepeat);
|
||||
tag_parser!(interlacing, "?9h", AnsiSequence::SetInterlacing);
|
||||
|
||||
named!(
|
||||
combined<&str, AnsiSequence>,
|
||||
@@ -192,6 +172,15 @@ named!(
|
||||
| reset_mode
|
||||
| hide_cursor
|
||||
| show_cursor
|
||||
| cursor_to_app
|
||||
| new_line_mode
|
||||
| col_132
|
||||
| smooth_scroll
|
||||
| reverse_video
|
||||
| origin_relative
|
||||
| auto_wrap
|
||||
| auto_repeat
|
||||
| interlacing
|
||||
)
|
||||
);
|
||||
|
||||
|
@@ -61,6 +61,5 @@ fn test_parser_iterator_failure() {
|
||||
let strings: Vec<Output> = ParserIterator::new(parse_str)
|
||||
.collect();
|
||||
|
||||
println!("{:#?}", strings);
|
||||
assert_eq!(strings.len(), 6);
|
||||
}
|
||||
|
Reference in New Issue
Block a user