Take console output with ruby

When I run vim or from above from the console, they can take over the entire console. When I leave, I will return to the console.

Can this be made 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 will be cleared and the first line will show the time. When I leave, I will continue the console session, as it was before I started the rake clock.


Update

Checking the tictactoe example for ruby ​​curses, here is an example of an example synchronization. I showed the clock on random lines to demonstrate the update of the entire 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 
+7
source share
1 answer

You are looking for a Ruby curses library that gives you full control over the screen: positioning, color, etc.

This is not a good document library, but a Stackoverflow search for β€œruby guns” will give you links to examples.

+5
source

All Articles