mirror of
https://github.com/NevermindZZT/letter-shell.git
synced 2025-01-21 10:02:54 +08:00
修复 passthrough模式bug
新增 passthrough直接单次透传
This commit is contained in:
parent
3da93f4c03
commit
6c555d42ea
@ -130,3 +130,12 @@
|
||||
- 退出
|
||||
|
||||
使用组合键`Ctrl + D`退出`passthrough`,键值可以在`shell_passthrough.h`文件中的`SHELL_PASSTHROUGH_EXIT_KEY`宏修改
|
||||
|
||||
- 单次调用
|
||||
|
||||
某些情况下,使用`passthrough`模式时,我们可能只需要单词数据的透传,此时可以不进入`passthrough`命令行,直接调用命令带上透传的数据即可
|
||||
|
||||
```sh
|
||||
letter:/mnt/f/Github/letter shell/demo/x86-gcc$ passTest "hello world"
|
||||
passthrough mode test, data: hello world, len: 11
|
||||
```
|
||||
|
@ -9,6 +9,7 @@
|
||||
*
|
||||
*/
|
||||
#include "shell_passthrough.h"
|
||||
#include "string.h"
|
||||
|
||||
/**
|
||||
* @brief shell passthrough 模式
|
||||
@ -16,38 +17,49 @@
|
||||
* @param shell shell
|
||||
* @param prompt passthrough 提示符
|
||||
* @param handler pssthrough handler
|
||||
* @param argc 命令行参数数量
|
||||
* @param argv 命令行参数
|
||||
*
|
||||
* @return unsigned int 返回值
|
||||
*/
|
||||
unsigned int shellPassthrough(Shell *shell, const char *prompt, ShellPassthrough handler)
|
||||
unsigned int shellPassthrough(Shell *shell, const char *prompt, ShellPassthrough handler, int argc, char *argv[])
|
||||
{
|
||||
char data;
|
||||
|
||||
shell->status.isActive = 0;
|
||||
shellWriteString(shell, prompt);
|
||||
while (1)
|
||||
if (argc > 1)
|
||||
{
|
||||
if (shell->read && shell->read(&data, 1) == 1)
|
||||
handler(argv[1], strlen(argv[1]));
|
||||
}
|
||||
else
|
||||
{
|
||||
shell->status.isActive = 0;
|
||||
shellWriteString(shell, prompt);
|
||||
while (1)
|
||||
{
|
||||
if (data == '\r' || data == '\n')
|
||||
if (shell->read && shell->read(&data, 1) == 1)
|
||||
{
|
||||
if (shell->parser.length == 0)
|
||||
if (data == '\r' || data == '\n')
|
||||
{
|
||||
continue;
|
||||
if (shell->parser.length == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
shellWriteString(shell, "\r\n");
|
||||
shell->parser.buffer[shell->parser.length] = 0;
|
||||
handler(shell->parser.buffer, shell->parser.length);
|
||||
shell->parser.length = 0;
|
||||
shell->parser.cursor = 0;
|
||||
shellWriteString(shell, prompt);
|
||||
}
|
||||
else if (data == SHELL_PASSTHROUGH_EXIT_KEY)
|
||||
{
|
||||
shellWriteString(shell, "\r\n");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
shellHandler(shell, data);
|
||||
}
|
||||
shellWriteString(shell, "\r\n");
|
||||
shell->parser.buffer[shell->parser.length] = 0;
|
||||
handler(shell->parser.buffer, shell->parser.length);
|
||||
shellWriteString(shell, prompt);
|
||||
}
|
||||
else if (data == SHELL_PASSTHROUGH_EXIT_KEY)
|
||||
{
|
||||
shellWriteString(shell, "\r\n");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
shellHandler(shell, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,8 +41,8 @@ typedef int (*ShellPassthrough)(char *data, unsigned short len);
|
||||
* @param _handler passthrough 模式 handler
|
||||
*/
|
||||
#define SHELL_PASSTROUGH_FUNC(_name, _prompt, _handler) \
|
||||
void SHELL_PASSTROUGH_FUNC_NAME(_name)(void) \
|
||||
{ shellPassthrough(shellGetCurrent(), #_prompt, _handler); }
|
||||
void SHELL_PASSTROUGH_FUNC_NAME(_name)(int p1, int p2) \
|
||||
{ shellPassthrough(shellGetCurrent(), #_prompt, _handler, p1, (void *)p2); }
|
||||
|
||||
/**
|
||||
* @brief shell passthrouh 定义
|
||||
@ -55,8 +55,8 @@ typedef int (*ShellPassthrough)(char *data, unsigned short len);
|
||||
*/
|
||||
#define SHELL_EXPORT_PASSTROUGH(_attr, _name, _prompt, _handler, _desc) \
|
||||
SHELL_PASSTROUGH_FUNC(_name, _prompt, _handler) \
|
||||
SHELL_EXPORT_CMD(_attr|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC), _name, SHELL_PASSTROUGH_FUNC_NAME(_name), _desc)
|
||||
SHELL_EXPORT_CMD(_attr|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), _name, SHELL_PASSTROUGH_FUNC_NAME(_name), _desc)
|
||||
|
||||
unsigned int shellPassthrough(Shell *shell, const char *prompt, ShellPassthrough handler);
|
||||
unsigned int shellPassthrough(Shell *shell, const char *prompt, ShellPassthrough handler, int argc, char *argv[]);
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user