|
@@ -14,12 +14,12 @@
|
|
|
#include "core/Queue.h"
|
|
|
#include "core/Thread.h"
|
|
|
|
|
|
-#define HISTORY_LENGTH 10
|
|
|
-#define CONSOLE_BUFFER_SIZE 256
|
|
|
+static constexpr size_t HISTORY_LENGTH = 10;
|
|
|
+static constexpr size_t CONSOLE_BUFFER_SIZE = 256;
|
|
|
|
|
|
typedef struct ConsoleLine {
|
|
|
char data[CONSOLE_BUFFER_SIZE];
|
|
|
- int length;
|
|
|
+ size_t length;
|
|
|
} ConsoleLine;
|
|
|
|
|
|
QUEUE(ConsoleLine, CL)
|
|
@@ -31,14 +31,14 @@ static thrd_t readThread = {0};
|
|
|
static struct termios original;
|
|
|
static QueueCL buffer = {0};
|
|
|
static ConsoleLine currentBuffer = {0};
|
|
|
-static int move = 0;
|
|
|
-static int cursorMove = 0;
|
|
|
+static size_t move = 0;
|
|
|
+static size_t cursorMove = 0;
|
|
|
static mtx_t bufferMutex = {0};
|
|
|
|
|
|
static ConsoleLine history[HISTORY_LENGTH];
|
|
|
-static int historyOffset = 0;
|
|
|
-static int historyIndex = 0;
|
|
|
-static int historyLength = 0;
|
|
|
+static size_t historyOffset = 0;
|
|
|
+static size_t historyIndex = 0;
|
|
|
+static size_t historyLength = 0;
|
|
|
|
|
|
static void getAttributes(struct termios* t) {
|
|
|
if(tcgetattr(STDIN_FILENO, t)) {
|
|
@@ -62,7 +62,7 @@ static void addChar(char c) {
|
|
|
if(currentBuffer.length >= CONSOLE_BUFFER_SIZE - 1) {
|
|
|
return;
|
|
|
}
|
|
|
- for(int i = 0; i < move; i++) {
|
|
|
+ for(size_t i = 0; i < move; i++) {
|
|
|
currentBuffer.data[currentBuffer.length - i] =
|
|
|
currentBuffer.data[currentBuffer.length - i - 1];
|
|
|
}
|
|
@@ -79,7 +79,7 @@ static void refreshLine(const char* prefix) {
|
|
|
print(prefix);
|
|
|
print(currentBuffer.data);
|
|
|
if(cursorMove > 0) {
|
|
|
- printf("\33[%dD", cursorMove);
|
|
|
+ printf("\33[%zuD", cursorMove);
|
|
|
}
|
|
|
fflush(stdout);
|
|
|
print("\33[2K\r");
|
|
@@ -127,9 +127,9 @@ static char isUTF8Part(char c) {
|
|
|
}
|
|
|
|
|
|
static bool removeChar() {
|
|
|
- int pos = currentBuffer.length - move;
|
|
|
+ size_t pos = currentBuffer.length - move;
|
|
|
if(pos > 0) {
|
|
|
- int l = 1;
|
|
|
+ size_t l = 1;
|
|
|
while(pos - l >= 0) {
|
|
|
if(!isUTF8Part(currentBuffer.data[pos - l])) {
|
|
|
break;
|
|
@@ -137,7 +137,7 @@ static bool removeChar() {
|
|
|
l++;
|
|
|
}
|
|
|
currentBuffer.length -= l;
|
|
|
- for(int i = pos - l; i <= currentBuffer.length; i++) {
|
|
|
+ for(size_t i = pos - l; i <= currentBuffer.length; i++) {
|
|
|
currentBuffer.data[i] = currentBuffer.data[i + l];
|
|
|
}
|
|
|
}
|