Fixed a potential infinite loop. First delete any chars after the
cursor, then delete everything before it. Before this, we would just delete everything before the cursor and freak out if there were still chars left (i.e. stuff after the cursor). -Erik
This commit is contained in:
11
cmdedit.c
11
cmdedit.c
@ -143,6 +143,12 @@ void input_backspace(char* command, int outputFd, int *cursor, int *len)
|
|||||||
{
|
{
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
|
||||||
|
/* Debug crap */
|
||||||
|
//fprintf(stderr, "\nerik: len=%d, cursor=%d, strlen(command)='%d'\n", *len, *cursor, strlen(command));
|
||||||
|
//xwrite(outputFd, command, *len);
|
||||||
|
//*cursor = *len;
|
||||||
|
|
||||||
|
|
||||||
if (*cursor > 0) {
|
if (*cursor > 0) {
|
||||||
xwrite(outputFd, "\b \b", 3);
|
xwrite(outputFd, "\b \b", 3);
|
||||||
--*cursor;
|
--*cursor;
|
||||||
@ -534,7 +540,10 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
|
|||||||
rewrite_line:
|
rewrite_line:
|
||||||
/* erase old command from command line */
|
/* erase old command from command line */
|
||||||
len = strlen(command)-strlen(hp->s);
|
len = strlen(command)-strlen(hp->s);
|
||||||
while (len>0)
|
|
||||||
|
while (len>cursor)
|
||||||
|
input_delete(command, outputFd, cursor, &len);
|
||||||
|
while (cursor>0)
|
||||||
input_backspace(command, outputFd, &cursor, &len);
|
input_backspace(command, outputFd, &cursor, &len);
|
||||||
input_home(outputFd, &cursor);
|
input_home(outputFd, &cursor);
|
||||||
|
|
||||||
|
@ -143,6 +143,12 @@ void input_backspace(char* command, int outputFd, int *cursor, int *len)
|
|||||||
{
|
{
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
|
||||||
|
/* Debug crap */
|
||||||
|
//fprintf(stderr, "\nerik: len=%d, cursor=%d, strlen(command)='%d'\n", *len, *cursor, strlen(command));
|
||||||
|
//xwrite(outputFd, command, *len);
|
||||||
|
//*cursor = *len;
|
||||||
|
|
||||||
|
|
||||||
if (*cursor > 0) {
|
if (*cursor > 0) {
|
||||||
xwrite(outputFd, "\b \b", 3);
|
xwrite(outputFd, "\b \b", 3);
|
||||||
--*cursor;
|
--*cursor;
|
||||||
@ -534,7 +540,10 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
|
|||||||
rewrite_line:
|
rewrite_line:
|
||||||
/* erase old command from command line */
|
/* erase old command from command line */
|
||||||
len = strlen(command)-strlen(hp->s);
|
len = strlen(command)-strlen(hp->s);
|
||||||
while (len>0)
|
|
||||||
|
while (len>cursor)
|
||||||
|
input_delete(command, outputFd, cursor, &len);
|
||||||
|
while (cursor>0)
|
||||||
input_backspace(command, outputFd, &cursor, &len);
|
input_backspace(command, outputFd, &cursor, &len);
|
||||||
input_home(outputFd, &cursor);
|
input_home(outputFd, &cursor);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user