annotate src/term.c @ 9:af6f4adc43d6
fixed a bug in strrchr and some warnings
author |
John Tsiombikas <nuclear@member.fsf.org> |
date |
Wed, 16 Feb 2011 08:01:19 +0200 |
parents |
86781ef20689 |
children |
06172322fb76 |
rev |
line source |
nuclear@4
|
1 #include <ctype.h>
|
nuclear@1
|
2 #include "term.h"
|
nuclear@1
|
3 #include "vid.h"
|
nuclear@1
|
4
|
nuclear@2
|
5 static int bg, fg = LTGRAY;
|
nuclear@1
|
6 static int cursor_x, cursor_y;
|
nuclear@1
|
7
|
nuclear@2
|
8 /* sets the active text color and returns previous value */
|
nuclear@2
|
9 int set_text_color(int c)
|
nuclear@1
|
10 {
|
nuclear@2
|
11 int prev = fg;
|
nuclear@2
|
12
|
nuclear@1
|
13 if(c >= 0 && c < 16) {
|
nuclear@1
|
14 fg = c;
|
nuclear@1
|
15 }
|
nuclear@2
|
16 return prev;
|
nuclear@1
|
17 }
|
nuclear@1
|
18
|
nuclear@2
|
19 /* sets the active background color and returns the current value */
|
nuclear@2
|
20 int set_back_color(int c)
|
nuclear@1
|
21 {
|
nuclear@2
|
22 int prev = bg;
|
nuclear@2
|
23
|
nuclear@1
|
24 if(c >= 0 && c < 16) {
|
nuclear@1
|
25 bg = c;
|
nuclear@1
|
26 }
|
nuclear@2
|
27 return prev;
|
nuclear@1
|
28 }
|
nuclear@1
|
29
|
nuclear@2
|
30 /* output a single character, handles formatting, cursor advancement
|
nuclear@2
|
31 * and scrolling the screen when we reach the bottom.
|
nuclear@2
|
32 * TODO make visible cursor actually move.
|
nuclear@2
|
33 */
|
nuclear@1
|
34 int putchar(int c)
|
nuclear@1
|
35 {
|
nuclear@1
|
36 switch(c) {
|
nuclear@1
|
37 case '\n':
|
nuclear@1
|
38 cursor_y++;
|
nuclear@1
|
39
|
nuclear@1
|
40 case '\r':
|
nuclear@1
|
41 cursor_x = 0;
|
nuclear@1
|
42 break;
|
nuclear@1
|
43
|
nuclear@1
|
44 case '\b':
|
nuclear@1
|
45 cursor_x--;
|
nuclear@1
|
46 set_char(' ', cursor_x, cursor_y, fg, bg);
|
nuclear@1
|
47 break;
|
nuclear@1
|
48
|
nuclear@1
|
49 case '\t':
|
nuclear@1
|
50 cursor_x = ((cursor_x >> 3) + 1) << 3;
|
nuclear@1
|
51 break;
|
nuclear@1
|
52
|
nuclear@1
|
53 default:
|
nuclear@2
|
54 if(isprint(c)) {
|
nuclear@2
|
55 set_char(c, cursor_x, cursor_y, fg, bg);
|
nuclear@2
|
56 if(++cursor_x >= WIDTH) {
|
nuclear@2
|
57 cursor_x = 0;
|
nuclear@2
|
58 cursor_y++;
|
nuclear@2
|
59 }
|
nuclear@1
|
60 }
|
nuclear@1
|
61 }
|
nuclear@1
|
62
|
nuclear@1
|
63 if(cursor_y >= HEIGHT) {
|
nuclear@1
|
64 scroll_scr();
|
nuclear@1
|
65 cursor_y--;
|
nuclear@1
|
66 }
|
nuclear@2
|
67
|
nuclear@2
|
68 set_cursor(cursor_x, cursor_y);
|
nuclear@1
|
69 return c;
|
nuclear@1
|
70 }
|