1 /* A conio.h like implementation for VTANSI displays.
3 * Copyright (c) 2009, 2010, 2017 Joachim Nilsson <troglobit@gmail.com>
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29 /* Colors for text and background */
41 #define LIGHTGREEN 0x12
43 #define LIGHTBLUE 0x14
44 #define LIGHTMAGENTA 0x15
45 #define LIGHTCYAN 0x16
48 /* Esc[2JEsc[1;1H - Clear screen and move cursor to 1,1 (upper left) pos. */
49 #define clrscr() puts ("\e[2J\e[1;1H")
50 /* Esc[K - Erases from the current cursor position to the end of the current line. */
51 #define clreol() puts ("\e[K")
52 /* Esc[2K - Erases the entire current line. */
53 #define delline() puts ("\e[2K")
54 /* Esc[Line;ColumnH - Moves the cursor to the specified position (coordinates) */
55 #define gotoxy(x,y) printf("\e[%d;%dH", y, x)
56 /* Esc[?25l (lower case L) - Hide Cursor */
57 #define hidecursor() puts ("\e[?25l")
58 /* Esc[?25h (lower case H) - Show Cursor */
59 #define showcursor() puts ("\e[?25h")
61 /* Esc[Value;...;Valuem - Set Graphics Mode */
62 #define __set_gm(attr,color,val) \
64 printf("\e[%dm", attr); \
66 printf("\e[%d;%dm", color & 0x10 ? 1 : 0, (color & 0xF) + val)
67 #define textattr(attr) __set_gm(attr, 0, 0)
68 #define textcolor(color) __set_gm(RESETATTR, color, 30)
69 #define textbackground(color) __set_gm(RESETATTR, color, 40)
74 * c-file-style: "linux"