libite 2.6.1
conio.h File Reference
#include <stdio.h>

Go to the source code of this file.

Macros

#define LIBITE_CONIO_H_
 
#define RESETATTR   0
 
#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
 
#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
 
#define clrscr()
 
#define clreol()
 
#define delline()
 
#define gotoxy(x, y)
 
#define hidecursor()
 
#define showcursor()
 
#define __set_gm(a, c, v)
 
#define textattr(attr)
 
#define textcolor(color)
 
#define textbackground(color)
 

Functions

void initscr (int *row, int *col)
 

Detailed Description

Author
Joachim Wiberg
Date
2009-2021

Helper macros and functions for interacting with TTY terminals.

Definition in file conio.h.

Macro Definition Documentation

◆ __set_gm

#define __set_gm ( a,
c,
v )
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)

Definition at line 83 of file conio.h.

◆ BLACK

#define BLACK   0x0

Colors for text and background

Definition at line 47 of file conio.h.

◆ BLINK

#define BLINK   5 /* May not work on all displays. */

Definition at line 42 of file conio.h.

◆ BLUE

#define BLUE   0x4

Definition at line 51 of file conio.h.

◆ BRIGHT

#define BRIGHT   1

Definition at line 39 of file conio.h.

◆ BROWN

#define BROWN   0x3

Definition at line 50 of file conio.h.

◆ clreol

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

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

Definition at line 72 of file conio.h.

◆ clrscr

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

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

Definition at line 70 of file conio.h.

◆ CYAN

#define CYAN   0x6

Definition at line 53 of file conio.h.

◆ DARKGREY

#define DARKGREY   0x10

Definition at line 56 of file conio.h.

◆ delline

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

Erases the entire current line.

Definition at line 74 of file conio.h.

◆ DIM

#define DIM   2

Definition at line 40 of file conio.h.

◆ gotoxy

#define gotoxy ( x,
y )
Value:
fprintf(stdout, "\033[%d;%dH", y, x)

Moves the cursor to the specified position (coordinates)

Definition at line 76 of file conio.h.

◆ GREEN

#define GREEN   0x2

Definition at line 49 of file conio.h.

◆ HIDDEN

#define HIDDEN   8

Definition at line 44 of file conio.h.

◆ hidecursor

#define hidecursor ( )
Value:
fputs("\033[?25l", stdout)

Hide Cursor

Definition at line 78 of file conio.h.

◆ LIBITE_CONIO_H_

#define LIBITE_CONIO_H_

Definition at line 33 of file conio.h.

◆ LIGHTBLUE

#define LIGHTBLUE   0x14

Definition at line 60 of file conio.h.

◆ LIGHTCYAN

#define LIGHTCYAN   0x16

Definition at line 62 of file conio.h.

◆ LIGHTGREEN

#define LIGHTGREEN   0x12

Definition at line 58 of file conio.h.

◆ LIGHTGREY

#define LIGHTGREY   0x7

Definition at line 54 of file conio.h.

◆ LIGHTMAGENTA

#define LIGHTMAGENTA   0x15

Definition at line 61 of file conio.h.

◆ LIGHTRED

#define LIGHTRED   0x11

Definition at line 57 of file conio.h.

◆ MAGENTA

#define MAGENTA   0x5

Definition at line 52 of file conio.h.

◆ RED

#define RED   0x1

Definition at line 48 of file conio.h.

◆ RESETATTR

#define RESETATTR   0

Attributes

Definition at line 38 of file conio.h.

◆ REVERSE

#define REVERSE   7

Definition at line 43 of file conio.h.

◆ SCREEN_WIDTH

#define SCREEN_WIDTH   80

Fallback screen width, possible to override.

Definition at line 66 of file conio.h.

◆ showcursor

#define showcursor ( )
Value:
fputs("\033[?25h", stdout)

Show Cursor

Definition at line 80 of file conio.h.

◆ textattr

#define textattr ( attr)
Value:
__set_gm(attr, 0, 0)
#define __set_gm(a, c, v)
Definition conio.h:83

Set text attribute

Definition at line 90 of file conio.h.

◆ textbackground

#define textbackground ( color)
Value:
__set_gm(RESETATTR, color, 40)
#define RESETATTR
Definition conio.h:38

Set text background

Definition at line 94 of file conio.h.

◆ textcolor

#define textcolor ( color)
Value:
__set_gm(RESETATTR, color, 30)

Set text color

Definition at line 92 of file conio.h.

◆ UNDERSCORE

#define UNDERSCORE   4

Definition at line 41 of file conio.h.

◆ WHITE

#define WHITE   0x17

Definition at line 63 of file conio.h.

◆ YELLOW

#define YELLOW   0x13

Definition at line 59 of file conio.h.

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.

Definition at line 44 of file conio.c.