tty支持&vi完整支持
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
int ls(int argc, char *agrv[])
|
||||
{
|
||||
DIR *dir;
|
||||
@@ -117,7 +118,7 @@ int cat(int argc, char *argv[])
|
||||
|
||||
while ((c = fgetc(fp)) != EOF)
|
||||
{
|
||||
cons_write((uint8_t *)&c, 1);
|
||||
write(STDOUT_FILENO, (uint8_t *)&c, 1);
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
@@ -178,8 +179,7 @@ int shell_symlink(int argc, char *argv[])
|
||||
return symlink(argv[1], argv[2]);
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), symlink, shell_symlink, symlink command);
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
int shell_touch(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 2)
|
||||
|
||||
@@ -23,6 +23,10 @@
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <pthread.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <termios.h>
|
||||
#include <sys/stat.h>
|
||||
#include "cons_cli.h"
|
||||
#include "u_sleep.h"
|
||||
#include "u_sema.h"
|
||||
@@ -41,8 +45,7 @@ static char shellBuffer[512];
|
||||
* @return unsigned short 写入实际长度
|
||||
*/
|
||||
signed short userShellWrite(char *data, unsigned short len)
|
||||
{
|
||||
return cons_write((const char *)data, len);
|
||||
{ return write(STDOUT_FILENO, data, len);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,13 +60,7 @@ signed short userShellRead(char *data, unsigned short len)
|
||||
{
|
||||
int rlen;
|
||||
|
||||
again:
|
||||
rlen = cons_read((uint8_t *)data, len);
|
||||
if (rlen <= 0)
|
||||
{
|
||||
u_sema_down(SEMA_PROT, 0, NULL);
|
||||
goto again;
|
||||
}
|
||||
rlen = read(STDIN_FILENO, data, len);
|
||||
return rlen;
|
||||
}
|
||||
/**
|
||||
@@ -98,12 +95,29 @@ size_t userShellListDir(char *path, char *buffer, size_t maxLen)
|
||||
closedir(dir);
|
||||
return 0;
|
||||
}
|
||||
static struct termios old_settings;
|
||||
static struct termios new_settings;
|
||||
|
||||
void tty_set_raw_mode(void)
|
||||
{
|
||||
new_settings = old_settings;
|
||||
new_settings.c_lflag &= ~(ICANON | ECHO); // 禁用规范模式和回显
|
||||
new_settings.c_cc[VMIN] = 1; // 读取的最小字符数
|
||||
new_settings.c_cc[VTIME] = 0; // 读取的超时时间(以10ms为单位)
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &new_settings);
|
||||
}
|
||||
void tty_set_normal_mode(void)
|
||||
{
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &old_settings);
|
||||
}
|
||||
/**
|
||||
* @brief 用户shell初始化
|
||||
*
|
||||
*/
|
||||
void userShellInit(void)
|
||||
{
|
||||
tcgetattr(STDIN_FILENO, &old_settings);
|
||||
tty_set_raw_mode();
|
||||
task_set_obj_name(TASK_THIS, TASK_THIS, "tk_shell");
|
||||
task_set_obj_name(TASK_THIS, THREAD_MAIN, "th_shell");
|
||||
// shellFs.getcwd = getcwd;
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
#include "stdarg.h"
|
||||
#include "shell_ext.h"
|
||||
#include "fs_types.h"
|
||||
#include "u_sig.h"
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#if SHELL_USING_CMD_EXPORT == 1
|
||||
/**
|
||||
* @brief 默认用户
|
||||
@@ -234,7 +237,7 @@ void shellInit(Shell *shell, char *buffer, unsigned short size)
|
||||
else if (cmd->attr.attrs.type <= SHELL_TYPE_KEY)
|
||||
{
|
||||
cmd->data.key.desc += start_addr;
|
||||
cmd->data.key.function = (void*)(int (*)())((unsigned long)cmd->data.key.function + start_addr | 0x1);
|
||||
cmd->data.key.function = (void *)(int (*)())((unsigned long)cmd->data.key.function + start_addr | 0x1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1454,6 +1457,7 @@ void shellExec(Shell *shell)
|
||||
{
|
||||
uint8_t params[FS_RPC_BUF_LEN];
|
||||
int params_len = 0;
|
||||
int pid;
|
||||
|
||||
for (int i = 1; i < shell->parser.paramCount; i++)
|
||||
{
|
||||
@@ -1461,10 +1465,31 @@ void shellExec(Shell *shell)
|
||||
params_len += strlen(shell->parser.param[i]) + 1;
|
||||
}
|
||||
//!< 内建命令中未找到,则执行应用
|
||||
if (pm_run_app(shell->parser.param[0], PM_APP_BG_RUN/*PM_APP_BG_RUN*/, params, params_len) < 0)
|
||||
pid = pm_run_app(shell->parser.param[0], 0 /*PM_APP_BG_RUN*/, params, params_len);
|
||||
if (pid < 0)
|
||||
{
|
||||
shellWriteString(shell, shellText[SHELL_TEXT_CMD_NOT_FOUND]);
|
||||
}
|
||||
else
|
||||
{
|
||||
pid_t cur_pid;
|
||||
|
||||
if (strcmp(shell->parser.param[shell->parser.paramCount - 1], "&") != 0)
|
||||
{
|
||||
shell->parser.param[shell->parser.paramCount - 1] = NULL;
|
||||
shell->parser.paramCount--;
|
||||
task_get_pid(TASK_THIS, &cur_pid);
|
||||
pm_sig_watch(pid, 0);
|
||||
extern void tty_set_raw_mode(void);
|
||||
extern void tty_set_normal_mode(void);
|
||||
|
||||
tty_set_normal_mode();
|
||||
tcsetpgrp(STDIN_FILENO, pid);
|
||||
pm_waitpid(pid, NULL);
|
||||
tcsetpgrp(STDIN_FILENO, cur_pid);
|
||||
tty_set_raw_mode();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user