0

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.

  • Can you elaborate a bit on what you have tried so far? I think your question will be better received then. – paisanco Sep 16 '14 at 00:45
  • If you hover over the htop tag, you'll notice the description says it is an "ncurses" application. This is a library that allows "terminal" programs to do more interesting things than just print lines. – phs Sep 16 '14 at 00:56

1 Answers1

5

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.

Hisham H M
  • 6,398
  • 1
  • 29
  • 30