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