|
@@ -10,25 +10,26 @@
|
|
|
template<int N, int H>
|
|
|
class RawReader final {
|
|
|
struct termios original;
|
|
|
-
|
|
|
+
|
|
|
int index;
|
|
|
char buffer[2][N];
|
|
|
bool bufferIndex;
|
|
|
bool noError;
|
|
|
int move;
|
|
|
-
|
|
|
+
|
|
|
char history[H][N];
|
|
|
int historyOffset;
|
|
|
int historyIndex;
|
|
|
int historyLength;
|
|
|
-
|
|
|
+
|
|
|
const char* prefix;
|
|
|
|
|
|
public:
|
|
|
typedef int DeciSeconds;
|
|
|
|
|
|
- RawReader(DeciSeconds timeout, const char* prefix) : index(0), bufferIndex(false), noError(true), move(0),
|
|
|
- historyOffset(0), historyIndex(0), historyLength(0), prefix(prefix) {
|
|
|
+ RawReader(DeciSeconds timeout, const char* prefix)
|
|
|
+ : index(0), bufferIndex(false), noError(true), move(0), historyOffset(0), historyIndex(0), historyLength(0),
|
|
|
+ prefix(prefix) {
|
|
|
// https://viewsourcecode.org/snaptoken/kilo/02.enteringRawMode.html
|
|
|
if(tcgetattr(STDIN_FILENO, &original) == -1) {
|
|
|
markError();
|
|
@@ -101,7 +102,6 @@ public:
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
-
|
|
|
void print(const char* s) {
|
|
|
fputs(s, stdout);
|
|
|
}
|
|
@@ -183,18 +183,10 @@ private:
|
|
|
return;
|
|
|
}
|
|
|
switch(readChar()) {
|
|
|
- case 'A':
|
|
|
- handleUpArrow();
|
|
|
- break;
|
|
|
- case 'B':
|
|
|
- handleDownArrow();
|
|
|
- break;
|
|
|
- case 'C':
|
|
|
- handleRightArrow();
|
|
|
- break;
|
|
|
- case 'D':
|
|
|
- handleLeftArrow();
|
|
|
- break;
|
|
|
+ case 'A': handleUpArrow(); break;
|
|
|
+ case 'B': handleDownArrow(); break;
|
|
|
+ case 'C': handleRightArrow(); break;
|
|
|
+ case 'D': handleLeftArrow(); break;
|
|
|
}
|
|
|
}
|
|
|
|