Professional Documents
Culture Documents
4 Slang
4 Slang
two sets
1. terminal-handling functions (the SLtt family)
2. higher-level screen management functions (the SLsmg
family) ---- string output, line drawing, and screen-
querying functions
SLtt function family works directly with the
terminal; functions that map closely with capabilities
defined in the terminal database.
Includes routines for defining foreground and
background color pairs and turning the cursor on and
off.
Initializing Screen Management
SLsmg_refresh()
updates the physical terminal with the results of any
screen drawing that has been done since the previous
time it was called.
Moving the Cursor
SLSMG_HLINE_CHAR
SLSMG_VLINE_CHAR
SLSMG_ULCORN_CHAR
Writing to the Screen
SLtt_set_color()
void SLtt_set_color(int entry, char * name, char * fg,
char * bg);
ioctl - control device
#include <sys/ioctl.h>
int ioctl(int d, int request, ...);
The ioctl() function manipulates the underlying device
parameters of special files.
terminals controlled with ioctl() requests.
The argument d must be an open file descriptor.
The second argument is a device-dependent request code.
The third argument is an untyped pointer to memory.
TIOCGWINSZ - Fill in the winsize structure pointed to by the
third argument with the screen width and height.
7.#include <slang/slang.h>
8: int main(void) {
9: struct winsize ws;
10:
11: /* get the size of the terminal connected to stdout */
12: if (ioctl(1, TIOCGWINSZ, &ws)) {
13: perror("failed to get window size");
14: return 1;
15: }
16:
17: SLtt_get_terminfo();
18:
19: SLtt_Screen_Rows = ws.ws_row;
20: SLtt_Screen_Cols = ws.ws_col;
21:
22: SLsmg_init_smg();
23:
24: /* heart of the program goes here */
25:
26: SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
27: SLsmg_refresh();
28: SLsmg_reset_smg();
29: SLang_reset_tty();
30:
31: return 0;