add tons of codes
This commit is contained in:
53
src/enums.rs
53
src/enums.rs
@@ -7,19 +7,30 @@ use heapless::Vec;
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum AnsiSequence {
|
||||
Escape,
|
||||
GetCursorPos,
|
||||
CursorPos(u32, u32),
|
||||
CursorUp(u32),
|
||||
CursorDown(u32),
|
||||
CursorForward(u32),
|
||||
CursorBackward(u32),
|
||||
CursorSave,
|
||||
CursorRestore,
|
||||
EraseDisplay,
|
||||
EraseLine,
|
||||
SetGraphicsMode(Vec<u8, 5>),
|
||||
SetMode(u8),
|
||||
ResetMode(u8),
|
||||
CursorHome, // ^[[H
|
||||
CursorPos(u32, u32), // ^[[#;#H or [#;#f
|
||||
CursorUp(u32), // ^[[#A
|
||||
CursorDown(u32), // ^[[#B
|
||||
CursorRight(u32), // ^[[#C
|
||||
CursorLeft(u32), // ^[[#D
|
||||
// TODO ^[[#E
|
||||
// TODO ^[[#F
|
||||
// TODO ^[[#G
|
||||
RequestCursorPos, // ^[[6n TODO rename GetCursorPos to RequestCursorPos
|
||||
CursorUpScroll, // ^[ M
|
||||
CursorSave, // ^[ 7
|
||||
CursorRestore, // ^[ 8
|
||||
EraseScreenToEnd, // ^[[0J or ^[[J
|
||||
EraseScreenFromStart, // ^[[1J
|
||||
EraseScreen, // ^[[2J
|
||||
// TODO ^[[3J
|
||||
EraseLineToEnd, // ^[[0K or ^[[K
|
||||
EraseLineFromStart, // ^[[1K
|
||||
EraseLine, // ^[[2K
|
||||
SetGraphicsMode(Vec<u8, 5>), // TODO figure out graphics mode
|
||||
SetMode(u8), // ^[[=#h
|
||||
ResetMode(u8), // ^[[=#l
|
||||
|
||||
HideCursor,
|
||||
ShowCursor,
|
||||
CursorToApp,
|
||||
@@ -66,16 +77,22 @@ impl Display for AnsiSequence {
|
||||
use AnsiSequence::*;
|
||||
match self {
|
||||
Escape => write!(formatter, "\u{1b}"),
|
||||
GetCursorPos => write!(formatter, "[6n"),
|
||||
RequestCursorPos => write!(formatter, "[6n"),
|
||||
CursorHome => write!(formatter, "[H"),
|
||||
CursorPos(line, col) => write!(formatter, "[{};{}H", line, col),
|
||||
CursorUp(amt) => write!(formatter, "[{}A", amt),
|
||||
CursorDown(amt) => write!(formatter, "[{}B", amt),
|
||||
CursorForward(amt) => write!(formatter, "[{}C", amt),
|
||||
CursorBackward(amt) => write!(formatter, "[{}D", amt),
|
||||
CursorRight(amt) => write!(formatter, "[{}C", amt),
|
||||
CursorLeft(amt) => write!(formatter, "[{}D", amt),
|
||||
CursorUpScroll => write!(formatter, "[ M"),
|
||||
CursorSave => write!(formatter, "[s"),
|
||||
CursorRestore => write!(formatter, "[u"),
|
||||
EraseDisplay => write!(formatter, "[2J"),
|
||||
EraseLine => write!(formatter, "[K"),
|
||||
EraseScreenToEnd => write!(formatter, "[0J"),
|
||||
EraseScreenFromStart => write!(formatter, "[1J"),
|
||||
EraseScreen => write!(formatter, "[2J"),
|
||||
EraseLineToEnd => write!(formatter, "[0K"),
|
||||
EraseLineFromStart => write!(formatter, "[1K"),
|
||||
EraseLine => write!(formatter, "[2K"),
|
||||
SetGraphicsMode(vec) => match vec.len() {
|
||||
0 => write!(formatter, "[m"),
|
||||
1 => write!(formatter, "[{}m", vec[0]),
|
||||
|
@@ -66,16 +66,16 @@ fn cursor_down(input: &str) -> IResult<&str, AnsiSequence> {
|
||||
.parse(input)
|
||||
}
|
||||
|
||||
fn cursor_forward(input: &str) -> IResult<&str, AnsiSequence> {
|
||||
fn cursor_right(input: &str) -> IResult<&str, AnsiSequence> {
|
||||
map(delimited(tag("["), parse_def_cursor_int, tag("C")), |am| {
|
||||
AnsiSequence::CursorForward(am)
|
||||
AnsiSequence::CursorRight(am)
|
||||
})
|
||||
.parse(input)
|
||||
}
|
||||
|
||||
fn cursor_backward(input: &str) -> IResult<&str, AnsiSequence> {
|
||||
fn cursor_left(input: &str) -> IResult<&str, AnsiSequence> {
|
||||
map(delimited(tag("["), parse_def_cursor_int, tag("D")), |am| {
|
||||
AnsiSequence::CursorBackward(am)
|
||||
AnsiSequence::CursorLeft(am)
|
||||
})
|
||||
.parse(input)
|
||||
}
|
||||
@@ -182,11 +182,37 @@ fn set_top_and_bottom(input: &str) -> IResult<&str, AnsiSequence> {
|
||||
.parse(input)
|
||||
}
|
||||
|
||||
tag_parser!(get_cursor_pos, "[6n", AnsiSequence::GetCursorPos);
|
||||
fn erase_line_to_end(input: &str) -> IResult<&str, AnsiSequence> {
|
||||
map(alt((tag("[K"), tag("[0K"))), |_| {
|
||||
AnsiSequence::EraseLineToEnd
|
||||
})
|
||||
.parse(input)
|
||||
}
|
||||
|
||||
fn erase_screen_to_end(input: &str) -> IResult<&str, AnsiSequence> {
|
||||
map(alt((tag("[J"), tag("[0J"))), |_| {
|
||||
AnsiSequence::EraseScreenToEnd
|
||||
})
|
||||
.parse(input)
|
||||
}
|
||||
|
||||
tag_parser!(
|
||||
erase_screen_from_start,
|
||||
"[1J",
|
||||
AnsiSequence::EraseScreenFromStart
|
||||
);
|
||||
tag_parser!(
|
||||
erase_line_from_start,
|
||||
"[1K",
|
||||
AnsiSequence::EraseLineFromStart
|
||||
);
|
||||
tag_parser!(cursor_up_scroll, "[ M", AnsiSequence::CursorUpScroll);
|
||||
tag_parser!(erase_line, "[2K", AnsiSequence::EraseLine);
|
||||
tag_parser!(cursor_home, "[H", AnsiSequence::CursorHome);
|
||||
tag_parser!(request_cursor_pos, "[6n", AnsiSequence::RequestCursorPos);
|
||||
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!(erase_screen, "[2J", AnsiSequence::EraseScreen);
|
||||
tag_parser!(hide_cursor, "[?25l", AnsiSequence::HideCursor);
|
||||
tag_parser!(show_cursor, "[?25h", AnsiSequence::ShowCursor);
|
||||
tag_parser!(cursor_to_app, "[?1h", AnsiSequence::CursorToApp);
|
||||
@@ -234,11 +260,11 @@ fn combined(input: &str) -> IResult<&str, AnsiSequence> {
|
||||
cursor_pos,
|
||||
cursor_up,
|
||||
cursor_down,
|
||||
cursor_forward,
|
||||
cursor_backward,
|
||||
cursor_right,
|
||||
cursor_left,
|
||||
cursor_save,
|
||||
cursor_restore,
|
||||
erase_display,
|
||||
erase_screen,
|
||||
erase_line,
|
||||
graphics_mode,
|
||||
set_mode,
|
||||
@@ -282,7 +308,13 @@ fn combined(input: &str) -> IResult<&str, AnsiSequence> {
|
||||
set_g1_graph,
|
||||
set_single_shift2,
|
||||
set_single_shift3,
|
||||
get_cursor_pos,
|
||||
request_cursor_pos,
|
||||
cursor_home,
|
||||
erase_line_from_start,
|
||||
erase_screen_from_start,
|
||||
erase_screen_to_end,
|
||||
erase_line_to_end,
|
||||
cursor_up_scroll,
|
||||
))
|
||||
.parse(input)
|
||||
}
|
||||
|
Reference in New Issue
Block a user