3

I would like to print an output like the following in a fixed position while the numbers in the block keep updating every couple of seconds. It is similar to what top does.

Jobs monitor:
+-----------------------------------------+
| Waiting | Launched | Running | Finished |
+-----------------------------------------+
|   319   |   364    |   94    |   201    |
+-----------------------------------------+
Elapsed time: 21s

Is there a way to do that?

With only one line, I could do it with STDOUT.flush and "\r", but it does not work for multiple lines since the carriage will put the cursor at the beginning of the new line only.

sawa
  • 165,429
  • 45
  • 277
  • 381
Juanpe Araque
  • 579
  • 1
  • 4
  • 16

1 Answers1

3

The curses library is one way to make this work. It allows you to write to locations on a 2-d screen so you're not constrained to the current line. This question has some good resources for learning curses.

Community
  • 1
  • 1
Paul Rubel
  • 26,632
  • 7
  • 60
  • 80
  • Is it a way of doing it without installing any gem? Playing with the output or something like that? Curses does not seem to be available without installing it. – Juanpe Araque Feb 22 '16 at 22:50
  • you could probably re-implement curses with things like [ANSI control codes](https://en.wikipedia.org/wiki/ANSI_escape_code) that seems pretty painful though. Nothing else comes to mind immediately. – Paul Rubel Feb 23 '16 at 16:40