|
|
f7dd65 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
f7dd65 |
From: Robbie Harwood <rharwood@redhat.com>
|
|
|
f7dd65 |
Date: Thu, 21 Oct 2021 15:15:33 -0400
|
|
|
f7dd65 |
Subject: [PATCH] Fix backspace when editing a multiline cmdline
|
|
|
f7dd65 |
|
|
|
f7dd65 |
Once the cmdline had passed the width of the screen, adding additional
|
|
|
f7dd65 |
characters introduced a spurious newline, and another newline at the
|
|
|
f7dd65 |
width of input. Furthermore, hitting backspace would not start
|
|
|
f7dd65 |
redrawing at the end of input, but rather at the beginning of the
|
|
|
f7dd65 |
current line - resulting in extra duplicate lines scrolling the console.
|
|
|
f7dd65 |
|
|
|
f7dd65 |
First, fix the assumption that the length of cmdline is the width - it
|
|
|
f7dd65 |
needs to include the length of the prompt (i.e., length of input and
|
|
|
f7dd65 |
space).
|
|
|
f7dd65 |
|
|
|
f7dd65 |
Second, fix the behavior of single-line redraw (i.e., redraw == 1) to
|
|
|
f7dd65 |
move the cursor to the row the line begins at.
|
|
|
f7dd65 |
|
|
|
f7dd65 |
Third, don't scroll the cursor down when a line wrap would occur - it's
|
|
|
f7dd65 |
not necessary since line wrap is enabled, and results in the extra blank
|
|
|
f7dd65 |
line.
|
|
|
f7dd65 |
|
|
|
f7dd65 |
Finally, comment all used escape sequences so that I don't need to look
|
|
|
f7dd65 |
them up again.
|
|
|
f7dd65 |
|
|
|
f7dd65 |
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
|
|
|
f7dd65 |
---
|
|
|
f7dd65 |
com32/elflink/ldlinux/cli.c | 33 ++++++++++++++++++---------------
|
|
|
f7dd65 |
1 file changed, 18 insertions(+), 15 deletions(-)
|
|
|
f7dd65 |
|
|
|
f7dd65 |
diff --git a/com32/elflink/ldlinux/cli.c b/com32/elflink/ldlinux/cli.c
|
|
|
f7dd65 |
index 3119b11f..4913f038 100644
|
|
|
f7dd65 |
--- a/com32/elflink/ldlinux/cli.c
|
|
|
f7dd65 |
+++ b/com32/elflink/ldlinux/cli.c
|
|
|
f7dd65 |
@@ -135,6 +135,7 @@ const char *edit_cmdline(const char *input, int top /*, int width */ ,
|
|
|
f7dd65 |
struct cli_command *comm_counter = NULL;
|
|
|
f7dd65 |
clock_t kbd_to = kbdtimeout;
|
|
|
f7dd65 |
clock_t tto = totaltimeout;
|
|
|
f7dd65 |
+ int prompt_len = 1 + strlen(input);
|
|
|
f7dd65 |
|
|
|
f7dd65 |
if (!width) {
|
|
|
f7dd65 |
int height;
|
|
|
f7dd65 |
@@ -144,7 +145,7 @@ const char *edit_cmdline(const char *input, int top /*, int width */ ,
|
|
|
f7dd65 |
|
|
|
f7dd65 |
len = cursor = 0;
|
|
|
f7dd65 |
prev_len = 0;
|
|
|
f7dd65 |
- x = y = 0;
|
|
|
f7dd65 |
+ y = 0;
|
|
|
f7dd65 |
|
|
|
f7dd65 |
/*
|
|
|
f7dd65 |
* Before we start messing with the x,y coordinates print 'input'
|
|
|
f7dd65 |
@@ -152,6 +153,7 @@ const char *edit_cmdline(const char *input, int top /*, int width */ ,
|
|
|
f7dd65 |
* previously.
|
|
|
f7dd65 |
*/
|
|
|
f7dd65 |
printf("%s ", input);
|
|
|
f7dd65 |
+ x = prompt_len;
|
|
|
f7dd65 |
|
|
|
f7dd65 |
while (!done) {
|
|
|
f7dd65 |
if (redraw > 1) {
|
|
|
f7dd65 |
@@ -162,8 +164,7 @@ const char *edit_cmdline(const char *input, int top /*, int width */ ,
|
|
|
f7dd65 |
if (pDraw_Menu)
|
|
|
f7dd65 |
(*pDraw_Menu) (-1, top, 1);
|
|
|
f7dd65 |
prev_len = 0;
|
|
|
f7dd65 |
- printf("\033[2J\033[H");
|
|
|
f7dd65 |
- // printf("\033[0m\033[2J\033[H");
|
|
|
f7dd65 |
+ printf("\033[2J\033[H"); /* Clear entire screen; move to 0, 0. */
|
|
|
f7dd65 |
}
|
|
|
f7dd65 |
|
|
|
f7dd65 |
if (redraw > 0) {
|
|
|
f7dd65 |
@@ -172,10 +173,14 @@ const char *edit_cmdline(const char *input, int top /*, int width */ ,
|
|
|
f7dd65 |
prev_len = max(len, prev_len);
|
|
|
f7dd65 |
|
|
|
f7dd65 |
/* Redraw the command line */
|
|
|
f7dd65 |
- printf("\033[?25l");
|
|
|
f7dd65 |
- printf("\033[1G%s ", input);
|
|
|
f7dd65 |
+ printf("\033[?25l"); /* Hide cursor. */
|
|
|
f7dd65 |
+ printf("\033[1G"); /* Column 1. */
|
|
|
f7dd65 |
+ if (y > 0)
|
|
|
f7dd65 |
+ printf("\033[%dA", y); /* Directly up. */
|
|
|
f7dd65 |
|
|
|
f7dd65 |
- x = strlen(input);
|
|
|
f7dd65 |
+ printf("%s ", input);
|
|
|
f7dd65 |
+
|
|
|
f7dd65 |
+ x = prompt_len;
|
|
|
f7dd65 |
y = 0;
|
|
|
f7dd65 |
at = 0;
|
|
|
f7dd65 |
while (at < prev_len) {
|
|
|
f7dd65 |
@@ -183,23 +188,22 @@ const char *edit_cmdline(const char *input, int top /*, int width */ ,
|
|
|
f7dd65 |
at++;
|
|
|
f7dd65 |
x++;
|
|
|
f7dd65 |
if (x >= width) {
|
|
|
f7dd65 |
- printf("\r\n");
|
|
|
f7dd65 |
x = 0;
|
|
|
f7dd65 |
y++;
|
|
|
f7dd65 |
}
|
|
|
f7dd65 |
}
|
|
|
f7dd65 |
- printf("\033[K\r");
|
|
|
f7dd65 |
+ printf("\033[K\r"); /* Clear to end of line; go to beginning. */
|
|
|
f7dd65 |
|
|
|
f7dd65 |
- dy = y - (cursor + strlen(input) + 1) / width;
|
|
|
f7dd65 |
- x = (cursor + strlen(input) + 1) % width;
|
|
|
f7dd65 |
+ dy = y - (cursor + prompt_len) / width;
|
|
|
f7dd65 |
+ x = (cursor + prompt_len) % width;
|
|
|
f7dd65 |
|
|
|
f7dd65 |
if (dy) {
|
|
|
f7dd65 |
- printf("\033[%dA", dy);
|
|
|
f7dd65 |
+ printf("\033[%dA", dy); /* Cursor directly up. */
|
|
|
f7dd65 |
y -= dy;
|
|
|
f7dd65 |
}
|
|
|
f7dd65 |
if (x)
|
|
|
f7dd65 |
- printf("\033[%dC", x);
|
|
|
f7dd65 |
- printf("\033[?25h");
|
|
|
f7dd65 |
+ printf("\033[%dC", x); /* Cursor forward. */
|
|
|
f7dd65 |
+ printf("\033[?25h"); /* Show cursor. */
|
|
|
f7dd65 |
prev_len = len;
|
|
|
f7dd65 |
redraw = 0;
|
|
|
f7dd65 |
}
|
|
|
f7dd65 |
@@ -439,7 +443,6 @@ const char *edit_cmdline(const char *input, int top /*, int width */ ,
|
|
|
f7dd65 |
cursor++;
|
|
|
f7dd65 |
x++;
|
|
|
f7dd65 |
if (x >= width) {
|
|
|
f7dd65 |
- printf("\r\n\033[K");
|
|
|
f7dd65 |
y++;
|
|
|
f7dd65 |
x = 0;
|
|
|
f7dd65 |
}
|
|
|
f7dd65 |
@@ -459,7 +462,7 @@ const char *edit_cmdline(const char *input, int top /*, int width */ ,
|
|
|
f7dd65 |
}
|
|
|
f7dd65 |
}
|
|
|
f7dd65 |
|
|
|
f7dd65 |
- printf("\033[?7h");
|
|
|
f7dd65 |
+ printf("\033[?7h"); /* Enable line wrap. */
|
|
|
f7dd65 |
|
|
|
f7dd65 |
/* Add the command to the history if its length is larger than 0 */
|
|
|
f7dd65 |
len = strlen(ret);
|