File: screen.c

package info (click to toggle)
notifyme 1.4.3-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny, sarge, squeeze
  • size: 176 kB
  • ctags: 148
  • sloc: ansic: 943; sh: 153; makefile: 116
file content (61 lines) | stat: -rw-r--r-- 1,017 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdio.h>
#include <string.h>

#define ESC 		"\033"
#define COLOR(N) 	ESC "[3" #N "m"

#define SAVE 		ESC "7" 	/* save current state		*/
#define BOLD 		ESC "[1m"
#define RESET 		ESC "[0m"	/* reset attr to their defaults	*/

/* restore most recently saved state */
#define RESTORE 	ESC "8"

extern int cols, rows;
static int msg_x, msg_y;

static inline void goto_col(int x)
{
	char buf[16];
	snprintf(buf, sizeof buf, "\033[1;%dH", x);
	printf("%s", buf);
}

static inline void goto_xy(int x, int y)
{
	char buf[16];
	snprintf(buf, sizeof buf, "\033[%d;%dH", y, x);
	printf("%s", buf);
}
	

void erase(int l)
{
	int i;
	i = l>cols?0:cols-l;
	printf(SAVE);
	goto_xy(msg_x, msg_y);
	while(i++ < cols)
		printf(" ");
	printf(RESTORE RESET);
}

void echo(char *s, int c)
{
	int l = strlen(s);
	int y, x;
	y = 1;
	x = cols - l;
//	if(l > cols) l = cols;
//	else l = cols - l;
	if(c) {
		y = rows/2;
		x = cols/2 - l/2;
	}
	msg_x = x;
	msg_y = y;
	goto_xy(x, y);
	printf(BOLD "%s", s);
	printf(RESTORE RESET);
}