title: How do you edit existing text (and move the cursor around) in the terminal?
body: <p>I saw this demo once that printed out a paragraph of text (like you'd get when typing <code>some-command --help</code>), and it then jumped back up to a couple keywords in the text and changed the text color, <em>after it was already printed out in the terminal</em>.</p>
  
  <p>That seems crazy to me.  How did they do that?</p>
  
  <p>Starting to think about it, I guess <code>stdout</code> and <code>stdin</code> are technically an "IO stream", so maybe that's a persistent variable that keeps track of the position of a cursor?  I remember doing something like that when building a language parser.</p>
  
  <p>The goal would be this: say you type the following into the console, and it outputs a blank array because in Node.js, it's all async and we don't want to write the async function everytime in the console:</p>
  
  <pre><code>$ node app.js
  &gt; App.User.all()
  =&gt; []
  </code></pre>
  
  <p>Then when the async callback executes, you go back and edit the <code>=&gt; []</code> to include the result:</p>
  
  <pre><code>$ node app.js
  &gt; App.User.all()
  =&gt; [#&lt;User id:1&gt;, #&lt;User id:2&gt;...]
  </code></pre>
  
  <p>That would be awesome to at least know how to implement, even if there are a lot of other issues to work through (unrelated to this question. And I know you can define a global callback and do something like <code>App.User.all(_c)</code>).</p>
  
  <p>How do you edit the terminal output after it's already been printed?</p>