does anyone have more info on standard in and standard out?
I don't have much of an interest in designing guis (too much work), and I wanna kn开发者_运维技巧ow 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!
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.
The answer is curses
.
- curses/ncurses
- termcap/terminfo
- Because FD0 is being read from.
- Keypresses are pushed into stdin by the terminal when they happen, and they pop out whenever it is read.
popen(3)
,pipe(2)
, or piping in a shell.
If you want formatted output on the screen you need to look at termcap
Using output from other programs is done using pipes
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.
精彩评论