Space Walk board game
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

70 lines
1.1 KiB

  1. #include <cstdio> // size_t
  2. #include <ncurses.h>
  3. #include "inputoutput.h"
  4. void IO::initialize() {
  5. }
  6. void IO::update() {
  7. IO::keyCode = getch();
  8. if (keyCode == KEY_ESC) {
  9. IO::setQuit();
  10. return;
  11. }
  12. }
  13. std::string IO::trim(std::string str) {
  14. size_t first = str.find_first_not_of(" ");
  15. if (first == std::string::npos) {
  16. return "";
  17. }
  18. size_t last = str.find_last_not_of(" ");
  19. return str.substr(first, (last - first + 1));
  20. }
  21. std::string IO::untrim(std::string str, unsigned int length) {
  22. unsigned int strLength = str.length();
  23. if (length > strLength) {
  24. int halfDiff = (length - strLength) / 2;
  25. std::string tmpStr;
  26. for (int i = 0; i < halfDiff; i++) {
  27. tmpStr += " ";
  28. }
  29. str.insert(0, tmpStr);
  30. str.append(tmpStr);
  31. }
  32. return str;
  33. }
  34. int IO::getKeyCode() {
  35. return IO::keyCode;
  36. }
  37. std::string IO::getKeyName() {
  38. return std::string(keyname(IO::keyCode));
  39. }
  40. std::string IO::getStrInput() {
  41. echo();
  42. char *tmp = new char();
  43. getstr(tmp);
  44. noecho();
  45. return std::string(tmp);
  46. }
  47. bool IO::getQuit() {
  48. return IO::quit;
  49. }
  50. void IO::setQuit() {
  51. IO::quit = true;
  52. }
  53. int IO::keyCode = ERR;
  54. bool IO::quit = false;