]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/jdb/jdb-ansi.cpp
update
[l4.git] / kernel / fiasco / src / jdb / jdb-ansi.cpp
1
2 /*
3  * JDB Module implementing ANSI/vt100 functions
4  */
5
6 INTERFACE:
7
8 EXTENSION class Jdb
9 {
10 public:
11   enum
12   {
13     NOFANCY=0,
14     FANCY=1
15   };
16
17   enum Direction
18   {
19     Cursor_up = 'A',
20     Cursor_down = 'B',
21     Cursor_right = 'C',
22     Cursor_left = 'D'
23   };
24 };
25
26 IMPLEMENTATION:
27
28 #include <cstdio>
29 #include <simpleio.h>
30 #include "jdb_screen.h"
31
32 PUBLIC static inline
33 void
34 Jdb::cursor( Direction d, unsigned n = 1)
35 {
36   printf("\033[%u%c", n, (char)d);
37 }
38
39
40 PUBLIC static
41 void
42 Jdb::cursor (unsigned int row=0, unsigned int col=0)
43 {
44   if (row || col)
45     printf ("\033[%u;%uH", row, col);
46   else
47     printf ("\033[%u;%uH", 1, 1);
48 }
49
50 PUBLIC static inline NEEDS[<cstdio>]
51 void
52 Jdb::blink_cursor (unsigned int row, unsigned int col)
53 {
54   printf ("\033[%d;%df", row, col);
55 }
56
57 PUBLIC static inline NEEDS[<simpleio.h>]
58 void
59 Jdb::cursor_save()
60 {
61   putstr ("\0337");
62 }
63
64 PUBLIC static inline NEEDS[<simpleio.h>]
65 void
66 Jdb::cursor_restore()
67 {
68   putstr ("\0338");
69 }
70
71 PUBLIC static inline NEEDS[<simpleio.h>]
72 void
73 Jdb::screen_erase()
74 {
75   putstr ("\033[2J");
76 }   
77
78 PUBLIC static
79 void
80 Jdb::screen_scroll (unsigned int start, unsigned int end)
81 {
82   if (start || end)
83     printf ("\033[%u;%ur", start, end);
84   else
85     printf ("\033[r");
86 }
87
88 PUBLIC static inline NEEDS[<simpleio.h>]
89 void
90 Jdb::clear_to_eol()
91 {
92   putstr("\033[K");
93 }
94
95 // preserve the history of the serial console if fancy != 0
96 PUBLIC static
97 void
98 Jdb::clear_screen(int fancy=FANCY)
99 {
100   if (fancy == FANCY)
101     {
102       cursor(Jdb_screen::height(), 1);
103       for (unsigned i=0; i<Jdb_screen::height(); i++)
104         {
105           putchar('\n');
106           clear_to_eol();
107         }
108     }
109   else
110     {
111       cursor();
112       for (unsigned i=0; i<Jdb_screen::height()-1; i++)
113         {
114           clear_to_eol();
115           putchar('\n');
116         }
117     }
118   cursor();
119 }
120