TerminalTests.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <stdio.h>
  2. #include "../Tests.h"
  3. #include "core/Logger.h"
  4. #include "core/Terminal.h"
  5. #include "core/Utility.h"
  6. #define KEY_CASE(key) \
  7. case key: puts(#key); break
  8. void testTerminal(void) {
  9. enterAlternativeTerminal();
  10. resetCursor();
  11. hideCursor();
  12. puts("Hi there");
  13. LOG_WARNING("This is a test");
  14. IntVector2 v = getTerminalSize();
  15. printf("%d %d\n", v.x, v.y);
  16. clearTerminal();
  17. resetCursor();
  18. showCursor();
  19. puts("the final!!!");
  20. sleepMillis(500);
  21. enterRawTerminal();
  22. while(true) {
  23. u64 c = getRawChar();
  24. if(c == 'q') {
  25. break;
  26. } else if(c == 0) {
  27. continue;
  28. }
  29. switch(c) {
  30. KEY_CASE(TERMINAL_KEY_ARROW_LEFT);
  31. KEY_CASE(TERMINAL_KEY_ARROW_RIGHT);
  32. KEY_CASE(TERMINAL_KEY_ARROW_UP);
  33. KEY_CASE(TERMINAL_KEY_ARROW_DOWN);
  34. KEY_CASE(TERMINAL_KEY_ARROW_DELETE);
  35. default: printf("%lu\n", c); break;
  36. }
  37. }
  38. leaveRawTerminal();
  39. leaveAlternativeTerminal();
  40. }