Fix formatting issues
This commit is contained in:
parent
2ea1f071e6
commit
b0445819cf
@ -90,7 +90,7 @@ static void consoleCls(int mode) {
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case 0:
|
||||
case 0:
|
||||
{
|
||||
colTemp = currentConsole->cursorX ;
|
||||
rowTemp = currentConsole->cursorY ;
|
||||
@ -102,7 +102,7 @@ static void consoleCls(int mode) {
|
||||
currentConsole->cursorY = rowTemp;
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
case 1:
|
||||
{
|
||||
colTemp = currentConsole->cursorX ;
|
||||
rowTemp = currentConsole->cursorY ;
|
||||
@ -117,7 +117,7 @@ static void consoleCls(int mode) {
|
||||
currentConsole->cursorY = rowTemp;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
case 2:
|
||||
{
|
||||
currentConsole->cursorY = 0;
|
||||
currentConsole->cursorX = 0;
|
||||
@ -141,7 +141,7 @@ static void consoleClearLine(int mode) {
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case 0:
|
||||
case 0:
|
||||
{
|
||||
colTemp = currentConsole->cursorX ;
|
||||
|
||||
@ -153,7 +153,7 @@ static void consoleClearLine(int mode) {
|
||||
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
case 1:
|
||||
{
|
||||
colTemp = currentConsole->cursorX ;
|
||||
|
||||
@ -167,7 +167,7 @@ static void consoleClearLine(int mode) {
|
||||
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
case 2:
|
||||
{
|
||||
colTemp = currentConsole->cursorX ;
|
||||
|
||||
@ -249,7 +249,7 @@ static struct
|
||||
ESC_BUILDING_FORMAT_FG_NONRGB,
|
||||
ESC_BUILDING_FORMAT_BG_NONRGB,
|
||||
ESC_BUILDING_FORMAT_FG_RGB,
|
||||
ESC_BUILDING_FORMAT_BG_RGB
|
||||
ESC_BUILDING_FORMAT_BG_RGB,
|
||||
} state;
|
||||
} escapeSeq;
|
||||
|
||||
@ -257,182 +257,182 @@ static void consoleHandleColorEsc(int code)
|
||||
{
|
||||
switch (escapeSeq.state)
|
||||
{
|
||||
case ESC_BUILDING_FORMAT_UNKNOWN:
|
||||
switch (code)
|
||||
{
|
||||
case 0: // reset
|
||||
escapeSeq.color.flags = 0;
|
||||
escapeSeq.color.bg = 0;
|
||||
escapeSeq.color.fg = 7;
|
||||
break;
|
||||
case ESC_BUILDING_FORMAT_UNKNOWN:
|
||||
switch (code)
|
||||
{
|
||||
case 0: // reset
|
||||
escapeSeq.color.flags = 0;
|
||||
escapeSeq.color.bg = 0;
|
||||
escapeSeq.color.fg = 7;
|
||||
break;
|
||||
|
||||
case 1: // bold
|
||||
escapeSeq.color.flags &= ~CONSOLE_COLOR_FAINT;
|
||||
escapeSeq.color.flags |= CONSOLE_COLOR_BOLD;
|
||||
break;
|
||||
case 1: // bold
|
||||
escapeSeq.color.flags &= ~CONSOLE_COLOR_FAINT;
|
||||
escapeSeq.color.flags |= CONSOLE_COLOR_BOLD;
|
||||
break;
|
||||
|
||||
case 2: // faint
|
||||
escapeSeq.color.flags &= ~CONSOLE_COLOR_BOLD;
|
||||
escapeSeq.color.flags |= CONSOLE_COLOR_FAINT;
|
||||
break;
|
||||
case 2: // faint
|
||||
escapeSeq.color.flags &= ~CONSOLE_COLOR_BOLD;
|
||||
escapeSeq.color.flags |= CONSOLE_COLOR_FAINT;
|
||||
break;
|
||||
|
||||
case 3: // italic
|
||||
escapeSeq.color.flags |= CONSOLE_ITALIC;
|
||||
break;
|
||||
case 3: // italic
|
||||
escapeSeq.color.flags |= CONSOLE_ITALIC;
|
||||
break;
|
||||
|
||||
case 4: // underline
|
||||
escapeSeq.color.flags |= CONSOLE_UNDERLINE;
|
||||
break;
|
||||
case 4: // underline
|
||||
escapeSeq.color.flags |= CONSOLE_UNDERLINE;
|
||||
break;
|
||||
|
||||
case 5: // blink slow
|
||||
escapeSeq.color.flags &= ~CONSOLE_BLINK_FAST;
|
||||
escapeSeq.color.flags |= CONSOLE_BLINK_SLOW;
|
||||
break;
|
||||
case 5: // blink slow
|
||||
escapeSeq.color.flags &= ~CONSOLE_BLINK_FAST;
|
||||
escapeSeq.color.flags |= CONSOLE_BLINK_SLOW;
|
||||
break;
|
||||
|
||||
case 6: // blink fast
|
||||
escapeSeq.color.flags &= ~CONSOLE_BLINK_SLOW;
|
||||
escapeSeq.color.flags |= CONSOLE_BLINK_FAST;
|
||||
break;
|
||||
case 6: // blink fast
|
||||
escapeSeq.color.flags &= ~CONSOLE_BLINK_SLOW;
|
||||
escapeSeq.color.flags |= CONSOLE_BLINK_FAST;
|
||||
break;
|
||||
|
||||
case 7: // reverse video
|
||||
escapeSeq.color.flags |= CONSOLE_COLOR_REVERSE;
|
||||
break;
|
||||
case 7: // reverse video
|
||||
escapeSeq.color.flags |= CONSOLE_COLOR_REVERSE;
|
||||
break;
|
||||
|
||||
case 8: // conceal
|
||||
escapeSeq.color.flags |= CONSOLE_CONCEAL;
|
||||
break;
|
||||
case 8: // conceal
|
||||
escapeSeq.color.flags |= CONSOLE_CONCEAL;
|
||||
break;
|
||||
|
||||
case 9: // crossed-out
|
||||
escapeSeq.color.flags |= CONSOLE_CROSSED_OUT;
|
||||
break;
|
||||
case 9: // crossed-out
|
||||
escapeSeq.color.flags |= CONSOLE_CROSSED_OUT;
|
||||
break;
|
||||
|
||||
case 21: // bold off
|
||||
escapeSeq.color.flags &= ~CONSOLE_COLOR_BOLD;
|
||||
break;
|
||||
case 21: // bold off
|
||||
escapeSeq.color.flags &= ~CONSOLE_COLOR_BOLD;
|
||||
break;
|
||||
|
||||
case 22: // normal color
|
||||
escapeSeq.color.flags &= ~CONSOLE_COLOR_BOLD;
|
||||
escapeSeq.color.flags &= ~CONSOLE_COLOR_FAINT;
|
||||
break;
|
||||
case 22: // normal color
|
||||
escapeSeq.color.flags &= ~CONSOLE_COLOR_BOLD;
|
||||
escapeSeq.color.flags &= ~CONSOLE_COLOR_FAINT;
|
||||
break;
|
||||
|
||||
case 23: // italic off
|
||||
escapeSeq.color.flags &= ~CONSOLE_ITALIC;
|
||||
break;
|
||||
case 23: // italic off
|
||||
escapeSeq.color.flags &= ~CONSOLE_ITALIC;
|
||||
break;
|
||||
|
||||
case 24: // underline off
|
||||
escapeSeq.color.flags &= ~CONSOLE_UNDERLINE;
|
||||
break;
|
||||
case 24: // underline off
|
||||
escapeSeq.color.flags &= ~CONSOLE_UNDERLINE;
|
||||
break;
|
||||
|
||||
case 25: // blink off
|
||||
escapeSeq.color.flags &= ~CONSOLE_BLINK_SLOW;
|
||||
escapeSeq.color.flags &= ~CONSOLE_BLINK_FAST;
|
||||
break;
|
||||
case 25: // blink off
|
||||
escapeSeq.color.flags &= ~CONSOLE_BLINK_SLOW;
|
||||
escapeSeq.color.flags &= ~CONSOLE_BLINK_FAST;
|
||||
break;
|
||||
|
||||
case 27: // reverse off
|
||||
escapeSeq.color.flags &= ~CONSOLE_COLOR_REVERSE;
|
||||
break;
|
||||
case 27: // reverse off
|
||||
escapeSeq.color.flags &= ~CONSOLE_COLOR_REVERSE;
|
||||
break;
|
||||
|
||||
case 29: // crossed-out off
|
||||
escapeSeq.color.flags &= ~CONSOLE_CROSSED_OUT;
|
||||
break;
|
||||
case 29: // crossed-out off
|
||||
escapeSeq.color.flags &= ~CONSOLE_CROSSED_OUT;
|
||||
break;
|
||||
|
||||
case 30 ... 37: // writing color
|
||||
escapeSeq.color.flags &= ~CONSOLE_FG_CUSTOM;
|
||||
escapeSeq.color.fg = code - 30;
|
||||
break;
|
||||
case 30 ... 37: // writing color
|
||||
escapeSeq.color.flags &= ~CONSOLE_FG_CUSTOM;
|
||||
escapeSeq.color.fg = code - 30;
|
||||
break;
|
||||
|
||||
case 38: // custom foreground color
|
||||
escapeSeq.state = ESC_BUILDING_FORMAT_FG;
|
||||
break;
|
||||
case 38: // custom foreground color
|
||||
escapeSeq.state = ESC_BUILDING_FORMAT_FG;
|
||||
break;
|
||||
|
||||
case 39: // reset foreground color
|
||||
escapeSeq.color.flags &= ~CONSOLE_FG_CUSTOM;
|
||||
escapeSeq.color.fg = 7;
|
||||
break;
|
||||
case 39: // reset foreground color
|
||||
escapeSeq.color.flags &= ~CONSOLE_FG_CUSTOM;
|
||||
escapeSeq.color.fg = 7;
|
||||
break;
|
||||
|
||||
case 40 ... 47: // screen color
|
||||
escapeSeq.color.flags &= ~CONSOLE_BG_CUSTOM;
|
||||
escapeSeq.color.bg = code - 40;
|
||||
break;
|
||||
case 40 ... 47: // screen color
|
||||
escapeSeq.color.flags &= ~CONSOLE_BG_CUSTOM;
|
||||
escapeSeq.color.bg = code - 40;
|
||||
break;
|
||||
|
||||
case 48: // custom background color
|
||||
escapeSeq.state = ESC_BUILDING_FORMAT_BG;
|
||||
break;
|
||||
case 48: // custom background color
|
||||
escapeSeq.state = ESC_BUILDING_FORMAT_BG;
|
||||
break;
|
||||
|
||||
case 49: // reset background color
|
||||
escapeSeq.color.flags &= ~CONSOLE_BG_CUSTOM;
|
||||
escapeSeq.color.fg = 0;
|
||||
case 49: // reset background color
|
||||
escapeSeq.color.flags &= ~CONSOLE_BG_CUSTOM;
|
||||
escapeSeq.color.fg = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ESC_BUILDING_FORMAT_FG:
|
||||
if (escapeSeq.color.args[0] == 5)
|
||||
escapeSeq.state = ESC_BUILDING_FORMAT_FG_NONRGB;
|
||||
else if (escapeSeq.color.args[0] == 2)
|
||||
escapeSeq.state = ESC_BUILDING_FORMAT_FG_RGB;
|
||||
else
|
||||
escapeSeq.state = ESC_BUILDING_FORMAT_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ESC_BUILDING_FORMAT_FG:
|
||||
if (escapeSeq.color.args[0] == 5)
|
||||
escapeSeq.state = ESC_BUILDING_FORMAT_FG_NONRGB;
|
||||
else if (escapeSeq.color.args[0] == 2)
|
||||
escapeSeq.state = ESC_BUILDING_FORMAT_FG_RGB;
|
||||
else
|
||||
case ESC_BUILDING_FORMAT_BG:
|
||||
if (escapeSeq.color.args[0] == 5)
|
||||
escapeSeq.state = ESC_BUILDING_FORMAT_BG_NONRGB;
|
||||
else if (escapeSeq.color.args[0] == 2)
|
||||
escapeSeq.state = ESC_BUILDING_FORMAT_BG_RGB;
|
||||
else
|
||||
escapeSeq.state = ESC_BUILDING_FORMAT_UNKNOWN;
|
||||
break;
|
||||
case ESC_BUILDING_FORMAT_FG_NONRGB:
|
||||
if (code <= 15) {
|
||||
escapeSeq.color.fg = code;
|
||||
escapeSeq.color.flags &= ~CONSOLE_FG_CUSTOM;
|
||||
} else if (code <= 231) {
|
||||
code -= 16;
|
||||
unsigned int r = code / 36;
|
||||
unsigned int g = (code - r * 36) / 6;
|
||||
unsigned int b = code - r * 36 - g * 6;
|
||||
|
||||
escapeSeq.color.fg = RGB8_to_565 (colorCube[r], colorCube[g], colorCube[b]);
|
||||
escapeSeq.color.flags |= CONSOLE_FG_CUSTOM;
|
||||
} else if (code <= 255) {
|
||||
code -= 232;
|
||||
|
||||
escapeSeq.color.fg = RGB8_to_565 (grayScale[code], grayScale[code], grayScale[code]);
|
||||
escapeSeq.color.flags |= CONSOLE_FG_CUSTOM;
|
||||
}
|
||||
escapeSeq.state = ESC_BUILDING_FORMAT_UNKNOWN;
|
||||
break;
|
||||
case ESC_BUILDING_FORMAT_BG:
|
||||
if (escapeSeq.color.args[0] == 5)
|
||||
escapeSeq.state = ESC_BUILDING_FORMAT_BG_NONRGB;
|
||||
else if (escapeSeq.color.args[0] == 2)
|
||||
escapeSeq.state = ESC_BUILDING_FORMAT_BG_RGB;
|
||||
else
|
||||
break;
|
||||
case ESC_BUILDING_FORMAT_BG_NONRGB:
|
||||
if (code <= 15) {
|
||||
escapeSeq.color.bg = code;
|
||||
escapeSeq.color.flags &= ~CONSOLE_BG_CUSTOM;
|
||||
} else if (code <= 231) {
|
||||
code -= 16;
|
||||
unsigned int r = code / 36;
|
||||
unsigned int g = (code - r * 36) / 6;
|
||||
unsigned int b = code - r * 36 - g * 6;
|
||||
|
||||
escapeSeq.color.bg = RGB8_to_565 (colorCube[r], colorCube[g], colorCube[b]);
|
||||
escapeSeq.color.flags |= CONSOLE_BG_CUSTOM;
|
||||
} else if (code <= 255) {
|
||||
code -= 232;
|
||||
|
||||
escapeSeq.color.bg = RGB8_to_565 (grayScale[code], grayScale[code], grayScale[code]);
|
||||
escapeSeq.color.flags |= CONSOLE_BG_CUSTOM;
|
||||
}
|
||||
escapeSeq.state = ESC_BUILDING_FORMAT_UNKNOWN;
|
||||
break;
|
||||
case ESC_BUILDING_FORMAT_FG_NONRGB:
|
||||
if (code <= 15) {
|
||||
escapeSeq.color.fg = code;
|
||||
escapeSeq.color.flags &= ~CONSOLE_FG_CUSTOM;
|
||||
} else if (code <= 231) {
|
||||
code -= 16;
|
||||
unsigned int r = code / 36;
|
||||
unsigned int g = (code - r * 36) / 6;
|
||||
unsigned int b = code - r * 36 - g * 6;
|
||||
|
||||
escapeSeq.color.fg = RGB8_to_565 (colorCube[r], colorCube[g], colorCube[b]);
|
||||
break;
|
||||
case ESC_BUILDING_FORMAT_FG_RGB:
|
||||
escapeSeq.color.fg = RGB8_to_565((unsigned int)escapeSeq.color.args[0], (unsigned int)escapeSeq.color.args[1], (unsigned int)escapeSeq.color.args[2]);
|
||||
escapeSeq.color.flags |= CONSOLE_FG_CUSTOM;
|
||||
} else if (code <= 255) {
|
||||
code -= 232;
|
||||
|
||||
escapeSeq.color.fg = RGB8_to_565 (grayScale[code], grayScale[code], grayScale[code]);
|
||||
escapeSeq.color.flags |= CONSOLE_FG_CUSTOM;
|
||||
}
|
||||
escapeSeq.state = ESC_BUILDING_FORMAT_UNKNOWN;
|
||||
break;
|
||||
case ESC_BUILDING_FORMAT_BG_NONRGB:
|
||||
if (code <= 15) {
|
||||
escapeSeq.color.bg = code;
|
||||
escapeSeq.color.flags &= ~CONSOLE_BG_CUSTOM;
|
||||
} else if (code <= 231) {
|
||||
code -= 16;
|
||||
unsigned int r = code / 36;
|
||||
unsigned int g = (code - r * 36) / 6;
|
||||
unsigned int b = code - r * 36 - g * 6;
|
||||
|
||||
escapeSeq.color.bg = RGB8_to_565 (colorCube[r], colorCube[g], colorCube[b]);
|
||||
escapeSeq.state = ESC_BUILDING_FORMAT_UNKNOWN;
|
||||
break;
|
||||
case ESC_BUILDING_FORMAT_BG_RGB:
|
||||
escapeSeq.color.bg = RGB8_to_565((unsigned int)escapeSeq.color.args[0], (unsigned int)escapeSeq.color.args[1], (unsigned int)escapeSeq.color.args[2]);
|
||||
escapeSeq.color.flags |= CONSOLE_BG_CUSTOM;
|
||||
} else if (code <= 255) {
|
||||
code -= 232;
|
||||
|
||||
escapeSeq.color.bg = RGB8_to_565 (grayScale[code], grayScale[code], grayScale[code]);
|
||||
escapeSeq.color.flags |= CONSOLE_BG_CUSTOM;
|
||||
}
|
||||
escapeSeq.state = ESC_BUILDING_FORMAT_UNKNOWN;
|
||||
break;
|
||||
case ESC_BUILDING_FORMAT_FG_RGB:
|
||||
escapeSeq.color.fg = RGB8_to_565((unsigned int)escapeSeq.color.args[0], (unsigned int)escapeSeq.color.args[1], (unsigned int)escapeSeq.color.args[2]);
|
||||
escapeSeq.color.flags |= CONSOLE_FG_CUSTOM;
|
||||
escapeSeq.state = ESC_BUILDING_FORMAT_UNKNOWN;
|
||||
break;
|
||||
case ESC_BUILDING_FORMAT_BG_RGB:
|
||||
escapeSeq.color.bg = RGB8_to_565((unsigned int)escapeSeq.color.args[0], (unsigned int)escapeSeq.color.args[1], (unsigned int)escapeSeq.color.args[2]);
|
||||
escapeSeq.color.flags |= CONSOLE_BG_CUSTOM;
|
||||
escapeSeq.state = ESC_BUILDING_FORMAT_UNKNOWN;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
escapeSeq.state = ESC_BUILDING_FORMAT_UNKNOWN;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
escapeSeq.argIdx = 0;
|
||||
}
|
||||
@ -461,14 +461,9 @@ static void consoleColorStateShift(void)
|
||||
case ESC_BUILDING_FORMAT_FG_RGB:
|
||||
case ESC_BUILDING_FORMAT_BG_RGB:
|
||||
if (escapeSeq.argIdx < 3)
|
||||
{
|
||||
escapeSeq.argIdx++;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Nothing passed here because three RGB items
|
||||
consoleHandleColorEsc(0);
|
||||
}
|
||||
consoleHandleColorEsc(0); // Nothing passed here because three RGB items
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -502,167 +497,163 @@ ssize_t con_write(struct _reent *r,void *fd,const char *ptr, size_t len) {
|
||||
|
||||
switch (escapeSeq.state)
|
||||
{
|
||||
case ESC_NONE:
|
||||
if (chr == 0x1b)
|
||||
{
|
||||
escapeSeq.state = ESC_START;
|
||||
}
|
||||
else
|
||||
{
|
||||
consolePrintChar(chr);
|
||||
}
|
||||
break;
|
||||
case ESC_START:
|
||||
if (chr == '[')
|
||||
{
|
||||
escapeSeq.state = ESC_BUILDING_UNKNOWN;
|
||||
memset(escapeSeq.rawBuf, 0, sizeof(escapeSeq.rawBuf));
|
||||
memset(escapeSeq.hasArg, 0, sizeof(escapeSeq.hasArg));
|
||||
escapeSeq.color.bg = currentConsole->bg;
|
||||
escapeSeq.color.fg = currentConsole->fg;
|
||||
escapeSeq.color.flags = currentConsole->flags;
|
||||
escapeSeq.argIdx = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
consolePrintChar(0x1b);
|
||||
consolePrintChar(chr);
|
||||
escapeSeq.state = ESC_NONE;
|
||||
}
|
||||
break;
|
||||
case ESC_BUILDING_UNKNOWN:
|
||||
switch (chr)
|
||||
{
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
escapeSeq.hasArg[escapeSeq.argIdx] = true;
|
||||
escapeSeq.rawBuf[escapeSeq.argIdx] = escapeSeq.rawBuf[escapeSeq.argIdx] * 10 + (chr - '0');
|
||||
break;
|
||||
case ';':
|
||||
if (escapeSeq.argIdx < 2)
|
||||
escapeSeq.argIdx++;
|
||||
case ESC_NONE:
|
||||
if (chr == 0x1b)
|
||||
escapeSeq.state = ESC_START;
|
||||
else
|
||||
consoleColorStateShift();
|
||||
consolePrintChar(chr);
|
||||
break;
|
||||
|
||||
//---------------------------------------
|
||||
// Cursor directional movement
|
||||
//---------------------------------------
|
||||
case 'A':
|
||||
if (!escapeSeq.hasArg[0])
|
||||
escapeSeq.directional.movement = 1;
|
||||
currentConsole->cursorY = (currentConsole->cursorY - escapeSeq.directional.movement) < 0 ? 0 : currentConsole->cursorY - escapeSeq.directional.movement;
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
case 'B':
|
||||
if (!escapeSeq.hasArg[0])
|
||||
escapeSeq.directional.movement = 1;
|
||||
currentConsole->cursorY = (currentConsole->cursorY + escapeSeq.directional.movement) > currentConsole->windowHeight - 1 ? currentConsole->windowHeight - 1 : currentConsole->cursorY + escapeSeq.directional.movement;
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
case 'C':
|
||||
if (!escapeSeq.hasArg[0])
|
||||
escapeSeq.directional.movement = 1;
|
||||
currentConsole->cursorX = (currentConsole->cursorX + escapeSeq.directional.movement) > currentConsole->windowWidth - 1 ? currentConsole->windowWidth - 1 : currentConsole->cursorX + escapeSeq.directional.movement;
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
case 'D':
|
||||
if (!escapeSeq.hasArg[0])
|
||||
escapeSeq.directional.movement = 1;
|
||||
currentConsole->cursorX = (currentConsole->cursorX - escapeSeq.directional.movement) < 0 ? 0 : currentConsole->cursorX - escapeSeq.directional.movement;
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
//---------------------------------------
|
||||
// Cursor position movement
|
||||
//---------------------------------------
|
||||
case 'H':
|
||||
case 'f':
|
||||
consolePosition(escapeSeq.hasArg[1] ? escapeSeq.absolute.x : 1, escapeSeq.hasArg[0] ? escapeSeq.absolute.y : 1);
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
//---------------------------------------
|
||||
// Screen clear
|
||||
//---------------------------------------
|
||||
case 'J':
|
||||
consoleCls(escapeSeq.hasArg[0] ? escapeSeq.clear.type : 0);
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
//---------------------------------------
|
||||
// Line clear
|
||||
//---------------------------------------
|
||||
case 'K':
|
||||
consoleClearLine(escapeSeq.hasArg[0] ? escapeSeq.clear.type : 0);
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
//---------------------------------------
|
||||
// Save cursor position
|
||||
//---------------------------------------
|
||||
case 's':
|
||||
currentConsole->prevCursorX = currentConsole->cursorX ;
|
||||
currentConsole->prevCursorY = currentConsole->cursorY ;
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
//---------------------------------------
|
||||
// Load cursor position
|
||||
//---------------------------------------
|
||||
case 'u':
|
||||
currentConsole->cursorX = currentConsole->prevCursorX ;
|
||||
currentConsole->cursorY = currentConsole->prevCursorY ;
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
//---------------------------------------
|
||||
// Color scan codes
|
||||
//---------------------------------------
|
||||
case 'm':
|
||||
consoleColorStateShift();
|
||||
consoleColorApply();
|
||||
escapeSeq.state = ESC_NONE;
|
||||
case ESC_START:
|
||||
if (chr == '[')
|
||||
{
|
||||
escapeSeq.state = ESC_BUILDING_UNKNOWN;
|
||||
memset(escapeSeq.rawBuf, 0, sizeof(escapeSeq.rawBuf));
|
||||
memset(escapeSeq.hasArg, 0, sizeof(escapeSeq.hasArg));
|
||||
escapeSeq.color.bg = currentConsole->bg;
|
||||
escapeSeq.color.fg = currentConsole->fg;
|
||||
escapeSeq.color.flags = currentConsole->flags;
|
||||
escapeSeq.argIdx = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
consolePrintChar(0x1b);
|
||||
consolePrintChar(chr);
|
||||
escapeSeq.state = ESC_NONE;
|
||||
}
|
||||
break;
|
||||
case ESC_BUILDING_UNKNOWN:
|
||||
switch (chr)
|
||||
{
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
escapeSeq.hasArg[escapeSeq.argIdx] = true;
|
||||
escapeSeq.rawBuf[escapeSeq.argIdx] = escapeSeq.rawBuf[escapeSeq.argIdx] * 10 + (chr - '0');
|
||||
break;
|
||||
case ';':
|
||||
if (escapeSeq.argIdx < 2)
|
||||
escapeSeq.argIdx++;
|
||||
else
|
||||
consoleColorStateShift();
|
||||
break;
|
||||
|
||||
//---------------------------------------
|
||||
// Cursor directional movement
|
||||
//---------------------------------------
|
||||
case 'A':
|
||||
if (!escapeSeq.hasArg[0])
|
||||
escapeSeq.directional.movement = 1;
|
||||
currentConsole->cursorY = (currentConsole->cursorY - escapeSeq.directional.movement) < 0 ? 0 : currentConsole->cursorY - escapeSeq.directional.movement;
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
case 'B':
|
||||
if (!escapeSeq.hasArg[0])
|
||||
escapeSeq.directional.movement = 1;
|
||||
currentConsole->cursorY = (currentConsole->cursorY + escapeSeq.directional.movement) > currentConsole->windowHeight - 1 ? currentConsole->windowHeight - 1 : currentConsole->cursorY + escapeSeq.directional.movement;
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
case 'C':
|
||||
if (!escapeSeq.hasArg[0])
|
||||
escapeSeq.directional.movement = 1;
|
||||
currentConsole->cursorX = (currentConsole->cursorX + escapeSeq.directional.movement) > currentConsole->windowWidth - 1 ? currentConsole->windowWidth - 1 : currentConsole->cursorX + escapeSeq.directional.movement;
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
case 'D':
|
||||
if (!escapeSeq.hasArg[0])
|
||||
escapeSeq.directional.movement = 1;
|
||||
currentConsole->cursorX = (currentConsole->cursorX - escapeSeq.directional.movement) < 0 ? 0 : currentConsole->cursorX - escapeSeq.directional.movement;
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
//---------------------------------------
|
||||
// Cursor position movement
|
||||
//---------------------------------------
|
||||
case 'H':
|
||||
case 'f':
|
||||
consolePosition(escapeSeq.hasArg[1] ? escapeSeq.absolute.x : 1, escapeSeq.hasArg[0] ? escapeSeq.absolute.y : 1);
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
//---------------------------------------
|
||||
// Screen clear
|
||||
//---------------------------------------
|
||||
case 'J':
|
||||
consoleCls(escapeSeq.hasArg[0] ? escapeSeq.clear.type : 0);
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
//---------------------------------------
|
||||
// Line clear
|
||||
//---------------------------------------
|
||||
case 'K':
|
||||
consoleClearLine(escapeSeq.hasArg[0] ? escapeSeq.clear.type : 0);
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
//---------------------------------------
|
||||
// Save cursor position
|
||||
//---------------------------------------
|
||||
case 's':
|
||||
currentConsole->prevCursorX = currentConsole->cursorX ;
|
||||
currentConsole->prevCursorY = currentConsole->cursorY ;
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
//---------------------------------------
|
||||
// Load cursor position
|
||||
//---------------------------------------
|
||||
case 'u':
|
||||
currentConsole->cursorX = currentConsole->prevCursorX ;
|
||||
currentConsole->cursorY = currentConsole->prevCursorY ;
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
//---------------------------------------
|
||||
// Color scan codes
|
||||
//---------------------------------------
|
||||
case 'm':
|
||||
consoleColorStateShift();
|
||||
consoleColorApply();
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
|
||||
default:
|
||||
// some sort of unsupported escape; just gloss over it
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
switch (chr)
|
||||
{
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
escapeSeq.hasArg[escapeSeq.argIdx] = true;
|
||||
escapeSeq.rawBuf[escapeSeq.argIdx] = escapeSeq.rawBuf[escapeSeq.argIdx] * 10 + (chr - '0');
|
||||
break;
|
||||
case ';':
|
||||
consoleColorStateShift();
|
||||
break;
|
||||
case 'm':
|
||||
consoleColorStateShift();
|
||||
consoleColorApply();
|
||||
escapeSeq.state = ESC_NONE;
|
||||
default:
|
||||
// some sort of unsupported escape; just gloss over it
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// some sort of unsupported escape; just gloss over it
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
switch (chr)
|
||||
{
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
escapeSeq.hasArg[escapeSeq.argIdx] = true;
|
||||
escapeSeq.rawBuf[escapeSeq.argIdx] = escapeSeq.rawBuf[escapeSeq.argIdx] * 10 + (chr - '0');
|
||||
break;
|
||||
case ';':
|
||||
consoleColorStateShift();
|
||||
break;
|
||||
case 'm':
|
||||
consoleColorStateShift();
|
||||
consoleColorApply();
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
default:
|
||||
// some sort of unsupported escape; just gloss over it
|
||||
escapeSeq.state = ESC_NONE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
@ -762,18 +753,18 @@ void consoleDebugInit(debugDevice device){
|
||||
|
||||
int buffertype = _IONBF;
|
||||
|
||||
switch(device) {
|
||||
|
||||
case debugDevice_SVC:
|
||||
devoptab_list[STD_ERR] = &dotab_svc;
|
||||
buffertype = _IOLBF;
|
||||
break;
|
||||
case debugDevice_CONSOLE:
|
||||
devoptab_list[STD_ERR] = &dotab_stdout;
|
||||
break;
|
||||
case debugDevice_NULL:
|
||||
devoptab_list[STD_ERR] = &dotab_null;
|
||||
break;
|
||||
switch(device)
|
||||
{
|
||||
case debugDevice_SVC:
|
||||
devoptab_list[STD_ERR] = &dotab_svc;
|
||||
buffertype = _IOLBF;
|
||||
break;
|
||||
case debugDevice_CONSOLE:
|
||||
devoptab_list[STD_ERR] = &dotab_stdout;
|
||||
break;
|
||||
case debugDevice_NULL:
|
||||
devoptab_list[STD_ERR] = &dotab_null;
|
||||
break;
|
||||
}
|
||||
setvbuf(stderr, NULL , buffertype, 0);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user