views:

60

answers:

5

I don't have much of an interest in designing guis (too much work), and I wanna know how it is that programs like vim, and greed work, how is it that vim can modify it's standard out without printing it all out again?, and I often see the output from terminal programs in bright colors, is there some sort of markup language that tells the terminal what colors to make the fonts?, and when I use "cin", how does the terminal know that the program is expecting input?, or does it just allow for putting stuff in standard in when the program pauses? and how do I get a program to read another program's standard out? I am using c++ as the language, on an Ubuntu linux 10.04 terminal, thanks!

A: 

If you want formatted output on the screen you need to look at termcap

Using output from other programs is done using pipes

Jay
+3  A: 

For interactive terminal programming, check out Curses. This library (and the more recent NCurses) permits you to program GUIs using the terminal. Each terminal type supports various features such as cursor positioning, colours etc. (documented via the terminfo database).

For info on redirection, check out this article on Streams. Each process can communicate with its parent process via 3 streams - stdout/stderr/stdin.

I'd look at Unix Power Tools as a great resource for these types of questions.

Brian Agnew
+1  A: 

The answer is curses.

Nikolai N Fetissov
A: 

To answer your first question only (one house rule on StackOverflow is that you ask one question per question), it could be using ANSI escape codes, although it is probably using a Curses-like library instead.

Pascal Cuoq
+1  A: 
  1. curses/ncurses
  2. termcap/terminfo
  3. Because FD0 is being read from.
  4. Keypresses are pushed into stdin by the terminal when they happen, and they pop out whenever it is read.
  5. popen(3), pipe(2), or piping in a shell.
Ignacio Vazquez-Abrams