Persistent Command Line Display Persistent Command Line Display shell shell

Persistent Command Line Display


Depending on your needs, erasing the screen and creating the grid again could be good enough :

def show_grid  line = '+---+---+---+---+---+---+---+---+---+'  puts line  9.times do    row = (1..9).map { rand(9) + 1 }    puts '| ' + row.join(' | ') + ' |'    puts line  endenddef clear_screen  system('clear') || system('cls')endloop do  clear_screen  show_grid  sleep 1end

It outputs

+---+---+---+---+---+---+---+---+---+| 1 | 2 | 7 | 3 | 4 | 9 | 8 | 6 | 5 |+---+---+---+---+---+---+---+---+---+| 1 | 8 | 1 | 7 | 6 | 2 | 2 | 1 | 3 |+---+---+---+---+---+---+---+---+---+| 2 | 2 | 1 | 2 | 2 | 8 | 2 | 3 | 6 |+---+---+---+---+---+---+---+---+---+| 5 | 3 | 6 | 1 | 5 | 3 | 2 | 7 | 9 |+---+---+---+---+---+---+---+---+---+| 9 | 7 | 7 | 4 | 7 | 2 | 2 | 9 | 1 |+---+---+---+---+---+---+---+---+---+| 5 | 9 | 1 | 9 | 3 | 7 | 8 | 3 | 1 |+---+---+---+---+---+---+---+---+---+| 8 | 5 | 4 | 7 | 3 | 2 | 2 | 5 | 3 |+---+---+---+---+---+---+---+---+---+| 4 | 7 | 1 | 1 | 4 | 8 | 4 | 1 | 1 |+---+---+---+---+---+---+---+---+---+| 1 | 1 | 8 | 4 | 2 | 4 | 8 | 3 | 8 |+---+---+---+---+---+---+---+---+---+

then

+---+---+---+---+---+---+---+---+---+| 6 | 4 | 4 | 3 | 5 | 5 | 8 | 9 | 1 |+---+---+---+---+---+---+---+---+---+| 7 | 7 | 7 | 3 | 3 | 2 | 8 | 7 | 6 |+---+---+---+---+---+---+---+---+---+| 6 | 2 | 2 | 1 | 4 | 7 | 1 | 1 | 9 |+---+---+---+---+---+---+---+---+---+| 3 | 8 | 7 | 7 | 7 | 9 | 7 | 4 | 4 |+---+---+---+---+---+---+---+---+---+| 4 | 1 | 2 | 8 | 6 | 7 | 1 | 9 | 3 |+---+---+---+---+---+---+---+---+---+| 6 | 7 | 7 | 5 | 1 | 7 | 6 | 7 | 4 |+---+---+---+---+---+---+---+---+---+| 8 | 2 | 3 | 5 | 3 | 5 | 4 | 7 | 2 |+---+---+---+---+---+---+---+---+---+| 5 | 9 | 3 | 2 | 4 | 2 | 9 | 6 | 3 |+---+---+---+---+---+---+---+---+---+| 1 | 7 | 8 | 9 | 4 | 3 | 4 | 1 | 5 |+---+---+---+---+---+---+---+---+---+

then...

It should work on Windows/Linux/MacOs.

For anything more complex, you'll need an ncurses gem.


So the question is marked as answered I thought I would write up the advice given to me in the comments.

It looks like the ncurses ruby gem and vedeu offer the functionality that I need. Another alternative would be to clear the scren and reprint the output.