1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- #include <stdio.h>
- #include "../Tests.h"
- #include "core/Logger.h"
- #include "core/Terminal.h"
- #include "core/Utility.h"
- #define KEY_CASE(key) \
- case key: puts(#key); break
- void testTerminal(bool tty) {
- IntVector2 size = getTerminalSize();
- if(tty) {
- TEST_TRUE(size.x > 0);
- TEST_TRUE(size.y > 0);
- TEST_FALSE(enterRawTerminal());
- TEST_FALSE(leaveRawTerminal());
- } else {
- TEST_INT(0, size.x);
- TEST_INT(0, size.y);
- }
- enterAlternativeTerminal();
- clearTerminal();
- resetCursor();
- LOG_ERROR("Not visible!");
- leaveAlternativeTerminal();
- LOG_ERROR("Not visible!");
- moveCursorUp(2);
- moveCursorDown(1);
- moveCursorLeft(3);
- moveCursorRight(3);
- clearTerminalLine();
- hideCursor();
- showCursor();
- }
- void testInteractiveTerminal(void) {
- enterAlternativeTerminal();
- resetCursor();
- hideCursor();
- puts("Hi there");
- LOG_WARNING("This is a test");
- IntVector2 v = getTerminalSize();
- printf("%d %d\n", v.x, v.y);
- clearTerminal();
- resetCursor();
- showCursor();
- puts("the final!!!");
- sleepMillis(500);
- enterRawTerminal();
- while(true) {
- u64 c = getRawChar();
- if(c == 'q') {
- break;
- } else if(c == 0) {
- continue;
- }
- switch(c) {
- KEY_CASE(TERMINAL_KEY_ARROW_LEFT);
- KEY_CASE(TERMINAL_KEY_ARROW_RIGHT);
- KEY_CASE(TERMINAL_KEY_ARROW_UP);
- KEY_CASE(TERMINAL_KEY_ARROW_DOWN);
- KEY_CASE(TERMINAL_KEY_DELETE);
- default: printf("%lu\n", c); break;
- }
- }
- leaveRawTerminal();
- leaveAlternativeTerminal();
- }
|