From 9dd5a1f082b97c3488b5ae24d47e5163b758b1da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Thu, 2 Mar 2017 00:06:45 +0100 Subject: [PATCH] Implemented cursor wrap control codes e[?7h and l --- user/ansi_parser_callbacks.c | 23 ++++++++++++++++------- user/screen.c | 33 +++++++++++++++++++++++++-------- user/screen.h | 3 +++ 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/user/ansi_parser_callbacks.c b/user/ansi_parser_callbacks.c index 46050cc..5d0a3bd 100644 --- a/user/ansi_parser_callbacks.c +++ b/user/ansi_parser_callbacks.c @@ -160,16 +160,25 @@ apars_handle_CSI(char leadchar, int *params, char keychar) } break; - // DECTCEM cursor show hide - case 'l': - if (leadchar == '?' && n1 == 25) { - screen_cursor_enable(0); + // DECTCEM feature enable / disable + + case 'h': + if (leadchar == '?') { + if (n1 == 25) { + screen_cursor_enable(1); + } else if (n1 == 7) { + screen_wrap_enable(1); + } } break; - case 'h': - if (leadchar == '?' && n1 == 25) { - screen_cursor_enable(1); + case 'l': + if (leadchar == '?') { + if (n1 == 25) { + screen_cursor_enable(0); + } else if (n1 == 7) { + screen_wrap_enable(0); + } } break; diff --git a/user/screen.c b/user/screen.c index d73079a..54fd004 100644 --- a/user/screen.c +++ b/user/screen.c @@ -31,6 +31,7 @@ static struct { int y; //!< Y coordinate bool visible; //!< Visible bool inverse; //!< Inverse colors + bool autowrap; //!< Wrapping when EOL Color fg; //!< Foreground color for writing Color bg; //!< Background color for writing } cursor; @@ -102,6 +103,7 @@ cursor_reset(void) cursor.bg = SCREEN_DEF_BG; cursor.visible = 1; cursor.inverse = 0; + cursor.autowrap = 1; } //endregion @@ -397,6 +399,17 @@ screen_cursor_enable(bool enable) NOTIFY_DONE(); } +/** + * Enable autowrap + */ +void ICACHE_FLASH_ATTR +screen_wrap_enable(bool enable) +{ + NOTIFY_LOCK(); + cursor.autowrap = enable; + NOTIFY_DONE(); +} + //endregion //region Colors @@ -492,7 +505,7 @@ screen_putchar(char ch) cursor.x--; } else { // wrap around start of line - if (cursor.y>0) { + if (cursor.autowrap && cursor.y>0) { cursor.x=W-1; cursor.y--; } @@ -532,13 +545,17 @@ screen_putchar(char ch) cursor.x++; // X wrap if (cursor.x >= W) { - cursor.x = 0; - cursor.y++; - // Y wrap - if (cursor.y > H-1) { - // Scroll up, so we have space for writing - screen_scroll_up(1); - cursor.y = H-1; + if (cursor.autowrap) { + cursor.x = 0; + cursor.y++; + // Y wrap + if (cursor.y > H - 1) { + // Scroll up, so we have space for writing + screen_scroll_up(1); + cursor.y = H - 1; + } + } else { + cursor.x = W - 1; } } diff --git a/user/screen.h b/user/screen.h index f8493df..701e759 100644 --- a/user/screen.h +++ b/user/screen.h @@ -109,6 +109,9 @@ void screen_cursor_restore(bool withAttrs); /** Enable cursor display */ void screen_cursor_enable(bool enable); +/** Enable auto wrap */ +void screen_wrap_enable(bool enable); + // --- Colors --- /** Set cursor foreground color */