Terminal programming

Created 2022-10-20 Updated 2053-02-12

Raw, unblocked, stdin

Raw, blocked, stdin

This program demonstrates the use of

See also: man tty_ioctl

It stops character echoing on the terminal. Newlines are still echoed properly. Any character that the user inputs is printed out in uppercase. `poll()` is used to check to see if a char is available, rather than using `getchar()`.

Source

Raw, blocked, tty

This example takes input from the tty in non-coocked mode, so it doesn't require the user to press Return before responding. The following example converts your input key to uppercase. It blocks on input, and echos the input key to output. You can, optionally, use stdin from file redirection (as per note 1).

Note 1

You can also additionally use stdin:

So you can do:

and it will print the file to stdout, and accept input from the tty.

Keycode recognition

The following code shows raw key codes for terminal input keys:

Example output:

This is the result of pressing the Page Down Key. ESC is decimal 27 (\033), 91 is '[', 54 is '6', and 126 is '~'.

Source code

SERIAL PORT

Source

ANSI

0: Reset style

1: Bold

2: light

3: italics

4: underlined

30: Black

31: Red

32: Green

33: Yellow

34: Blue

35: Magenta

36: Cyan

37: White

Usage: echo -e "\033[31mI am red"

Combining multiple:

Use ';' to separate elements

Use 'm' to finish sequence

E.g.: \033[31;1m will be bold red

\033[A up arrow

\033[B down arrow

\033[C right arrow

\033[D left arrow

\033[F end

\033[H home

\033[J clear screen

\033[2~ insert

\033[3~ delete

\033[5~ page up

\033[6~ page down

Cursor

EXITS

termios(3) - terminal interface functions

cerbo/cprogs for terminal size