6

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.

Is it possible to do this from ruby? As a simple example, how would I do the following

# Rakefile
task :clock do
  loop do
    console.render Time.now
    sleep 1
  end
end

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.


Update

Having checked the tictactoe example 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.

#!/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

1 Answer 1

5

You're looking for the Ruby curses library which gives you full control over the screen: positioning, color, &c.

It's not a well document library, but a Stackoverflow search for "[ruby] curses" will give you links to examples.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.