-
Notifications
You must be signed in to change notification settings - Fork 2
/
term.c
72 lines (62 loc) · 1.65 KB
/
term.c
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
62
63
64
65
66
67
68
69
70
71
/*
* Copyright (c) 2008 - Chuck McManis, All Rights Reserved
*
* These are some 'curses' like functions which have come in
* handy.
*/
#include <stdint.h>
#include "uart.h"
#include "term.h"
extern int console;
#define CSI "\033["
/*
* Send the escape sequence to position the cursor
*/
void
move_cursor(int chan, int row, int col) {
if ((row <= 0) || (col <= 0) || (row > 88) || (col > 200)) {
return;
}
uart_puts(chan, CSI);
uart_putnum(chan, FMT_BASE_10, row);
uart_putc(chan, ';');
uart_putnum(chan, FMT_BASE_10, col);
uart_putc(chan, 'H');
}
static const char *__screen_clear = CSI "2J";
/* Clear the screen */
void
clear_screen(int chan) {
uart_puts(chan, __screen_clear);
}
static const char * __clear_eol = CSI "2j";
void
clear_eol(int chan) {
uart_puts(chan, __clear_eol);
}
static const char *__screen_colors[6] = {
CSI "31;40;1m", // RED on black
CSI "33;40;1m", // YELLOW on black
CSI "37;40;1m", // WHITE on black
CSI "32;40;1m", // GREEN on black
CSI "34;40;1m", // BLUE on black
CSI "0m", // DEFAULT on black
};
/* Set Text Color */
void
text_color(int chan, enum TEXT_COLOR color) {
switch (color) {
case RED:
return uart_puts(chan, __screen_colors[0]);
case YELLOW:
return uart_puts(chan, __screen_colors[1]);
case WHITE:
return uart_puts(chan, __screen_colors[2]);
case GREEN:
return uart_puts(chan, __screen_colors[3]);
case BLUE:
return uart_puts(chan, __screen_colors[4]);
default:
return uart_puts(chan, __screen_colors[5]);
}
}