Reputation: 8883
Almost all of the applications I've ever written have been GUIs of one form or another - HTML/Flex/Swing - and the bulk of my command line apps have been extremely simple, without much interaction. The most I've ever done is make a simple ascii game that just does a print/input loop, printing the game board over and over again.
I was thinking about doing something a little more complex, and I was really curious how some of the more advanced command line apps like emacs even work. Specifically, I have no idea how they seem to be able to have an interactive command line that responds to key presses and appears to just operate on a buffer in the terminal instead of constantly going through the print->read->print loop. Is it all just stdin/stdout kung fu I'm not aware of or is it something completely different?
Update - I want to be clear that I'm not trying to ask a broad question here, perhaps I'm just having difficulty finding the right words. Basically, I don't know how I would make emacs work using stdin/stdout. Is it using some mechanism I'm not aware of, and if so, what?
Upvotes: 4
Views: 609
Reputation: 258388
You are right that it isn't just stdin/stdout for a program like this. Usually it's a terminal control library such as curses.
Some other arbitrarily-chosen libraries include:
See also Text user interface on Wikipedia.
I'm not very familiar with using any of those libraries, but the current version of terminfo.c in the emacs source has the following comment, suggesting they do use curses:
/* Interface to curses/terminfo library. Turns out that all of the terminfo-level routines look like their termcap counterparts except for tparm, which replaces tgoto. Not only is the calling sequence different, but the string format is different too. */
Upvotes: 2