10 static int runcmd(void);
11 static int cmd_list(const char *args);
12 static int cmd_help(const char *args);
15 #define CBUF_MASK (CBUF_SIZE - 1)
20 static char cbuf[CBUF_SIZE];
21 static char inp[CBUF_SIZE + 1], *dptr;
24 static char hist[HIST_SIZE][CBUF_SIZE + 1];
25 static int hist_head, hist_tail;
27 static char sbuf[SBUF_SIZE][CBUF_SIZE + 1];
28 static int sbuf_head, sbuf_tail;
35 hist_head = hist_tail = 0;
36 sbuf_head = sbuf_tail = 0;
50 void con_draw(uint16_t *fb)
54 /* print output buffer */
57 while(sidx != sbuf_tail) {
58 cs_cputs(fb, 1, y, sbuf[sidx]);
59 sidx = (sidx + 1) & (SBUF_SIZE - 1);
63 memset(fb + y++ * 320, 0xff, 640);
65 cs_confont(fb, 1, y, '>' - 32);
69 cs_confont(fb, x, y, cbuf[cidx] - 32);
71 cidx = (cidx + 1) & CBUF_MASK;
73 memset(fb + (y + 8) * 320, 0xff, 640);
76 int con_input(int key)
81 wr = (wr + CBUF_SIZE - 1) & CBUF_MASK;
90 rd = (rd + 1) & CBUF_MASK;
95 memcpy(hist[hist_tail], inp, dptr - inp + 1);
96 hist_tail = (hist_tail + 1) & (HIST_SIZE - 1);
97 if(hist_tail == hist_head) { /* ovf */
98 hist_head = (hist_head + 1) & (HIST_SIZE - 1);
106 if(hist_head == hist_tail) break;
107 hist_tail = (hist_tail + HIST_SIZE - 1) & (HIST_SIZE - 1);
108 strcpy(inp, hist[hist_tail]);
112 if(key < 256 && isprint(key)) {
114 wr = (wr + 1) & CBUF_MASK;
115 if(wr == rd) { /* overflow */
116 rd = (rd + 1) & CBUF_MASK;
125 void con_printf(const char *fmt, ...)
131 len = vsprintf(sbuf[sbuf_tail], fmt, ap);
132 sbuf[sbuf_tail][len] = 0;
135 sbuf_tail = (sbuf_tail + 1) & (SBUF_SIZE - 1);
136 if(sbuf_tail == sbuf_head) { /* ovf */
137 sbuf_head = (sbuf_head + 1) & (SBUF_SIZE - 1);
140 if(sbuf_size < SBUF_SIZE) sbuf_size++;
145 int (*func)(const char*);
153 static int runcmd(void)
160 nscr = scr_num_screens();
161 for(i=0; i<nscr; i++) {
162 if(strstr(scr_screen(i)->name, inp + 1)) {
167 con_printf("no such screen: %s\n", inp + 1);
171 i = strtol(inp + 1, &endp, 10);
172 if(endp == inp + 1) {
173 con_printf("usage: #<screen number>\n");
176 nscr = scr_num_screens();
177 if(i < 0 || i >= nscr) {
178 con_printf("no such screen: %d\n", i);
186 while(*endp && isspace(*endp)) endp++;
187 while(*endp && !isspace(*endp)) endp++;
189 args = *endp ? endp + 1 : 0;
192 for(i=0; cmd[i].name; i++) {
193 if(strcmp(inp, cmd[i].name) == 0) {
199 con_printf("?%s\n", inp);
205 static int cmd_list(const char *args)
208 char buf[512], *ptr = buf;
210 nscr = scr_num_screens();
211 for(i=0; i<nscr; i++) {
212 char *sname = scr_screen(i)->name;
215 if(ptr - buf + len > 53) {
217 con_printf("%s", buf);
221 len = sprintf(ptr, "%s ", sname);
226 con_printf("%s", buf);
231 static int cmd_help(const char *args)
233 con_printf("cmds: /, #, ls, help, ?\n");