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)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum AnsiSequence {
|
pub enum AnsiSequence {
|
||||||
Escape,
|
Escape,
|
||||||
GetCursorPos,
|
CursorHome, // ^[[H
|
||||||
CursorPos(u32, u32),
|
CursorPos(u32, u32), // ^[[#;#H or [#;#f
|
||||||
CursorUp(u32),
|
CursorUp(u32), // ^[[#A
|
||||||
CursorDown(u32),
|
CursorDown(u32), // ^[[#B
|
||||||
CursorForward(u32),
|
CursorRight(u32), // ^[[#C
|
||||||
CursorBackward(u32),
|
CursorLeft(u32), // ^[[#D
|
||||||
CursorSave,
|
// TODO ^[[#E
|
||||||
CursorRestore,
|
// TODO ^[[#F
|
||||||
EraseDisplay,
|
// TODO ^[[#G
|
||||||
EraseLine,
|
RequestCursorPos, // ^[[6n TODO rename GetCursorPos to RequestCursorPos
|
||||||
SetGraphicsMode(Vec<u8, 5>),
|
CursorUpScroll, // ^[ M
|
||||||
SetMode(u8),
|
CursorSave, // ^[ 7
|
||||||
ResetMode(u8),
|
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,
|
HideCursor,
|
||||||
ShowCursor,
|
ShowCursor,
|
||||||
CursorToApp,
|
CursorToApp,
|
||||||
@@ -66,16 +77,22 @@ impl Display for AnsiSequence {
|
|||||||
use AnsiSequence::*;
|
use AnsiSequence::*;
|
||||||
match self {
|
match self {
|
||||||
Escape => write!(formatter, "\u{1b}"),
|
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),
|
CursorPos(line, col) => write!(formatter, "[{};{}H", line, col),
|
||||||
CursorUp(amt) => write!(formatter, "[{}A", amt),
|
CursorUp(amt) => write!(formatter, "[{}A", amt),
|
||||||
CursorDown(amt) => write!(formatter, "[{}B", amt),
|
CursorDown(amt) => write!(formatter, "[{}B", amt),
|
||||||
CursorForward(amt) => write!(formatter, "[{}C", amt),
|
CursorRight(amt) => write!(formatter, "[{}C", amt),
|
||||||
CursorBackward(amt) => write!(formatter, "[{}D", amt),
|
CursorLeft(amt) => write!(formatter, "[{}D", amt),
|
||||||
|
CursorUpScroll => write!(formatter, "[ M"),
|
||||||
CursorSave => write!(formatter, "[s"),
|
CursorSave => write!(formatter, "[s"),
|
||||||
CursorRestore => write!(formatter, "[u"),
|
CursorRestore => write!(formatter, "[u"),
|
||||||
EraseDisplay => write!(formatter, "[2J"),
|
EraseScreenToEnd => write!(formatter, "[0J"),
|
||||||
EraseLine => write!(formatter, "[K"),
|
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() {
|
SetGraphicsMode(vec) => match vec.len() {
|
||||||
0 => write!(formatter, "[m"),
|
0 => write!(formatter, "[m"),
|
||||||
1 => write!(formatter, "[{}m", vec[0]),
|
1 => write!(formatter, "[{}m", vec[0]),
|
||||||
|
@@ -66,16 +66,16 @@ fn cursor_down(input: &str) -> IResult<&str, AnsiSequence> {
|
|||||||
.parse(input)
|
.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| {
|
map(delimited(tag("["), parse_def_cursor_int, tag("C")), |am| {
|
||||||
AnsiSequence::CursorForward(am)
|
AnsiSequence::CursorRight(am)
|
||||||
})
|
})
|
||||||
.parse(input)
|
.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| {
|
map(delimited(tag("["), parse_def_cursor_int, tag("D")), |am| {
|
||||||
AnsiSequence::CursorBackward(am)
|
AnsiSequence::CursorLeft(am)
|
||||||
})
|
})
|
||||||
.parse(input)
|
.parse(input)
|
||||||
}
|
}
|
||||||
@@ -182,11 +182,37 @@ fn set_top_and_bottom(input: &str) -> IResult<&str, AnsiSequence> {
|
|||||||
.parse(input)
|
.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_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_screen, "[2J", AnsiSequence::EraseScreen);
|
||||||
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);
|
||||||
@@ -234,11 +260,11 @@ fn combined(input: &str) -> IResult<&str, AnsiSequence> {
|
|||||||
cursor_pos,
|
cursor_pos,
|
||||||
cursor_up,
|
cursor_up,
|
||||||
cursor_down,
|
cursor_down,
|
||||||
cursor_forward,
|
cursor_right,
|
||||||
cursor_backward,
|
cursor_left,
|
||||||
cursor_save,
|
cursor_save,
|
||||||
cursor_restore,
|
cursor_restore,
|
||||||
erase_display,
|
erase_screen,
|
||||||
erase_line,
|
erase_line,
|
||||||
graphics_mode,
|
graphics_mode,
|
||||||
set_mode,
|
set_mode,
|
||||||
@@ -282,7 +308,13 @@ fn combined(input: &str) -> IResult<&str, AnsiSequence> {
|
|||||||
set_g1_graph,
|
set_g1_graph,
|
||||||
set_single_shift2,
|
set_single_shift2,
|
||||||
set_single_shift3,
|
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)
|
.parse(input)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user