Question: I am looking for some sort of packages / APIs in Linux that can display output in columns similar to how `top` does. 

For example, keep cleaning and rewriting the output to a full screen at a given interval (I guess [watch](http://linux.die.net/man/1/watch) probably does this good enough. But I am hoping to have some APIs that wrap on top of it). 

Sort by columns easily. Particularly if I sort by column A, then when next time I re-print everything, it remembers to sort by that column A every time the output is refreshed. 

And of course, ideally it can handle the keyboard input for me as well. 

All in all, I am looking for packages or APIs that can help me organize my output in a way "`top`" organizes it. 

Just to clarity: What I display might be completely unrelated to the system statistics. I just like the way top organizes the content. For example, My output content might be (and it's constantly changing, which is why it needs to be cleaned and rewritten): 

> 
> Time Col1 Col2  
> 
>  12 4 13  
> 
>  13 5 19  
> 
>  14 5 15
> 
> 
> 

I can hit a key say "A" then it sorts by Time. If I hit a key B then it sorts by Col1. If I hit a key say C then it sorts by Col2, etc, etc. 

And of course this output content can be entirely in memory, organized in any data structures.

Answer: 
I found the curses library in Python handy for this sort of requirement. It still doesn't support column management, but it provides a decent solution with a sane language, a nice document and a manageable learning curve. 

If anyone else has better suggestion, I would be happy to pick his as the best answer.

<http://docs.python.org/howto/curses.html>
There's [CDK](http://invisible-island.net/cdk/). I tried it, and it's all right, feels a bit like GTK. But a `printf` solution is far cleaner.

If you don't mind scripting languages, you could try [rbcurse](https://github.com/rkumar/rbcurse), which has more features. It has very bad documentation though.