/* term.h - ncurses replacement :)

  REV   DATE	REVISION NOTES
   -  10/16/02	Moved terminal code from te.c
 */

#include <termios.h>

struct termios new_termios, old_termios;

term_init() {
  tcgetattr(0, &old_termios);
  new_termios = old_termios;
  new_termios.c_iflag &= ~(BRKINT+ISTRIP+IXON+IXOFF);
  new_termios.c_iflag |= (IGNBRK+IGNPAR);
  new_termios.c_lflag &= ~(ICANON+ISIG+IEXTEN+ECHO);
  new_termios.c_cc[VMIN] = 1;
  new_termios.c_cc[VTIME] = 0;
  tcsetattr(0, TCSANOW, &new_termios);
  }

term_cleanup() {
  tcsetattr(0, TCSANOW, &old_termios);
  }

cls() { printf("\e[2J"); home(); }
home() { printf("\e[1;1H"); }
xy(int x, int y) { printf("\e[%d;%dH", y, x); }
mode(int n) { printf("\e[%dm", n); }
color(int n) { printf("\e[0%s;3%d;4%dm", (n<128) ? "" : ";1", (n>>4)%8, n%8); }

/* ----------------------------------------------------------------
			VT100/ANSI CODES

\e[nA	Cursor movement ("n" is optional) .....	  A
						D B C
\e[E	Move to start of next line ... same as ^M^J or ^J ...?
\e[r;cH	Move to (row, column)
\e7	Save position
\e8	Restore position
\e[nK	Erase line... 0: to right, 1: to left, 2: entire line
\e[nJ	Erase screen... 0: bottom, 1: top, 2: entire screen
\e[nL	Insert line(s) (n is optional)
\e[nM	Delete line(s)
\e[n@	Insert character(s)
\e[nP	Delete character(s)

\e[nm	Attributes.. (can do multiple settings, ie, \e[0;34;41m)
	0=reset  1=bold  4=underline
	Colors: 3x=foreground (bold=bright)  4x=background
	      where x =	0 black		gray (when bold)
			1 red		pink
			2 green
			3 brown		yellow
			4 blue
			5 purple	magenta
			6 cyan/turquoise
			7 white
\eH	Set tab stop (at current column)
\e[g	Clear tab stop (at current column)
\e[3g	Clear all tab stops (including default ones at 8 chars)
---------------------------------------------------------------- */
