Skip to content

Commit 2b5d7bf

Browse files
authored
Update shell.c
add delete key.
1 parent 6229153 commit 2b5d7bf

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

components/finsh/shell.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,33 @@ static void finsh_thread_entry(void *parameter)
607607
shell->line_curpos ++;
608608
}
609609

610+
continue;
611+
}
612+
else if (ch == 0x33) /* delete key */
613+
{
614+
/* note that shell->line_curpos >= 0 */
615+
if (shell->line_curpos < 0)
616+
continue;
617+
618+
if (shell->line_position > shell->line_curpos)
619+
{
620+
rt_kprintf("%c", shell->line[shell->line_curpos]);
621+
shell->line_position--;
622+
623+
int i;
624+
625+
rt_memmove(&shell->line[shell->line_curpos],
626+
&shell->line[shell->line_curpos + 1],
627+
shell->line_position - shell->line_curpos);
628+
shell->line[shell->line_position] = 0;
629+
630+
rt_kprintf("\b%s \b", &shell->line[shell->line_curpos]);
631+
632+
/* move the cursor to the origin position */
633+
for (i = shell->line_curpos; i <= shell->line_position; i++)
634+
rt_kprintf("\b");
635+
}
636+
610637
continue;
611638
}
612639
}

0 commit comments

Comments
 (0)