mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-05-20 11:04:21 +08:00
[Feature][Shell] 增加对 Home、Insert、Delete 和 End 键的支持,改进输入模式处理 (#10595)
RT-Thread BSP Static Build Check / 🔍 Summary of Git Diff Changes (push) Has been cancelled
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (push) Has been cancelled
RT-Thread BSP Static Build Check / collect-artifacts (push) Has been cancelled
doc_doxygen / doxygen_doc generate (push) Has been cancelled
doc_doxygen / deploy (push) Has been cancelled
pkgs_test / change (push) Has been cancelled
utest_auto_run / A9 :components/dfs.cfg (push) Has been cancelled
utest_auto_run / A9 :components/lwip.cfg (push) Has been cancelled
utest_auto_run / A9 :components/netdev.cfg (push) Has been cancelled
utest_auto_run / A9 :cpp11/cpp11.cfg (push) Has been cancelled
utest_auto_run / AARCH64-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64 :default.cfg (push) Has been cancelled
utest_auto_run / A9 :default.cfg (push) Has been cancelled
utest_auto_run / A9-smp :default.cfg (push) Has been cancelled
utest_auto_run / RISCV :default.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/mem.cfg (push) Has been cancelled
ToolsCI / Tools (push) Has been cancelled
RT-Thread BSP Static Build Check / 🔍 Summary of Git Diff Changes (push) Has been cancelled
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (push) Has been cancelled
RT-Thread BSP Static Build Check / collect-artifacts (push) Has been cancelled
doc_doxygen / doxygen_doc generate (push) Has been cancelled
doc_doxygen / deploy (push) Has been cancelled
pkgs_test / change (push) Has been cancelled
utest_auto_run / A9 :components/dfs.cfg (push) Has been cancelled
utest_auto_run / A9 :components/lwip.cfg (push) Has been cancelled
utest_auto_run / A9 :components/netdev.cfg (push) Has been cancelled
utest_auto_run / A9 :cpp11/cpp11.cfg (push) Has been cancelled
utest_auto_run / AARCH64-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64 :default.cfg (push) Has been cancelled
utest_auto_run / A9 :default.cfg (push) Has been cancelled
utest_auto_run / A9-smp :default.cfg (push) Has been cancelled
utest_auto_run / RISCV :default.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/mem.cfg (push) Has been cancelled
ToolsCI / Tools (push) Has been cancelled
This commit is contained in:
@@ -42,6 +42,12 @@ if RT_USING_MSH
|
||||
help
|
||||
Enable Ctrl+Backspace to delete words and Ctrl+Arrow to move cursor by word
|
||||
|
||||
config FINSH_USING_FUNC_EXT
|
||||
bool "Enable function extension home end ins del"
|
||||
default n
|
||||
help
|
||||
Enable function extension home end ins del.
|
||||
|
||||
config FINSH_USING_SYMTAB
|
||||
bool "Using symbol table for commands"
|
||||
default y
|
||||
|
||||
+97
-12
@@ -558,6 +558,10 @@ static void finsh_thread_entry(void *parameter)
|
||||
* down key: 0x1b 0x5b 0x42
|
||||
* right key:0x1b 0x5b 0x43
|
||||
* left key: 0x1b 0x5b 0x44
|
||||
* home : 0x1b 0x5b 0x31 0x7E
|
||||
* insert : 0x1b 0x5b 0x32 0x7E
|
||||
* del : 0x1b 0x5b 0x33 0x7E
|
||||
* end : 0x1b 0x5b 0x34 0x7E
|
||||
*/
|
||||
if (ch == 0x1b)
|
||||
{
|
||||
@@ -676,6 +680,69 @@ static void finsh_thread_entry(void *parameter)
|
||||
}
|
||||
}
|
||||
#endif /*defined(FINSH_USING_WORD_OPERATION) */
|
||||
#if defined(FINSH_USING_FUNC_EXT)
|
||||
else if (ch >= 0x31 && ch <= 0x34) /* home(0x31), insert(0x32), del(0x33), end(0x34) */
|
||||
{
|
||||
shell->stat = WAIT_EXT_KEY;
|
||||
shell->line[shell->line_position + 1] = ch; /* store the key code */
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
else if (shell->stat == WAIT_EXT_KEY)
|
||||
{
|
||||
shell->stat = WAIT_NORMAL;
|
||||
|
||||
if (ch == 0x7E) /* extended key terminator */
|
||||
{
|
||||
rt_uint8_t key_code = shell->line[shell->line_position + 1];
|
||||
|
||||
if (key_code == 0x31) /* home key */
|
||||
{
|
||||
/* move cursor to beginning of line */
|
||||
while (shell->line_curpos > 0)
|
||||
{
|
||||
rt_kprintf("\b");
|
||||
shell->line_curpos--;
|
||||
}
|
||||
}
|
||||
else if (key_code == 0x32) /* insert key */
|
||||
{
|
||||
/* toggle insert mode */
|
||||
shell->overwrite_mode = !shell->overwrite_mode;
|
||||
}
|
||||
else if (key_code == 0x33) /* del key */
|
||||
{
|
||||
/* delete character at current cursor position */
|
||||
if (shell->line_curpos < shell->line_position)
|
||||
{
|
||||
int i;
|
||||
shell->line_position--;
|
||||
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("%s ", &shell->line[shell->line_curpos]);
|
||||
|
||||
/* move cursor back to original position */
|
||||
for (i = shell->line_curpos; i <= shell->line_position; i++)
|
||||
rt_kprintf("\b");
|
||||
}
|
||||
}
|
||||
else if (key_code == 0x34) /* end key */
|
||||
{
|
||||
/* move cursor to end of line */
|
||||
while (shell->line_curpos < shell->line_position)
|
||||
{
|
||||
rt_kprintf("%c", shell->line[shell->line_curpos]);
|
||||
shell->line_curpos++;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
#endif /*defined(FINSH_USING_FUNC_EXT) */
|
||||
}
|
||||
|
||||
/* received null or error */
|
||||
@@ -789,28 +856,46 @@ static void finsh_thread_entry(void *parameter)
|
||||
if (shell->line_curpos < shell->line_position)
|
||||
{
|
||||
int i;
|
||||
#if defined(FINSH_USING_FUNC_EXT)
|
||||
if (shell->overwrite_mode) /* overwrite mode */
|
||||
{
|
||||
/* directly overwrite the character */
|
||||
shell->line[shell->line_curpos] = ch;
|
||||
if (shell->echo_mode)
|
||||
rt_kprintf("%c", ch);
|
||||
shell->line_curpos++;
|
||||
}
|
||||
else /* insert mode */
|
||||
#endif /*defined(FINSH_USING_FUNC_EXT)*/
|
||||
{
|
||||
shell->line_position++;
|
||||
/* 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);
|
||||
shell->line[shell->line_curpos] = ch;
|
||||
|
||||
rt_memmove(&shell->line[shell->line_curpos + 1],
|
||||
&shell->line[shell->line_curpos],
|
||||
shell->line_position - shell->line_curpos);
|
||||
shell->line[shell->line_curpos] = ch;
|
||||
if (shell->echo_mode)
|
||||
rt_kprintf("%s", &shell->line[shell->line_curpos]);
|
||||
|
||||
/* move the cursor to new position */
|
||||
for (i = shell->line_curpos; i < shell->line_position; i++)
|
||||
rt_kprintf("\b");
|
||||
if (shell->echo_mode)
|
||||
{
|
||||
rt_kprintf("%s", &shell->line[shell->line_curpos]);
|
||||
/* move cursor back to correct position */
|
||||
for (i = shell->line_curpos + 1; i < shell->line_position; i++)
|
||||
rt_kprintf("\b");
|
||||
}
|
||||
shell->line_curpos++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* append character at end of line */
|
||||
shell->line[shell->line_position] = ch;
|
||||
if (shell->echo_mode)
|
||||
rt_kprintf("%c", ch);
|
||||
shell->line_position++;
|
||||
shell->line_curpos++;
|
||||
}
|
||||
|
||||
ch = 0;
|
||||
shell->line_position ++;
|
||||
shell->line_curpos++;
|
||||
if (shell->line_position >= FINSH_CMD_SIZE)
|
||||
{
|
||||
/* clear command line */
|
||||
|
||||
@@ -57,6 +57,7 @@ enum input_stat
|
||||
WAIT_NORMAL,
|
||||
WAIT_SPEC_KEY,
|
||||
WAIT_FUNC_KEY,
|
||||
WAIT_EXT_KEY,
|
||||
};
|
||||
struct finsh_shell
|
||||
{
|
||||
@@ -66,7 +67,7 @@ struct finsh_shell
|
||||
|
||||
rt_uint8_t echo_mode: 1;
|
||||
rt_uint8_t prompt_mode: 1;
|
||||
|
||||
rt_uint8_t overwrite_mode: 1;
|
||||
#ifdef FINSH_USING_HISTORY
|
||||
rt_uint16_t current_history;
|
||||
rt_uint16_t history_count;
|
||||
|
||||
Reference in New Issue
Block a user