I'm having a weird problem with my current project. Using ncurses I'm making a shell based on lsh, before I introduced ncurses it was working as one would expect with just writing the output from execvp. Now however, the length of the output makes an indent before my prompt which actually also shifts the X coordination with it to the side (so the indent doesn't seem to be part of the line).
I'm thinking it is due to forking into a child process without ncurses (or something along those lines).
You can see the full code here but this here is the part where execvp is run:
int shell_launch(char **args) {
pid_t pid;
int status;
pid = fork();
if (pid == 0) {
// Child process.
// Check if user is trying to run an allowed program.
for (int i = 0; i < arrlen(allowed_cmds); i++) {
if (strcmp(allowed_cmds[i], args[0]) == 0) {
if (execvp(args[0], args) == -1) {
perror("shell");
}
}
}
exit(EXIT_FAILURE);
} else if (pid < 0) {
// Error forking
perror("shell");
} else {
// Parent process
do {
waitpid(pid, &status, WUNTRACED);
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
}
return 1;
}
If you've initialized the screen with ncurses, that's in raw mode, which (among other things) makes newline no longer map to carriage-return/line-feed.
If you're going to run a subshell, then on the way you should restore the terminal modes, and then reinstate the raw mode on return. Those are done with reset_shell_mode and reset_prog_mode.