Skip to content

[Feature][Shell] 增加对 Home、Insert、Delete 和 End 键的支持,改进输入模式处理 #10595

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

Conversation

meng-plus
Copy link
Contributor

@meng-plus meng-plus commented Aug 9, 2025

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

补全交互操作

你的解决方案是什么 (what is your solution)

增加交互处理逻辑

请提供验证的bsp和config (provide the config and bsp)

  • BSP:
  • .config:
  • action:

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/workflows/bsp_buildings.yml 详细请参考链接BSP自查

@Copilot Copilot AI review requested due to automatic review settings August 9, 2025 17:54
Copy link

github-actions bot commented Aug 9, 2025

📌 Code Review Assignment

🏷️ Tag: components

Reviewers: Maihuanyi

Changed Files (Click to expand)
  • components/finsh/shell.c
  • components/finsh/shell.h

📊 Current Review Status (Last Updated: 2025-08-12 09:18 CST)

  • Maihuanyi Pending Review

📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for Home, Insert, Delete, and End key functionality to the finsh shell component, along with improved input mode handling. The changes enhance the shell's text editing capabilities by implementing standard terminal key bindings and introducing an overwrite/insert mode toggle.

  • Adds new WAIT_EXT_KEY state to handle extended key sequences for Home, Insert, Delete, and End keys
  • Implements an overwrite mode toggle that can be controlled via the Insert key
  • Refactors character insertion logic to properly handle both insert and overwrite modes

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
components/finsh/shell.h Adds new input state WAIT_EXT_KEY and overwrite_mode flag to shell structure
components/finsh/shell.c Implements extended key handling logic and improved character insertion with mode support

Comment on lines +685 to +686
shell->stat = WAIT_EXT_KEY;
shell->line[shell->line_position + 1] = ch; /* store the key code */
Copy link
Preview

Copilot AI Aug 9, 2025

Choose a reason for hiding this comment

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

Storing the key code at shell->line_position + 1 could cause buffer overflow or corrupt user input data. The shell->line buffer is used for command input and overwriting it with key codes can lead to unexpected behavior. Consider using a separate temporary variable to store the key code.

Suggested change
shell->stat = WAIT_EXT_KEY;
shell->line[shell->line_position + 1] = ch; /* store the key code */
shell->stat = WAIT_EXT_KEY;
shell->ext_key_code = ch; /* store the key code in a dedicated variable */

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

新增一个没必要 在line的缓存区申请中就已经有个多余的字节放在了最后 可以利用起来 不会产生越界操作


if (ch == 0x7E) /* extended key terminator */
{
rt_uint8_t key_code = shell->line[shell->line_position + 1];
Copy link
Preview

Copilot AI Aug 9, 2025

Choose a reason for hiding this comment

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

Reading the key code from shell->line_position + 1 is problematic because this location in the buffer may contain user input data or be out of bounds. This creates a dependency on the previous problematic storage at line 686 and could lead to incorrect key code interpretation.

Suggested change
rt_uint8_t key_code = shell->line[shell->line_position + 1];
rt_uint8_t key_code = shell_ext_key_code;

Copilot uses AI. Check for mistakes.

/* move existing characters to the right */
rt_memmove(&shell->line[shell->line_curpos + 1],
&shell->line[shell->line_curpos],
shell->line_position - shell->line_curpos + 1);
Copy link
Preview

Copilot AI Aug 9, 2025

Choose a reason for hiding this comment

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

Adding + 1 to the memmove length could cause buffer overflow. The original calculation shell->line_position - shell->line_curpos correctly represents the number of characters to move. The extra + 1 could copy beyond the intended range and potentially access uninitialized memory or overwrite the null terminator.

Suggested change
shell->line_position - shell->line_curpos + 1);
shell->line_position - shell->line_curpos);

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

shell->line_position是有效数据长度 但是缺少字符串结束符'\0' 因此需要+1

@illustriousness
Copy link
Contributor

作者可以看一下这个 #10394 (comment)

@meng-plus
Copy link
Contributor Author

作者可以看一下这个 #10394 (comment)

对比看了一下 你那边属于增加功能 我补充的这点应该归属于基础操作 del ins都不支持 用起来 太难受了

@supperthomas
Copy link
Member

image

CI问题需要处理一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants