Add prompt generating (now should be less buggy)
This commit is contained in:
parent
6eae072b19
commit
7a88322f19
20
src/main.c
20
src/main.c
|
@ -17,6 +17,7 @@ char *username; // Current username
|
|||
char *homedir; // HOME directory of current user
|
||||
pid_t shell_pid; // pid of current shell (gets only on start)
|
||||
pid_t pid; // FIXME: this shouldn't be global i think
|
||||
char prompt[2048];
|
||||
|
||||
char **split_line(char *line, char *delim) {
|
||||
int bufsize = 64;
|
||||
|
@ -146,23 +147,19 @@ void init() { // Some initial tasks
|
|||
shell_pid = getpid();
|
||||
}
|
||||
|
||||
void print_ps() {
|
||||
void gen_prompt() {
|
||||
// TODO: add parsing config file
|
||||
// FIXME: add proper PS1 (this is commented because of readline currently)
|
||||
/*
|
||||
if (!strcmp(pwd, homedir)) {
|
||||
printf("%s@%s %s> ", username, hostname, "~");
|
||||
sprintf(prompt, "%s@%s %s> ", username, hostname, "~");
|
||||
} else {
|
||||
printf("%s@%s %s> ", username, hostname, basename(pwd));
|
||||
}*/
|
||||
printf("orsh> ");
|
||||
sprintf(prompt, "%s@%s %s> ", username, hostname, basename(pwd));
|
||||
}
|
||||
}
|
||||
|
||||
void signal_handler(int sig) {
|
||||
if (pid == 0) {
|
||||
if (pid == 0 || shell_pid == getpid()) {
|
||||
printf("\n");
|
||||
print_ps();
|
||||
} else if (shell_pid == getpid()) { // Do nothing because readline prints the prompt
|
||||
printf("%s", prompt);
|
||||
} else
|
||||
raise(sig);
|
||||
|
||||
|
@ -190,7 +187,8 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
} else {
|
||||
while(1) {
|
||||
line = readline("orsh> "); // FIXME: add prompt
|
||||
gen_prompt();
|
||||
line = readline(prompt); // FIXME: add prompt
|
||||
if (line == NULL) {
|
||||
printf("exit\n");
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue