Merge branch 'fix_clippy' into 'master'
Fix cargo clippy && cargo fmt See merge request davidbittner/ansi-parser!8
This commit is contained in:
174
src/enums.rs
174
src/enums.rs
@@ -1,7 +1,7 @@
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
use heapless::{Vec, consts::U5};
|
use heapless::{consts::U5, Vec};
|
||||||
|
|
||||||
///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, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
@@ -64,114 +64,66 @@ impl Display for AnsiSequence {
|
|||||||
|
|
||||||
use AnsiSequence::*;
|
use AnsiSequence::*;
|
||||||
match self {
|
match self {
|
||||||
Escape =>
|
Escape => write!(formatter, "\u{1b}"),
|
||||||
write!(formatter, "\u{1b}"),
|
CursorPos(line, col) => write!(formatter, "[{};{}H", line, col),
|
||||||
CursorPos(line, col)
|
CursorUp(amt) => write!(formatter, "[{}A", amt),
|
||||||
=> write!(formatter, "[{};{}H", line, col),
|
CursorDown(amt) => write!(formatter, "[{}B", amt),
|
||||||
CursorUp(amt)
|
CursorForward(amt) => write!(formatter, "[{}C", amt),
|
||||||
=> write!(formatter, "[{}A", amt),
|
CursorBackward(amt) => write!(formatter, "[{}D", amt),
|
||||||
CursorDown(amt)
|
CursorSave => write!(formatter, "[s"),
|
||||||
=> write!(formatter, "[{}B", amt),
|
CursorRestore => write!(formatter, "[u"),
|
||||||
CursorForward(amt)
|
EraseDisplay => write!(formatter, "[2J"),
|
||||||
=> write!(formatter, "[{}C", amt),
|
EraseLine => write!(formatter, "[K"),
|
||||||
CursorBackward(amt)
|
SetGraphicsMode(vec) => match vec.len() {
|
||||||
=> write!(formatter, "[{}D", amt),
|
0 => write!(formatter, "[m"),
|
||||||
CursorSave
|
1 => write!(formatter, "[{}m", vec[0]),
|
||||||
=> write!(formatter, "[s"),
|
2 => write!(formatter, "[{};{}m", vec[0], vec[1]),
|
||||||
CursorRestore
|
3 => write!(formatter, "[{};{};{}m", vec[0], vec[1], vec[2]),
|
||||||
=> write!(formatter, "[u"),
|
5 => write!(
|
||||||
EraseDisplay
|
formatter,
|
||||||
=> write!(formatter, "[2J"),
|
"[{};{};{};{};{}m",
|
||||||
EraseLine
|
vec[0], vec[1], vec[2], vec[3], vec[4]
|
||||||
=> write!(formatter, "[K"),
|
),
|
||||||
SetGraphicsMode(vec)
|
_ => unreachable!(),
|
||||||
=> {
|
},
|
||||||
match vec.len() {
|
SetMode(mode) => write!(formatter, "[={}h", mode),
|
||||||
0 => write!(formatter, "[m"),
|
ResetMode(mode) => write!(formatter, "[={}l", mode),
|
||||||
1 => write!(formatter, "[{}m", vec[0]),
|
ShowCursor => write!(formatter, "[?25h"),
|
||||||
2 => write!(formatter, "[{};{}m", vec[0], vec[1]),
|
HideCursor => write!(formatter, "[?25l"),
|
||||||
3 => write!(formatter, "[{};{};{}m", vec[0], vec[1], vec[2]),
|
CursorToApp => write!(formatter, "[?1h"),
|
||||||
5 => write!(formatter, "[{};{};{};{};{}m", vec[0], vec[1],
|
SetNewLineMode => write!(formatter, "[20h"),
|
||||||
vec[2], vec[3], vec[4]),
|
SetCol132 => write!(formatter, "[?3h"),
|
||||||
_ => unreachable!()
|
SetSmoothScroll => write!(formatter, "[?4h"),
|
||||||
}
|
SetReverseVideo => write!(formatter, "[?5h"),
|
||||||
},
|
SetOriginRelative => write!(formatter, "[?6h"),
|
||||||
SetMode(mode)
|
SetAutoWrap => write!(formatter, "[?7h"),
|
||||||
=> write!(formatter, "[={}h", mode),
|
SetAutoRepeat => write!(formatter, "[?8h"),
|
||||||
ResetMode(mode)
|
SetInterlacing => write!(formatter, "[?9h"),
|
||||||
=> write!(formatter, "[={}l", mode),
|
SetLineFeedMode => write!(formatter, "[20l"),
|
||||||
ShowCursor
|
SetCursorKeyToCursor => write!(formatter, "[?1l"),
|
||||||
=> write!(formatter, "[?25h"),
|
SetVT52 => write!(formatter, "[?2l"),
|
||||||
HideCursor
|
SetCol80 => write!(formatter, "[?3l"),
|
||||||
=> write!(formatter, "[?25l"),
|
SetJumpScrolling => write!(formatter, "[?4l"),
|
||||||
CursorToApp
|
SetNormalVideo => write!(formatter, "[?5l"),
|
||||||
=> write!(formatter, "[?1h"),
|
SetOriginAbsolute => write!(formatter, "[?6l"),
|
||||||
SetNewLineMode
|
ResetAutoWrap => write!(formatter, "[?7l"),
|
||||||
=> write!(formatter, "[20h"),
|
ResetAutoRepeat => write!(formatter, "[?8l"),
|
||||||
SetCol132
|
ResetInterlacing => write!(formatter, "[?9l"),
|
||||||
=> write!(formatter, "[?3h"),
|
SetAlternateKeypad => write!(formatter, "="),
|
||||||
SetSmoothScroll
|
SetNumericKeypad => write!(formatter, ">"),
|
||||||
=> write!(formatter, "[?4h"),
|
SetUKG0 => write!(formatter, "(A"),
|
||||||
SetReverseVideo
|
SetUKG1 => write!(formatter, ")A"),
|
||||||
=> write!(formatter, "[?5h"),
|
SetUSG0 => write!(formatter, "(B"),
|
||||||
SetOriginRelative
|
SetUSG1 => write!(formatter, ")B"),
|
||||||
=> write!(formatter, "[?6h"),
|
SetG0SpecialChars => write!(formatter, "(0"),
|
||||||
SetAutoWrap
|
SetG1SpecialChars => write!(formatter, ")0"),
|
||||||
=> write!(formatter, "[?7h"),
|
SetG0AlternateChar => write!(formatter, "(1"),
|
||||||
SetAutoRepeat
|
SetG1AlternateChar => write!(formatter, ")1"),
|
||||||
=> write!(formatter, "[?8h"),
|
SetG0AltAndSpecialGraph => write!(formatter, "(2"),
|
||||||
SetInterlacing
|
SetG1AltAndSpecialGraph => write!(formatter, ")2"),
|
||||||
=> write!(formatter, "[?9h"),
|
SetSingleShift2 => write!(formatter, "N"),
|
||||||
SetLineFeedMode
|
SetSingleShift3 => write!(formatter, "O"),
|
||||||
=> write!(formatter, "[20l"),
|
SetTopAndBottom(x, y) => write!(formatter, "{};{}r", x, y),
|
||||||
SetCursorKeyToCursor
|
|
||||||
=> write!(formatter, "[?1l"),
|
|
||||||
SetVT52
|
|
||||||
=> write!(formatter, "[?2l"),
|
|
||||||
SetCol80
|
|
||||||
=> write!(formatter, "[?3l"),
|
|
||||||
SetJumpScrolling
|
|
||||||
=> write!(formatter, "[?4l"),
|
|
||||||
SetNormalVideo
|
|
||||||
=> write!(formatter, "[?5l"),
|
|
||||||
SetOriginAbsolute
|
|
||||||
=> write!(formatter, "[?6l"),
|
|
||||||
ResetAutoWrap
|
|
||||||
=> write!(formatter, "[?7l"),
|
|
||||||
ResetAutoRepeat
|
|
||||||
=> write!(formatter, "[?8l"),
|
|
||||||
ResetInterlacing
|
|
||||||
=> write!(formatter, "[?9l"),
|
|
||||||
SetAlternateKeypad
|
|
||||||
=> write!(formatter, "="),
|
|
||||||
SetNumericKeypad
|
|
||||||
=> write!(formatter, ">"),
|
|
||||||
SetUKG0
|
|
||||||
=> write!(formatter, "(A"),
|
|
||||||
SetUKG1
|
|
||||||
=> write!(formatter, ")A"),
|
|
||||||
SetUSG0
|
|
||||||
=> write!(formatter, "(B"),
|
|
||||||
SetUSG1
|
|
||||||
=> write!(formatter, ")B"),
|
|
||||||
SetG0SpecialChars
|
|
||||||
=> write!(formatter, "(0"),
|
|
||||||
SetG1SpecialChars
|
|
||||||
=> write!(formatter, ")0"),
|
|
||||||
SetG0AlternateChar
|
|
||||||
=> write!(formatter, "(1"),
|
|
||||||
SetG1AlternateChar
|
|
||||||
=> write!(formatter, ")1"),
|
|
||||||
SetG0AltAndSpecialGraph
|
|
||||||
=> write!(formatter, "(2"),
|
|
||||||
SetG1AltAndSpecialGraph
|
|
||||||
=> write!(formatter, ")2"),
|
|
||||||
SetSingleShift2
|
|
||||||
=> write!(formatter, "N"),
|
|
||||||
SetSingleShift3
|
|
||||||
=> write!(formatter, "O"),
|
|
||||||
SetTopAndBottom(x, y)
|
|
||||||
=> write!(formatter, "{};{}r", x, y)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -182,7 +134,7 @@ impl Display for AnsiSequence {
|
|||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum Output<'a> {
|
pub enum Output<'a> {
|
||||||
TextBlock(&'a str),
|
TextBlock(&'a str),
|
||||||
Escape(AnsiSequence)
|
Escape(AnsiSequence),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Display for Output<'a> {
|
impl<'a> Display for Output<'a> {
|
||||||
@@ -190,7 +142,7 @@ impl<'a> Display for Output<'a> {
|
|||||||
use Output::*;
|
use Output::*;
|
||||||
match self {
|
match self {
|
||||||
TextBlock(txt) => write!(formatter, "{}", txt),
|
TextBlock(txt) => write!(formatter, "{}", txt),
|
||||||
Escape(seq) => write!(formatter, "{}", seq)
|
Escape(seq) => write!(formatter, "{}", seq),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,8 +7,7 @@ fn test_cursor_pos() {
|
|||||||
let pos = AnsiSequence::CursorPos(5, 20);
|
let pos = AnsiSequence::CursorPos(5, 20);
|
||||||
let mut buff = String::new();
|
let mut buff = String::new();
|
||||||
|
|
||||||
write!(&mut buff, "{}", pos)
|
write!(&mut buff, "{}", pos).expect("failed to write");
|
||||||
.expect("failed to write");
|
|
||||||
|
|
||||||
assert_eq!(buff, "\x1b[5;20H");
|
assert_eq!(buff, "\x1b[5;20H");
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
#![recursion_limit="256"]
|
#![recursion_limit = "256"]
|
||||||
#![cfg_attr(not(any(feature = "std", test)), no_std)]
|
#![cfg_attr(not(any(feature = "std", test)), no_std)]
|
||||||
|
|
||||||
mod enums;
|
mod enums;
|
||||||
@@ -18,7 +18,6 @@ mod traits;
|
|||||||
/// This is done through a pulldown type parser, where an iterator is exposed. This essentially
|
/// 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
|
/// turns all of the ANSI sequences into enums and splits the string at every location that there
|
||||||
/// was an ANSI Sequence.
|
/// was an ANSI Sequence.
|
||||||
|
|
||||||
pub use enums::*;
|
pub use enums::*;
|
||||||
pub use traits::*;
|
|
||||||
pub use parsers::parse_escape;
|
pub use parsers::parse_escape;
|
||||||
|
pub use traits::*;
|
||||||
|
@@ -190,7 +190,6 @@ named!(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
named!(
|
named!(
|
||||||
graphics_mode<&str, AnsiSequence>,
|
graphics_mode<&str, AnsiSequence>,
|
||||||
alt!(
|
alt!(
|
||||||
@@ -236,31 +235,31 @@ named!(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
tag_parser!(cursor_save, "[s", AnsiSequence::CursorSave);
|
tag_parser!(cursor_save, "[s", AnsiSequence::CursorSave);
|
||||||
tag_parser!(cursor_restore, "[u", AnsiSequence::CursorRestore);
|
tag_parser!(cursor_restore, "[u", AnsiSequence::CursorRestore);
|
||||||
tag_parser!(erase_display, "[2J", AnsiSequence::EraseDisplay);
|
tag_parser!(erase_display, "[2J", AnsiSequence::EraseDisplay);
|
||||||
tag_parser!(erase_line, "[K", AnsiSequence::EraseLine);
|
tag_parser!(erase_line, "[K", AnsiSequence::EraseLine);
|
||||||
tag_parser!(hide_cursor, "[?25l", AnsiSequence::HideCursor);
|
tag_parser!(hide_cursor, "[?25l", AnsiSequence::HideCursor);
|
||||||
tag_parser!(show_cursor, "[?25h", AnsiSequence::ShowCursor);
|
tag_parser!(show_cursor, "[?25h", AnsiSequence::ShowCursor);
|
||||||
tag_parser!(cursor_to_app, "[?1h", AnsiSequence::CursorToApp);
|
tag_parser!(cursor_to_app, "[?1h", AnsiSequence::CursorToApp);
|
||||||
tag_parser!(set_new_line_mode, "[20h", AnsiSequence::SetNewLineMode);
|
tag_parser!(set_new_line_mode, "[20h", AnsiSequence::SetNewLineMode);
|
||||||
tag_parser!(set_col_132, "[?3h", AnsiSequence::SetCol132);
|
tag_parser!(set_col_132, "[?3h", AnsiSequence::SetCol132);
|
||||||
tag_parser!(set_smooth_scroll, "[?4h", AnsiSequence::SetSmoothScroll);
|
tag_parser!(set_smooth_scroll, "[?4h", AnsiSequence::SetSmoothScroll);
|
||||||
tag_parser!(set_reverse_video, "[?5h", AnsiSequence::SetReverseVideo);
|
tag_parser!(set_reverse_video, "[?5h", AnsiSequence::SetReverseVideo);
|
||||||
tag_parser!(set_origin_rel, "[?6h", AnsiSequence::SetOriginRelative);
|
tag_parser!(set_origin_rel, "[?6h", AnsiSequence::SetOriginRelative);
|
||||||
tag_parser!(set_auto_wrap, "[?7h", AnsiSequence::SetAutoWrap);
|
tag_parser!(set_auto_wrap, "[?7h", AnsiSequence::SetAutoWrap);
|
||||||
tag_parser!(set_auto_repeat, "[?8h", AnsiSequence::SetAutoRepeat);
|
tag_parser!(set_auto_repeat, "[?8h", AnsiSequence::SetAutoRepeat);
|
||||||
tag_parser!(set_interlacing, "[?9h", AnsiSequence::SetInterlacing);
|
tag_parser!(set_interlacing, "[?9h", AnsiSequence::SetInterlacing);
|
||||||
tag_parser!(set_linefeed, "[20l", AnsiSequence::SetLineFeedMode);
|
tag_parser!(set_linefeed, "[20l", AnsiSequence::SetLineFeedMode);
|
||||||
tag_parser!(set_cursorkey, "[?1l", AnsiSequence::SetCursorKeyToCursor);
|
tag_parser!(set_cursorkey, "[?1l", AnsiSequence::SetCursorKeyToCursor);
|
||||||
tag_parser!(set_vt52, "[?2l", AnsiSequence::SetVT52);
|
tag_parser!(set_vt52, "[?2l", AnsiSequence::SetVT52);
|
||||||
tag_parser!(set_col80, "[?3l", AnsiSequence::SetCol80);
|
tag_parser!(set_col80, "[?3l", AnsiSequence::SetCol80);
|
||||||
tag_parser!(set_jump_scroll, "[?4l", AnsiSequence::SetJumpScrolling);
|
tag_parser!(set_jump_scroll, "[?4l", AnsiSequence::SetJumpScrolling);
|
||||||
tag_parser!(set_normal_video, "[?5l", AnsiSequence::SetNormalVideo);
|
tag_parser!(set_normal_video, "[?5l", AnsiSequence::SetNormalVideo);
|
||||||
tag_parser!(set_origin_abs, "[?6l", AnsiSequence::SetOriginAbsolute);
|
tag_parser!(set_origin_abs, "[?6l", AnsiSequence::SetOriginAbsolute);
|
||||||
tag_parser!(reset_auto_wrap, "[?7l", AnsiSequence::ResetAutoWrap);
|
tag_parser!(reset_auto_wrap, "[?7l", AnsiSequence::ResetAutoWrap);
|
||||||
tag_parser!(reset_auto_repeat, "[?8l", AnsiSequence::ResetAutoRepeat);
|
tag_parser!(reset_auto_repeat, "[?8l", AnsiSequence::ResetAutoRepeat);
|
||||||
tag_parser!(reset_interlacing, "[?9l", AnsiSequence::ResetInterlacing);
|
tag_parser!(reset_interlacing, "[?9l", AnsiSequence::ResetInterlacing);
|
||||||
|
|
||||||
tag_parser!(set_alternate_keypad, "=", AnsiSequence::SetAlternateKeypad);
|
tag_parser!(set_alternate_keypad, "=", AnsiSequence::SetAlternateKeypad);
|
||||||
tag_parser!(set_numeric_keypad, ">", AnsiSequence::SetNumericKeypad);
|
tag_parser!(set_numeric_keypad, ">", AnsiSequence::SetNumericKeypad);
|
||||||
@@ -268,8 +267,8 @@ tag_parser!(set_uk_g0, "(A", AnsiSequence::SetUKG0);
|
|||||||
tag_parser!(set_uk_g1, ")A", AnsiSequence::SetUKG1);
|
tag_parser!(set_uk_g1, ")A", AnsiSequence::SetUKG1);
|
||||||
tag_parser!(set_us_g0, "(B", AnsiSequence::SetUSG0);
|
tag_parser!(set_us_g0, "(B", AnsiSequence::SetUSG0);
|
||||||
tag_parser!(set_us_g1, ")B", AnsiSequence::SetUSG1);
|
tag_parser!(set_us_g1, ")B", AnsiSequence::SetUSG1);
|
||||||
tag_parser!(set_g0_special, "(0", AnsiSequence::SetG0SpecialChars);
|
tag_parser!(set_g0_special, "(0", AnsiSequence::SetG0SpecialChars);
|
||||||
tag_parser!(set_g1_special, ")0", AnsiSequence::SetG1SpecialChars);
|
tag_parser!(set_g1_special, ")0", AnsiSequence::SetG1SpecialChars);
|
||||||
tag_parser!(set_g0_alternate, "(1", AnsiSequence::SetG0AlternateChar);
|
tag_parser!(set_g0_alternate, "(1", AnsiSequence::SetG0AlternateChar);
|
||||||
tag_parser!(set_g1_alternate, ")1", AnsiSequence::SetG1AlternateChar);
|
tag_parser!(set_g1_alternate, ")1", AnsiSequence::SetG1AlternateChar);
|
||||||
tag_parser!(set_g0_graph, "(2", AnsiSequence::SetG0AltAndSpecialGraph);
|
tag_parser!(set_g0_graph, "(2", AnsiSequence::SetG0AltAndSpecialGraph);
|
||||||
|
@@ -16,12 +16,11 @@ macro_rules! test_parser {
|
|||||||
assert!(ret.is_ok());
|
assert!(ret.is_ok());
|
||||||
let ret = ret.unwrap().1;
|
let ret = ret.unwrap().1;
|
||||||
|
|
||||||
write!(&mut buff, "{}", ret)
|
write!(&mut buff, "{}", ret).unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(buff, $string);
|
assert_eq!(buff, $string);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! test_def_val_parser {
|
macro_rules! test_def_val_parser {
|
||||||
@@ -34,8 +33,7 @@ macro_rules! test_def_val_parser {
|
|||||||
assert!(ret.is_ok());
|
assert!(ret.is_ok());
|
||||||
let ret = ret.unwrap().1;
|
let ret = ret.unwrap().1;
|
||||||
|
|
||||||
write!(&mut buff, "{}", ret)
|
write!(&mut buff, "{}", ret).unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let ret2 = parse_escape(&buff);
|
let ret2 = parse_escape(&buff);
|
||||||
assert!(ret2.is_ok());
|
assert!(ret2.is_ok());
|
||||||
@@ -43,21 +41,21 @@ macro_rules! test_def_val_parser {
|
|||||||
let ret2 = ret2.unwrap().1;
|
let ret2 = ret2.unwrap().1;
|
||||||
assert_eq!(ret, ret2);
|
assert_eq!(ret, ret2);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
test_def_val_parser!(cursor_pos_default, "\u{1b}[H");
|
test_def_val_parser!(cursor_pos_default, "\u{1b}[H");
|
||||||
test_def_val_parser!(cursor_pos, "\u{1b}[10;5H");
|
test_def_val_parser!(cursor_pos, "\u{1b}[10;5H");
|
||||||
test_def_val_parser!(cursor_up_default, "\u{1b}[A");
|
test_def_val_parser!(cursor_up_default, "\u{1b}[A");
|
||||||
test_def_val_parser!(cursor_up, "\u{1b}[5A");
|
test_def_val_parser!(cursor_up, "\u{1b}[5A");
|
||||||
test_def_val_parser!(cursor_down, "\u{1b}[5B");
|
test_def_val_parser!(cursor_down, "\u{1b}[5B");
|
||||||
test_def_val_parser!(cursor_forward, "\u{1b}[5C");
|
test_def_val_parser!(cursor_forward, "\u{1b}[5C");
|
||||||
test_def_val_parser!(cursor_backward, "\u{1b}[5D");
|
test_def_val_parser!(cursor_backward, "\u{1b}[5D");
|
||||||
test_parser!(cursor_save, "\u{1b}[s");
|
test_parser!(cursor_save, "\u{1b}[s");
|
||||||
test_parser!(cursor_restore, "\u{1b}[u");
|
test_parser!(cursor_restore, "\u{1b}[u");
|
||||||
|
|
||||||
test_parser!(erase_display, "\u{1b}[2J");
|
test_parser!(erase_display, "\u{1b}[2J");
|
||||||
test_parser!(erase_line, "\u{1b}[K");
|
test_parser!(erase_line, "\u{1b}[K");
|
||||||
|
|
||||||
test_parser!(set_video_mode_a, "\u{1b}[4m");
|
test_parser!(set_video_mode_a, "\u{1b}[4m");
|
||||||
test_parser!(set_video_mode_b, "\u{1b}[4;42m");
|
test_parser!(set_video_mode_b, "\u{1b}[4;42m");
|
||||||
@@ -65,30 +63,30 @@ test_parser!(set_video_mode_c, "\u{1b}[4;31;42m");
|
|||||||
test_parser!(set_video_mode_d, "\u{1b}[4;31;42;42;42m");
|
test_parser!(set_video_mode_d, "\u{1b}[4;31;42;42;42m");
|
||||||
|
|
||||||
test_parser!(reset_mode, "\u{1b}[=13l");
|
test_parser!(reset_mode, "\u{1b}[=13l");
|
||||||
test_parser!(set_mode, "\u{1b}[=7h");
|
test_parser!(set_mode, "\u{1b}[=7h");
|
||||||
|
|
||||||
test_parser!(show_cursor, "\u{1b}[?25h");
|
test_parser!(show_cursor, "\u{1b}[?25h");
|
||||||
test_parser!(hide_cursor, "\u{1b}[?25l");
|
test_parser!(hide_cursor, "\u{1b}[?25l");
|
||||||
test_parser!(cursor_to_app, "\u{1b}[?1h");
|
test_parser!(cursor_to_app, "\u{1b}[?1h");
|
||||||
|
|
||||||
test_parser!(set_newline_mode, "\u{1b}[20h");
|
test_parser!(set_newline_mode, "\u{1b}[20h");
|
||||||
test_parser!(set_column_132, "\u{1b}[?3h");
|
test_parser!(set_column_132, "\u{1b}[?3h");
|
||||||
test_parser!(set_smooth_scroll, "\u{1b}[?4h");
|
test_parser!(set_smooth_scroll, "\u{1b}[?4h");
|
||||||
test_parser!(set_reverse_video, "\u{1b}[?5h");
|
test_parser!(set_reverse_video, "\u{1b}[?5h");
|
||||||
test_parser!(set_origin_rel, "\u{1b}[?6h");
|
test_parser!(set_origin_rel, "\u{1b}[?6h");
|
||||||
test_parser!(set_auto_wrap, "\u{1b}[?7h");
|
test_parser!(set_auto_wrap, "\u{1b}[?7h");
|
||||||
test_parser!(set_auto_repeat, "\u{1b}[?8h");
|
test_parser!(set_auto_repeat, "\u{1b}[?8h");
|
||||||
test_parser!(set_interlacing, "\u{1b}[?9h");
|
test_parser!(set_interlacing, "\u{1b}[?9h");
|
||||||
|
|
||||||
test_parser!(set_cursor_key_to_cursor, "\u{1b}[?1l");
|
test_parser!(set_cursor_key_to_cursor, "\u{1b}[?1l");
|
||||||
|
|
||||||
test_parser!(set_linefeed, "\u{1b}[20l");
|
test_parser!(set_linefeed, "\u{1b}[20l");
|
||||||
test_parser!(set_vt52, "\u{1b}[?2l");
|
test_parser!(set_vt52, "\u{1b}[?2l");
|
||||||
test_parser!(set_col80, "\u{1b}[?3l");
|
test_parser!(set_col80, "\u{1b}[?3l");
|
||||||
test_parser!(set_jump_scroll, "\u{1b}[?4l");
|
test_parser!(set_jump_scroll, "\u{1b}[?4l");
|
||||||
test_parser!(set_normal_video, "\u{1b}[?5l");
|
test_parser!(set_normal_video, "\u{1b}[?5l");
|
||||||
test_parser!(set_origin_abs, "\u{1b}[?6l");
|
test_parser!(set_origin_abs, "\u{1b}[?6l");
|
||||||
test_parser!(reset_auto_wrap, "\u{1b}[?7l");
|
test_parser!(reset_auto_wrap, "\u{1b}[?7l");
|
||||||
test_parser!(reset_auto_repeat, "\u{1b}[?8l");
|
test_parser!(reset_auto_repeat, "\u{1b}[?8l");
|
||||||
test_parser!(reset_interlacing, "\u{1b}[?9l");
|
test_parser!(reset_interlacing, "\u{1b}[?9l");
|
||||||
|
|
||||||
@@ -109,20 +107,20 @@ test_parser!(set_single_shift3, "\u{1b}O");
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parser_iterator() {
|
fn test_parser_iterator() {
|
||||||
let strings: Vec<_> = "\x1b[=25l\x1b[=7l\x1b[0m\x1b[36m\x1b[1m-`"
|
let count = "\x1b[=25l\x1b[=7l\x1b[0m\x1b[36m\x1b[1m-`"
|
||||||
.ansi_parse()
|
.ansi_parse()
|
||||||
.collect();
|
.count();
|
||||||
|
|
||||||
assert_eq!(strings.len(), 6);
|
assert_eq!(count, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parser_iterator_failure() {
|
fn test_parser_iterator_failure() {
|
||||||
let strings: Vec<_> = "\x1b[=25l\x1b[=7l\x1b[0m\x1b[36;1;15;2m\x1b[1m-`"
|
let count = "\x1b[=25l\x1b[=7l\x1b[0m\x1b[36;1;15;2m\x1b[1m-`"
|
||||||
.ansi_parse()
|
.ansi_parse()
|
||||||
.collect();
|
.count();
|
||||||
|
|
||||||
assert_eq!(strings.len(), 6);
|
assert_eq!(count, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -131,9 +129,15 @@ fn test_default_value() {
|
|||||||
.ansi_parse()
|
.ansi_parse()
|
||||||
.collect();
|
.collect();
|
||||||
assert_eq!(strings.len(), 5);
|
assert_eq!(strings.len(), 5);
|
||||||
assert_eq!(strings[0], Output::Escape(AnsiSequence::CursorPos(1,1)));
|
assert_eq!(strings[0], Output::Escape(AnsiSequence::CursorPos(1, 1)));
|
||||||
assert_eq!(strings[1], Output::Escape(AnsiSequence::CursorPos(123456,1)));
|
assert_eq!(
|
||||||
assert_eq!(strings[2], Output::Escape(AnsiSequence::CursorPos(1,123456)));
|
strings[1],
|
||||||
|
Output::Escape(AnsiSequence::CursorPos(123456, 1))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
strings[2],
|
||||||
|
Output::Escape(AnsiSequence::CursorPos(1, 123456))
|
||||||
|
);
|
||||||
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"));
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
use crate::enums::{Output};
|
use crate::enums::Output;
|
||||||
use crate::parsers::parse_escape;
|
use crate::parsers::parse_escape;
|
||||||
|
|
||||||
pub trait AnsiParser {
|
pub trait AnsiParser {
|
||||||
@@ -7,18 +7,14 @@ pub trait AnsiParser {
|
|||||||
|
|
||||||
impl AnsiParser for str {
|
impl AnsiParser for str {
|
||||||
fn ansi_parse(&self) -> AnsiParseIterator<'_> {
|
fn ansi_parse(&self) -> AnsiParseIterator<'_> {
|
||||||
AnsiParseIterator {
|
AnsiParseIterator { dat: self }
|
||||||
dat: self
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "std", test))]
|
#[cfg(any(feature = "std", test))]
|
||||||
impl AnsiParser for String {
|
impl AnsiParser for String {
|
||||||
fn ansi_parse(&self) -> AnsiParseIterator<'_> {
|
fn ansi_parse(&self) -> AnsiParseIterator<'_> {
|
||||||
AnsiParseIterator {
|
AnsiParseIterator { dat: self }
|
||||||
dat: self
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,9 +24,9 @@ pub struct AnsiParseIterator<'a> {
|
|||||||
|
|
||||||
impl<'a> Iterator for AnsiParseIterator<'a> {
|
impl<'a> Iterator for AnsiParseIterator<'a> {
|
||||||
type Item = Output<'a>;
|
type Item = Output<'a>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
if self.dat == "" {
|
if self.dat.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,33 +36,32 @@ impl<'a> Iterator for AnsiParseIterator<'a> {
|
|||||||
let res = parse_escape(&self.dat[loc..]);
|
let res = parse_escape(&self.dat[loc..]);
|
||||||
|
|
||||||
if let Ok(ret) = res {
|
if let Ok(ret) = res {
|
||||||
self.dat = &ret.0;
|
self.dat = ret.0;
|
||||||
Some(Output::Escape(ret.1))
|
Some(Output::Escape(ret.1))
|
||||||
}else{
|
} else {
|
||||||
let pos = self.dat[(loc+1)..].find('\u{1b}');
|
let pos = self.dat[(loc + 1)..].find('\u{1b}');
|
||||||
if let Some(loc) = pos {
|
if let Some(loc) = pos {
|
||||||
//Added to because it's based one character ahead
|
//Added to because it's based one character ahead
|
||||||
let loc = loc+1;
|
let loc = loc + 1;
|
||||||
|
|
||||||
let temp = &self.dat[..loc];
|
let temp = &self.dat[..loc];
|
||||||
self.dat = &self.dat[loc..];
|
self.dat = &self.dat[loc..];
|
||||||
|
|
||||||
Some(Output::TextBlock(temp))
|
Some(Output::TextBlock(temp))
|
||||||
}else{
|
} else {
|
||||||
let temp = self.dat;
|
let temp = self.dat;
|
||||||
self.dat = "";
|
self.dat = "";
|
||||||
|
|
||||||
Some(Output::TextBlock(temp))
|
Some(Output::TextBlock(temp))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
}else {
|
|
||||||
let temp = &self.dat[..loc];
|
let temp = &self.dat[..loc];
|
||||||
self.dat = &self.dat[loc..];
|
self.dat = &self.dat[loc..];
|
||||||
|
|
||||||
Some(Output::TextBlock(&temp))
|
Some(Output::TextBlock(temp))
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
let temp = self.dat;
|
let temp = self.dat;
|
||||||
self.dat = "";
|
self.dat = "";
|
||||||
Some(Output::TextBlock(temp))
|
Some(Output::TextBlock(temp))
|
||||||
|
Reference in New Issue
Block a user