title: Using ncurses in conjunction wth execvp
body: <p>I am writing a shell project in C for a class and I decided I wanted to implement arrow-key command history in the shell as an extra feature.  After calling <code>initscr()</code>, everything prints out correctly, but when I call <code>execvp()</code> inside of a fork to execute shell commands and display the result on the screen, things get a little wacky.  I read <a href="https://stackoverflow.com/questions/52181084/execvp-output-creates-indent-for-ncurses">this post</a> and learned that to avoid those indents from the execvp output, I can use <code>reset_shell_mode()</code> followed by <code>reset_prog_mode()</code>.  When I do this, the execvp command prints fine, but <code>reset_prog_mode()</code> doesn't seem to work correctly if the execvp command works correctly.  Here is some code that demonstrates the problem area.</p>
  <pre class="lang-c prettyprint-override"><code>pid = fork();
  if (pid == 0) {
      reset_shell_mode();
      execvp(command, args);
      reset_prog_mode();
      refresh();
      printw(&quot;error&quot;); // prints correctly
  }
  else {
      usleep(1000);
      waitpid(pid, &amp;status, 0); // status is defined, just not in this snippet
      reset_prog_mode();
      refresh();
      printw(&quot;completed&quot;); // never prints - printw is scuffed from this point on.  getstr() works tho.
  }
  </code></pre>
  <p>I'm almost certain that my problem has everything to do with the fork and where I place <code>reset_prog_mode()</code> after successful execvp completion, but I don't know how to fix it.</p>