Skip to content

Update shell.c add delete key. #10224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions components/finsh/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,33 @@ static void finsh_thread_entry(void *parameter)
shell->line_curpos ++;
}

continue;
}
else if (ch == 0x33) /* delete key */
{
/* note that shell->line_curpos >= 0 */
if (shell->line_curpos < 0)
continue;

if (shell->line_position > shell->line_curpos)
{
rt_kprintf("%c", shell->line[shell->line_curpos]);
Copy link
Preview

Copilot AI Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The delete key handler currently prints the character at the cursor, which may lead to unexpected output on the console. Consider removing or revising this output to correctly reflect the deletion.

Suggested change
rt_kprintf("%c", shell->line[shell->line_curpos]);

Copilot uses AI. Check for mistakes.

shell->line_position--;

int i;

rt_memmove(&shell->line[shell->line_curpos],
&shell->line[shell->line_curpos + 1],
shell->line_position - shell->line_curpos);
shell->line[shell->line_position] = 0;

rt_kprintf("\b%s \b", &shell->line[shell->line_curpos]);

/* move the cursor to the origin position */
for (i = shell->line_curpos; i <= shell->line_position; i++)
rt_kprintf("\b");
}

continue;
}
}
Expand Down