-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[update] <components>:finsh/shell.c 增加新功能 #10394
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||||||
| /* | ||||||||||
| * Copyright (c) 2006-2021, RT-Thread Development Team | ||||||||||
| * Copyright (c) 2006-2025, RT-Thread Development Team | ||||||||||
| * | ||||||||||
| * SPDX-License-Identifier: Apache-2.0 | ||||||||||
| * | ||||||||||
|
|
@@ -457,6 +457,37 @@ static void shell_push_history(struct finsh_shell *shell) | |||||||||
| } | ||||||||||
| #endif | ||||||||||
|
|
||||||||||
| #if defined(FINSH_USING_WORD_OPERATION) | ||||||||||
| static int find_prev_word_start(const char *line, int curpos) | ||||||||||
| { | ||||||||||
| if (curpos <= 0) return 0; | ||||||||||
|
|
||||||||||
| /* Skip whitespace */ | ||||||||||
| while (--curpos > 0 && (line[curpos] == ' ' || line[curpos] == '\t')); | ||||||||||
|
|
||||||||||
| /* Find word start */ | ||||||||||
| while (curpos > 0 && !(line[curpos] == ' ' || line[curpos] == '\t')) | ||||||||||
| curpos--; | ||||||||||
|
|
||||||||||
| return (curpos <= 0) ? 0 : curpos + 1; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| static int find_next_word_end(const char *line, int curpos, int max) | ||||||||||
| { | ||||||||||
| if (curpos >= max) return max; | ||||||||||
|
|
||||||||||
| /* Skip to next word */ | ||||||||||
| while (curpos < max && (line[curpos] == ' ' || line[curpos] == '\t')) | ||||||||||
| curpos++; | ||||||||||
|
|
||||||||||
| /* Find word end */ | ||||||||||
| while (curpos < max && !(line[curpos] == ' ' || line[curpos] == '\t')) | ||||||||||
| curpos++; | ||||||||||
|
|
||||||||||
| return curpos; | ||||||||||
| } | ||||||||||
| #endif /* defined(FINSH_USING_WORD_OPERATION) */ | ||||||||||
|
|
||||||||||
| #ifdef RT_USING_HOOK | ||||||||||
| static void (*_finsh_thread_entry_hook)(void); | ||||||||||
|
|
||||||||||
|
|
@@ -609,6 +640,42 @@ static void finsh_thread_entry(void *parameter) | |||||||||
|
|
||||||||||
| continue; | ||||||||||
| } | ||||||||||
| #if defined(FINSH_USING_WORD_OPERATION) | ||||||||||
| /* Add Ctrl+Left/Right handling */ | ||||||||||
| else if (ch == '1') | ||||||||||
| { | ||||||||||
| /* Read modifier sequence [1;5D/C] */ | ||||||||||
| int next_ch = finsh_getchar(); | ||||||||||
| if (next_ch == ';') | ||||||||||
| { | ||||||||||
| next_ch = finsh_getchar(); | ||||||||||
| if (next_ch == '5') | ||||||||||
| { | ||||||||||
| next_ch = finsh_getchar(); | ||||||||||
| if (next_ch == 'D') /* Ctrl+Left */ | ||||||||||
| { | ||||||||||
| int new_pos = find_prev_word_start(shell->line, shell->line_curpos); | ||||||||||
| if (new_pos != shell->line_curpos) | ||||||||||
| { | ||||||||||
| rt_kprintf("\033[%dD", shell->line_curpos - new_pos); | ||||||||||
| shell->line_curpos = new_pos; | ||||||||||
| } | ||||||||||
| continue; | ||||||||||
| } | ||||||||||
| else if (next_ch == 'C') /* Ctrl+Right */ | ||||||||||
| { | ||||||||||
| int new_pos = find_next_word_end(shell->line, shell->line_curpos, shell->line_position); | ||||||||||
| if (new_pos != shell->line_curpos) | ||||||||||
| { | ||||||||||
| rt_kprintf("\033[%dC", new_pos - shell->line_curpos); | ||||||||||
| shell->line_curpos = new_pos; | ||||||||||
| } | ||||||||||
| continue; | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| #endif /*defined(FINSH_USING_WORD_OPERATION) */ | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /* received null or error */ | ||||||||||
|
|
@@ -661,7 +728,43 @@ static void finsh_thread_entry(void *parameter) | |||||||||
|
|
||||||||||
| continue; | ||||||||||
| } | ||||||||||
| #if defined(FINSH_USING_WORD_OPERATION) | ||||||||||
| /* Add Ctrl+Backspace handling */ | ||||||||||
| else if (ch == 0x17) /* Ctrl+Backspace (typically ^W) */ | ||||||||||
|
Comment on lines
+732
to
+733
|
||||||||||
| /* Add Ctrl+Backspace handling */ | |
| else if (ch == 0x17) /* Ctrl+Backspace (typically ^W) */ | |
| /* Add Ctrl+W (delete previous word) handling */ | |
| else if (ch == 0x17) /* Ctrl+W (delete previous word) */ |
Copilot
AI
Aug 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The calculation new_len - start + 1 for the memmove length appears incorrect. It should be shell->line_position - start - del_count to move the remaining characters after the deleted word.
| new_len - start + 1); | |
| shell->line_position - start - del_count); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The loop uses pre-decrement
--curposin the condition, which could cause the function to skip checking the character at the initial position. This may lead to incorrect word boundary detection.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果当前curpos 为空格 跳过就跳过了
如果不是空格 预减也不影响