yeahwhatever10
yeahwhatever10

Reputation: 13

How does htop display work?

I want to write a program that displays its output in the shell like htop does, as opposed to just running the program and using the watch command. I have looked through the htop source code and am still a little lost. Is there a output beyond tty in the shell that is used, or are all the htop panels custom and opening an output like that is not a native task for a shell like bash?

Thanks.

Upvotes: 1

Views: 1146

Answers (1)

Hisham H M
Hisham H M

Reputation: 6808

htop author here. What you're looking for is the NCurses library. With NCurses, you can implement a full-screen textmode application in C.

It provides a set of primitives for "drawing" on the terminal: ie, move() to go to a X-Y coordinate on the screen, functions to change colors, to erase part of the screen, etc. It also provides some high-level constructs such as "windows" through which you can scroll parts of the screen separately, but in htop I don't use that and implement my scrollable panels drawing them "by hand" using the lower-level primitives.

Upvotes: 6

Related Questions