libite
Macros | Functions
conio.h File Reference
#include <stdio.h>
Include dependency graph for conio.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LIBITE_CONIO_H_
 
#define RESETATTR   0
 Attributes.
 
#define BRIGHT   1
 
#define DIM   2
 
#define UNDERSCORE   4
 
#define BLINK   5 /* May not work on all displays. */
 
#define REVERSE   7
 
#define HIDDEN   8
 
#define BLACK   0x0
 Colors for text and background.
 
#define RED   0x1
 
#define GREEN   0x2
 
#define BROWN   0x3
 
#define BLUE   0x4
 
#define MAGENTA   0x5
 
#define CYAN   0x6
 
#define LIGHTGREY   0x7
 
#define DARKGREY   0x10
 
#define LIGHTRED   0x11
 
#define LIGHTGREEN   0x12
 
#define YELLOW   0x13
 
#define LIGHTBLUE   0x14
 
#define LIGHTMAGENTA   0x15
 
#define LIGHTCYAN   0x16
 
#define WHITE   0x17
 
#define SCREEN_WIDTH   80
 Fallback screen width, possible to override. More...
 
#define clrscr()   fputs("\033[2J\033[1;1H", stdout)
 Clear screen and move cursor to 1,1 (upper left) pos. More...
 
#define clreol()   fputs("\033[K", stdout)
 Erases from the current cursor position to the end of the current line. More...
 
#define delline()   fputs("\033[2K", stdout)
 Erases the entire current line. More...
 
#define gotoxy(x, y)   fprintf(stdout, "\033[%d;%dH", y, x)
 Moves the cursor to the specified position (coordinates)
 
#define hidecursor()   fputs("\033[?25l", stdout)
 Hide Cursor.
 
#define showcursor()   fputs("\033[?25h", stdout)
 Show Cursor.
 
#define __set_gm(a, c, v)
 Set Graphics Mode (attr, color, val) More...
 
#define textattr(attr)   __set_gm(attr, 0, 0)
 Set text attribute.
 
#define textcolor(color)   __set_gm(RESETATTR, color, 30)
 Set text color.
 
#define textbackground(color)   __set_gm(RESETATTR, color, 40)
 Set text background.
 

Functions

void initscr (int *row, int *col)
 Probe terminal size. More...
 

Detailed Description

Author
Joachim Wiberg
Date
2009-2021

Helper macros and functions for interacting with TTY terminals.

Macro Definition Documentation

◆ __set_gm

#define __set_gm (   a,
  c,
 
)
Value:
if (!c) \
fprintf(stdout, "\033[%dm", a); \
else \
fprintf(stdout, "\033[%d;%dm", c & 0x10 ? 1 : 0, (c & 0xF) + v)

Set Graphics Mode (attr, color, val)

◆ clreol

#define clreol ( )    fputs("\033[K", stdout)

Erases from the current cursor position to the end of the current line.

◆ clrscr

#define clrscr ( )    fputs("\033[2J\033[1;1H", stdout)

Clear screen and move cursor to 1,1 (upper left) pos.

◆ delline

#define delline ( )    fputs("\033[2K", stdout)

Erases the entire current line.

◆ SCREEN_WIDTH

#define SCREEN_WIDTH   80

Fallback screen width, possible to override.

Function Documentation

◆ initscr()

void initscr ( int *  row,
int *  col 
)

Probe terminal size.

Parameters
rowpointer to integer to store number of rows
colpointer to integer to store number of columns

This function checks if stdin and stdout isatty() and then sets the TTY in raw mode to silently ask the size using ANSI escape sequences. This is achieved by trying to go to corner 999,999 followed by querying the cursor position. Afterwards the TTY is returned to the state if was before, e.g. cooked. The number of rows and columns is returned in the input arguments to this function.

If stdio is not a TTY, then a default 24x80 is returned.