From c57d46a17138343c3da90ebd52bd3d0afff634f3 Mon Sep 17 00:00:00 2001 From: iridiumR Date: Sun, 18 Sep 2022 14:53:38 +0800 Subject: [PATCH] feat(builtin): add clear command --- builtin.c | 14 +++++++++++--- main.c | 11 ++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/builtin.c b/builtin.c index 7e3e604..7541be3 100644 --- a/builtin.c +++ b/builtin.c @@ -2,7 +2,7 @@ * @Author: 1ridic * @Date: 2022-09-18 14:16:19 * @Last Modified by: 1ridic - * @Last Modified time: 2022-09-18 14:28:01 + * @Last Modified time: 2022-09-18 14:52:17 */ #include #include @@ -12,17 +12,20 @@ int dish_cd(char **args); int dish_help(char **args); int dish_exit(char **args); +int dish_clear(char **args); char* builtin_cmd[] = { "cd", "help", - "exit" + "exit", + "clear" }; int (*builtin_func[]) (char **) = { &dish_cd, &dish_help, - &dish_exit + &dish_exit, + &dish_clear }; int dish_cd(char **args) @@ -50,4 +53,9 @@ int dish_exit(char **args) int getBuiltinNum() { return sizeof(builtin_cmd) / sizeof(char *); +} + +int dish_clear(char **args){ + fprintf(stdout,"\033[H\033[J"); + return 0; } \ No newline at end of file diff --git a/main.c b/main.c index 23b4e4b..fab2f99 100644 --- a/main.c +++ b/main.c @@ -2,7 +2,7 @@ * @Author: 1ridic * @Date: 2022-09-18 14:13:59 * @Last Modified by: 1ridic - * @Last Modified time: 2022-09-18 14:21:48 + * @Last Modified time: 2022-09-18 14:53:04 */ #include #include @@ -14,17 +14,18 @@ char volatile isWaiting = 0; void intHandler(int dummy) { if (isWaiting) { return; - printf("\nSIGINT exit.\n"); + fprintf(stderr,"\nSIGINT exit.\n"); exit(EXIT_FAILURE); } } int main(int argc, char *argv[]) { - + /* soft irq */ signal(SIGINT, intHandler); - + /* clear screen */ + fprintf(stdout,"\033[H\033[J"); #ifdef DEBUG - printf("DEBUG is defined\n"); + fprintf(stdout,"DEBUG is defined\n"); #endif while (1) { loop();