feat(builtin): add clear command
This commit is contained in:
parent
0ecd13c0bb
commit
c57d46a171
2 changed files with 17 additions and 8 deletions
14
builtin.c
14
builtin.c
|
@ -2,7 +2,7 @@
|
||||||
* @Author: 1ridic
|
* @Author: 1ridic
|
||||||
* @Date: 2022-09-18 14:16:19
|
* @Date: 2022-09-18 14:16:19
|
||||||
* @Last Modified by: 1ridic
|
* @Last Modified by: 1ridic
|
||||||
* @Last Modified time: 2022-09-18 14:28:01
|
* @Last Modified time: 2022-09-18 14:52:17
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -12,17 +12,20 @@
|
||||||
int dish_cd(char **args);
|
int dish_cd(char **args);
|
||||||
int dish_help(char **args);
|
int dish_help(char **args);
|
||||||
int dish_exit(char **args);
|
int dish_exit(char **args);
|
||||||
|
int dish_clear(char **args);
|
||||||
|
|
||||||
char* builtin_cmd[] = {
|
char* builtin_cmd[] = {
|
||||||
"cd",
|
"cd",
|
||||||
"help",
|
"help",
|
||||||
"exit"
|
"exit",
|
||||||
|
"clear"
|
||||||
};
|
};
|
||||||
|
|
||||||
int (*builtin_func[]) (char **) = {
|
int (*builtin_func[]) (char **) = {
|
||||||
&dish_cd,
|
&dish_cd,
|
||||||
&dish_help,
|
&dish_help,
|
||||||
&dish_exit
|
&dish_exit,
|
||||||
|
&dish_clear
|
||||||
};
|
};
|
||||||
|
|
||||||
int dish_cd(char **args)
|
int dish_cd(char **args)
|
||||||
|
@ -51,3 +54,8 @@ int dish_exit(char **args)
|
||||||
int getBuiltinNum() {
|
int getBuiltinNum() {
|
||||||
return sizeof(builtin_cmd) / sizeof(char *);
|
return sizeof(builtin_cmd) / sizeof(char *);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int dish_clear(char **args){
|
||||||
|
fprintf(stdout,"\033[H\033[J");
|
||||||
|
return 0;
|
||||||
|
}
|
11
main.c
11
main.c
|
@ -2,7 +2,7 @@
|
||||||
* @Author: 1ridic
|
* @Author: 1ridic
|
||||||
* @Date: 2022-09-18 14:13:59
|
* @Date: 2022-09-18 14:13:59
|
||||||
* @Last Modified by: 1ridic
|
* @Last Modified by: 1ridic
|
||||||
* @Last Modified time: 2022-09-18 14:21:48
|
* @Last Modified time: 2022-09-18 14:53:04
|
||||||
*/
|
*/
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -14,17 +14,18 @@ char volatile isWaiting = 0;
|
||||||
void intHandler(int dummy) {
|
void intHandler(int dummy) {
|
||||||
if (isWaiting) {
|
if (isWaiting) {
|
||||||
return;
|
return;
|
||||||
printf("\nSIGINT exit.\n");
|
fprintf(stderr,"\nSIGINT exit.\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
/* soft irq */
|
||||||
signal(SIGINT, intHandler);
|
signal(SIGINT, intHandler);
|
||||||
|
/* clear screen */
|
||||||
|
fprintf(stdout,"\033[H\033[J");
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("DEBUG is defined\n");
|
fprintf(stdout,"DEBUG is defined\n");
|
||||||
#endif
|
#endif
|
||||||
while (1) {
|
while (1) {
|
||||||
loop();
|
loop();
|
||||||
|
|
Loading…
Reference in a new issue