2008-03-25 10:02:13 +00:00
|
|
|
#include "solvespace.h"
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
void TextWindow::Init(void) {
|
2008-03-26 09:18:12 +00:00
|
|
|
ClearScreen();
|
|
|
|
ClearCommand();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextWindow::ClearScreen(void) {
|
2008-03-25 10:02:13 +00:00
|
|
|
int i, j;
|
|
|
|
for(i = 0; i < MAX_ROWS; i++) {
|
|
|
|
for(j = 0; j < MAX_COLS; j++) {
|
|
|
|
text[i][j] = ' ';
|
|
|
|
meta[i][j].color = COLOR_NORMAL;
|
|
|
|
meta[i][j].link = NOT_A_LINK;
|
|
|
|
}
|
|
|
|
}
|
2008-03-26 09:18:12 +00:00
|
|
|
row0 = 0;
|
|
|
|
rows = 0;
|
2008-03-25 10:02:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextWindow::Printf(char *fmt, ...) {
|
|
|
|
va_list vl;
|
|
|
|
va_start(vl, fmt);
|
|
|
|
|
|
|
|
int r, c;
|
|
|
|
if(rows < MAX_ROWS) {
|
|
|
|
r = rows;
|
|
|
|
rows++;
|
|
|
|
} else {
|
|
|
|
r = row0;
|
|
|
|
row0++;
|
|
|
|
}
|
|
|
|
for(c = 0; c < MAX_COLS; c++) {
|
|
|
|
text[r][c] = ' ';
|
|
|
|
meta[r][c].link = NOT_A_LINK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int color = COLOR_NORMAL;
|
|
|
|
|
|
|
|
c = 0;
|
|
|
|
while(*fmt) {
|
|
|
|
if(*fmt == '%') {
|
2008-03-26 09:18:12 +00:00
|
|
|
fmt++;
|
|
|
|
if(*fmt == '\0') goto done;
|
|
|
|
switch(*fmt) {
|
|
|
|
case 's': {
|
|
|
|
char *s = va_arg(vl, char *);
|
|
|
|
memcpy(&(text[r][c]), s, strlen(s));
|
|
|
|
c += strlen(s);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'd': {
|
|
|
|
int v = va_arg(vl, int);
|
|
|
|
sprintf((char *)&(text[r][c]), "%d", v);
|
|
|
|
c += strlen((char *)&(text[r][c]));
|
|
|
|
text[r][c] = ' ';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '%':
|
|
|
|
text[r][c++] = '%';
|
|
|
|
break;
|
|
|
|
}
|
2008-03-25 10:02:13 +00:00
|
|
|
} else {
|
|
|
|
if(c >= MAX_COLS) goto done;
|
|
|
|
text[r][c++] = *fmt;
|
|
|
|
}
|
|
|
|
fmt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
va_end(vl);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextWindow::ClearCommand(void) {
|
|
|
|
int j;
|
|
|
|
for(j = 0; j < MAX_COLS; j++) {
|
|
|
|
cmd[j] = ' ';
|
|
|
|
}
|
|
|
|
memcpy(cmd, "+> ", 3);
|
|
|
|
cmdLen = 0;
|
|
|
|
cmdInsert = 3;
|
2008-03-26 09:18:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextWindow::ProcessCommand(char *cmd)
|
|
|
|
{
|
|
|
|
Printf("command: '%s'", cmd);
|
2008-03-25 10:02:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextWindow::KeyPressed(int c) {
|
|
|
|
if(cmdLen >= MAX_COLS - 10) {
|
|
|
|
ClearCommand();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(c == '\n' || c == '\r') {
|
2008-03-26 09:18:12 +00:00
|
|
|
cmd[cmdLen+3] = '\0';
|
|
|
|
ProcessCommand(cmd+3);
|
|
|
|
|
2008-03-25 10:02:13 +00:00
|
|
|
ClearCommand();
|
|
|
|
return;
|
|
|
|
} else if(c == 27) {
|
|
|
|
ClearCommand();
|
2008-03-26 09:18:12 +00:00
|
|
|
} else if(c == 'l' - 'a' + 1) {
|
|
|
|
ClearScreen();
|
2008-03-25 10:02:13 +00:00
|
|
|
} else if(c == '\b') {
|
|
|
|
// backspace, delete from insertion point
|
|
|
|
if(cmdInsert <= 3) return;
|
|
|
|
memmove(cmd+cmdInsert-1, cmd+cmdInsert, MAX_COLS-cmdInsert);
|
|
|
|
cmdLen--;
|
|
|
|
cmdInsert--;
|
|
|
|
} else {
|
|
|
|
cmd[cmdInsert] = c;
|
|
|
|
cmdInsert++;
|
|
|
|
cmdLen++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|