title: Take over console output using ruby
body: <p>When I run vim or top from a console they are able to take over rendering the whole console. When I quit I'm then returned to the console.</p>
  
  <p>Is it possible to do this from ruby? As a simple example, how would I do the following</p>
  
  <pre><code># Rakefile
  task :clock do
    loop do
      console.render Time.now
      sleep 1
    end
  end
  </code></pre>
  
  <p>when I run this the console would be cleared and the first line would show the time. When I quit I'd then continue the console session as it was before I ran rake clock.</p>
  
  <hr>
  
  <h2>Update</h2>
  
  <p>Having checked the <a href="https://github.com/grosser/tic_tac_toe" rel="nofollow">tictactoe example</a> for ruby curses here's an implementation of the clock example. I've shown the clock on random lines to demonstrate refreshing the whole console.</p>
  
  <pre><code>#!/usr/bin/env ruby
  require 'curses'
  
  loop do
    Curses.clear  
    Curses.setpos(rand * 10, 0)  
    Curses.addstr(Time.now.to_s);
    Curses.refresh
    sleep 1
  end
  </code></pre>