csteifel
csteifel

Reputation: 2934

Console overwriting like top

Ok so I was just wondering how console applications like top(1) for linux overwrite multiple lines. I want to know how to do it for C++ or C. I know how to overwrite 1 line by just putting a \r but I wanted to know how to do so for multiple lines, again like in top or if its even possible.

Upvotes: 5

Views: 534

Answers (2)

ezod
ezod

Reputation: 7421

This may not directly address the question, but this sort of thing is dependent on the terminal and is commonly done with a curses implementation (ncurses is the most widely used).

Upvotes: 2

Ben Voigt
Ben Voigt

Reputation: 283684

They use terminal escape sequences to move the cursor around the screen. A few even use direct framebuffer access, to treat the screen as an array of characters which can be directly indexed.

The curses (or ncurses) library is a good abstraction layer.

Upvotes: 3

Related Questions