Restore console, server/client stuff.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/string.h"
|
||||
#include "input.h"
|
||||
|
||||
console_t CONSOLE;
|
||||
|
||||
@@ -20,6 +21,8 @@ void consoleInit() {
|
||||
CONSOLE.cmdGet = consoleRegCmd("get", cmdGet);
|
||||
CONSOLE.cmdSet = consoleRegCmd("set", cmdSet);
|
||||
consoleRegCmd("echo", cmdEcho);
|
||||
|
||||
consolePrint(" = Dawn Console = ");
|
||||
}
|
||||
|
||||
consolecmd_t * consoleRegCmd(const char_t *name, consolecmdfunc_t function) {
|
||||
@@ -331,37 +334,45 @@ void cmdEcho(const consolecmdexec_t *exec) {
|
||||
|
||||
// May move these later
|
||||
void consoleUpdate() {
|
||||
int32_t key = GetKeyPressed();
|
||||
if(inputIsPressed(INPUT_TOGGLE_CONSOLE)) {
|
||||
CONSOLE.open = !CONSOLE.open;
|
||||
} else if(CONSOLE.open) {
|
||||
switch(INPUT.keyPressed) {
|
||||
case 0:
|
||||
break;
|
||||
|
||||
switch(key) {
|
||||
case 0:
|
||||
break;
|
||||
case KEY_ENTER:
|
||||
consoleExec(CONSOLE.inputBuffer);
|
||||
CONSOLE.inputIndex = 0;
|
||||
CONSOLE.inputBuffer[0] = '\0';
|
||||
break;
|
||||
|
||||
case KEY_ENTER:
|
||||
consoleExec(CONSOLE.inputBuffer);
|
||||
CONSOLE.inputIndex = 0;
|
||||
CONSOLE.inputBuffer[0] = '\0';
|
||||
break;
|
||||
case KEY_BACKSPACE:
|
||||
if(CONSOLE.inputIndex > 0) {
|
||||
CONSOLE.inputIndex--;
|
||||
CONSOLE.inputBuffer[CONSOLE.inputIndex] = '\0';
|
||||
}
|
||||
break;
|
||||
|
||||
case KEY_BACKSPACE:
|
||||
if(CONSOLE.inputIndex > 0) {
|
||||
CONSOLE.inputIndex--;
|
||||
CONSOLE.inputBuffer[CONSOLE.inputIndex] = '\0';
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if(key >= 32 && key <= 126 && CONSOLE.inputIndex < CONSOLE_LINE_MAX - 1) {
|
||||
CONSOLE.inputBuffer[CONSOLE.inputIndex++] = (char_t)GetCharPressed();
|
||||
CONSOLE.inputBuffer[CONSOLE.inputIndex] = '\0';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if(
|
||||
INPUT.keyPressed >= 32 &&
|
||||
INPUT.keyPressed <= 126 &&
|
||||
CONSOLE.inputIndex < CONSOLE_LINE_MAX - 1
|
||||
) {
|
||||
CONSOLE.inputBuffer[CONSOLE.inputIndex++] = INPUT.charPressed;
|
||||
CONSOLE.inputBuffer[CONSOLE.inputIndex] = '\0';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
consoleProcess();
|
||||
}
|
||||
|
||||
void consoleDraw() {
|
||||
if(!CONSOLE.open) return;
|
||||
|
||||
size_t i = 0;
|
||||
char_t *line;
|
||||
int32_t fontSize = 10;
|
||||
@@ -371,7 +382,7 @@ void consoleDraw() {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
DrawText(line, 0, i*fontSize, fontSize, BLACK);
|
||||
DrawText(line, 0, i*fontSize, fontSize, YELLOW);
|
||||
i++;
|
||||
} while(i < CONSOLE_HISTORY_MAX);
|
||||
|
||||
@@ -379,6 +390,6 @@ void consoleDraw() {
|
||||
CONSOLE.inputBuffer, 0,
|
||||
(CONSOLE_HISTORY_MAX + 1) * fontSize,
|
||||
fontSize,
|
||||
BLACK
|
||||
PINK
|
||||
);
|
||||
}
|
@@ -42,6 +42,8 @@ typedef struct {
|
||||
// May move these later
|
||||
char_t inputBuffer[CONSOLE_LINE_MAX];
|
||||
int32_t inputIndex;
|
||||
|
||||
bool_t open;
|
||||
} console_t;
|
||||
|
||||
extern console_t CONSOLE;
|
||||
|
Reference in New Issue
Block a user