|
@@ -35,6 +35,33 @@ ANSI_TYPE console_ansi(struct console_details *cdp, const char *ansi);
|
|
|
termchar console_char(struct console_details *cdp, char ch);
|
|
|
void console_receive(struct console_details *cdp, std::string chars);
|
|
|
|
|
|
+// Ok, it's a problem testing this. :(
|
|
|
+
|
|
|
+class Terminal {
|
|
|
+private:
|
|
|
+ int posx, posy;
|
|
|
+ std::vector<std::pair<int, int>> saved_cursor_position;
|
|
|
+ std::string ansi;
|
|
|
+ int in_ansi;
|
|
|
+ int fgcolor, bgcolor, status;
|
|
|
+ enum ANSI_TYPE { START, CURSOR, COLOR, CLEAR, OTHER };
|
|
|
+ struct termchar {
|
|
|
+ int in_ansi;
|
|
|
+ ANSI_TYPE ansi;
|
|
|
+ };
|
|
|
+
|
|
|
+public:
|
|
|
+ Terminal(void);
|
|
|
+ void init(void);
|
|
|
+ std::string color_restore(void);
|
|
|
+ termchar putchar(char ch);
|
|
|
+ void putstring(std::string text);
|
|
|
+
|
|
|
+private:
|
|
|
+ void ansi_color(int color);
|
|
|
+ ANSI_TYPE ansi_code(std::string ansi);
|
|
|
+};
|
|
|
+
|
|
|
*/
|
|
|
|
|
|
console_details console;
|
|
@@ -54,7 +81,7 @@ TEST(ConsoleInit, init) {
|
|
|
ASSERT_EQ(console.bgcolor, 0);
|
|
|
ASSERT_EQ(console.fgcolor, 7);
|
|
|
|
|
|
- std::string reset("\x1b[0m\x1b[2J\x1b[1;1H");
|
|
|
+ // std::string reset("\x1b[0m\x1b[2J\x1b[1;1H");
|
|
|
console_receive(&console, reset);
|
|
|
ASSERT_EQ(console.posx, 0);
|
|
|
ASSERT_EQ(console.posy, 0);
|
|
@@ -121,4 +148,84 @@ TEST(ConsoleCRNL, NLCRTests) {
|
|
|
ASSERT_EQ(console.posy, 1);
|
|
|
}
|
|
|
|
|
|
+TEST(Terminal, init) {
|
|
|
+ Terminal term;
|
|
|
+
|
|
|
+ ASSERT_EQ(term.getx(), 0);
|
|
|
+ ASSERT_EQ(term.gety(), 0);
|
|
|
+ ASSERT_EQ(term.inANSI(), 0);
|
|
|
+ ASSERT_TRUE(term.ansiempty());
|
|
|
+ ASSERT_EQ(term.getstatus(), 0);
|
|
|
+ ASSERT_EQ(term.bg(), 0);
|
|
|
+ ASSERT_EQ(term.fg(), 7);
|
|
|
+
|
|
|
+ term.putstring(reset);
|
|
|
+
|
|
|
+ ASSERT_EQ(term.getx(), 0);
|
|
|
+ ASSERT_EQ(term.gety(), 0);
|
|
|
+ ASSERT_EQ(term.inANSI(), 0);
|
|
|
+ ASSERT_TRUE(term.ansiempty());
|
|
|
+ ASSERT_EQ(term.getstatus(), 0);
|
|
|
+ ASSERT_EQ(term.bg(), 0);
|
|
|
+ ASSERT_EQ(term.fg(), 7);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(TerminalBasic, simpleString) {
|
|
|
+ Terminal term;
|
|
|
+ std::string send("Hello");
|
|
|
+
|
|
|
+ term.putstring(send);
|
|
|
+ ASSERT_NE(term.getx(), 0);
|
|
|
+ ASSERT_EQ(term.getx(), (int)send.size());
|
|
|
+ ASSERT_EQ(term.gety(), 0);
|
|
|
+
|
|
|
+ term.putstring(reset);
|
|
|
+ ASSERT_EQ(term.getx(), 0);
|
|
|
+ ASSERT_EQ(term.gety(), 0);
|
|
|
+ send = "Hello\r\n";
|
|
|
+ term.putstring(send);
|
|
|
+ ASSERT_EQ(term.getx(), 0);
|
|
|
+ ASSERT_EQ(term.gety(), 1);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(TerminalPosition, simplePositions) {
|
|
|
+ Terminal term;
|
|
|
+
|
|
|
+ std::string send("\x1b[10;5H"); // Y;X
|
|
|
+
|
|
|
+ term.putstring(send);
|
|
|
+ ASSERT_EQ(term.getx(), 4);
|
|
|
+ ASSERT_EQ(term.gety(), 9);
|
|
|
+ std::string save_pos("\x1b[s");
|
|
|
+ std::string restore_pos("\x1b[u");
|
|
|
+ term.putstring(save_pos);
|
|
|
+ ASSERT_EQ(term.getx(), 4);
|
|
|
+ ASSERT_EQ(term.gety(), 9);
|
|
|
+ send = "\x1b[5;10H";
|
|
|
+ term.putstring(send);
|
|
|
+ ASSERT_EQ(term.getx(), 9);
|
|
|
+ ASSERT_EQ(term.gety(), 4);
|
|
|
+ term.putstring(restore_pos);
|
|
|
+ ASSERT_EQ(term.getx(), 4);
|
|
|
+ ASSERT_EQ(term.gety(), 9);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(TerminalCRNL, NLCRTests) {
|
|
|
+ Terminal term;
|
|
|
+
|
|
|
+ std::string send("Hello\r");
|
|
|
+ term.putstring(send);
|
|
|
+ ASSERT_EQ(term.getx(), 0);
|
|
|
+ ASSERT_EQ(term.gety(), 0);
|
|
|
+ send = "Hello\n";
|
|
|
+ term.putstring(send);
|
|
|
+ ASSERT_EQ(term.getx(), 5);
|
|
|
+ ASSERT_EQ(term.gety(), 1);
|
|
|
+ term.putstring(reset);
|
|
|
+ send = "Hello\r\n";
|
|
|
+ term.putstring(send);
|
|
|
+ ASSERT_EQ(term.getx(), 0);
|
|
|
+ ASSERT_EQ(term.gety(), 1);
|
|
|
+}
|
|
|
+
|
|
|
} // namespace
|