title: Input bar at console bottom in C
body: <h2>Window bottom</h2>
  
  <p>Some applications like vim, mutt, aptitude contain </p>
  
  <ul>
  <li>a top window section for output and </li>
  <li>a bottom section for the user to type in or for status display.</li>
  </ul>
  
  <p>(Suppose there is one child process to output and another one to take user input. The purpose is to allow for updated output at the same time as you are typing the input or viewing the status.)</p>
  
  <pre><code>Actions  Undo  Package  Resolver  Search  Options  Views  Help
  C-T: Menu  ?: Help  q: Quit  u: Update  g: Download/Install/Remove Pkgs
  
  
  
                                                                              |
                                                                              |
                                                                              |
                                                                              |
                                                                              |
                              ┌─────────────┐                                 |
                              │Loading cache│                                 |
                              └─────────────┘                                 |
                                                                              |
                                                                              |
                                                                              |
                                                                              |
                                                                              |
                                                                              |    
                                                                              |
  --------------------------------------------------------------------------- |
  Initialising package states                                            100% |
  </code></pre>
  
  <hr>
  
  <pre><code>+-------------------------------------------------------+
  | some output here                                      |
  |                                                       |
  |                                                       |
  |                                                       |
  |                                                       |
  |                                                       |
  |-------------------------------------------------------+
  |:input here                                            |
  +-------------------------------------------------------+
  </code></pre>
  
  <p><a href="http://www.tldp.org/HOWTO/NCURSES-Programming-HOWTO/" rel="nofollow noreferrer">Ncurses tutorial</a> does not mention this to be obviously possible.</p>
  
  <p>A query on "<em>c print to {window,screen,terminal,console} bottom</em>" at StackOverflow or at a web search engine isn't helpful.</p>
  
  <p>Can this be done in C programmatically?</p>
  
  <h2>Discarding input</h2>
  
  <p>While some of the solutions below can move character to a given position, there is the problem that it may be needed to discard user input rather than leaving it on screen. Like in <code>vim</code>'s case, typing "<code>:w</code>" and pressing Enter does not leave a "<code>:w</code>" on the screen.</p>
  
  <p>Update. This is found here: <a href="https://stackoverflow.com/questions/7910512">How to delete text after getstr() c++ ncurses</a></p>
  
  <h2>Window focus - the UNSOLVED PART OF THE PROBLEM</h2>
  
  <p>While you are typing the input at window bottom and the text at the top changes, we see the problem of moving the focus back to the bottom. This is absent in the solutions as of December 29.</p>
  
  <hr>
  
  <p>Update 1. Just attempting to</p>
  
  <ul>
  <li>remember the previous cursor position, then</li>
  <li>display the output, and then </li>
  <li>restore the position</li>
  </ul>
  
  <p>is <strong>not an easy solution</strong>: as these are different processes, attempts to retrieve cursor position don't affect the changes that happened during the other process execution. </p>
  
  <p>Eg if parent takes input then the child doesn't know how the cursor position changed and can't restore the cursor position after performing a line of output at another part of the console.</p>
  
  <p>Implementing this would involve some inter process communication and if there are other solutions they could be preferable.</p>
  
  <h2>Related</h2>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/6886579">Get Input from keyboard without waiting for input</a> Related, but not specific enough.</li>
  <li><a href="https://stackoverflow.com/questions/8635299/">How to make a chat like UI using Python Urwid?</a> Urwid for Python which does the job (per <em>J.F. Sebastian</em> in the comment below). Unfortunately not in C.</li>
  </ul>