Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

92 lines
2.5KB

  1. /*------------ -------------- -------- --- ----- --- -- - -
  2. * Libre Blackjack - tty interactive player
  3. *
  4. * Copyright (C) 2020 jeremy theler
  5. *
  6. * This file is part of Libre Blackjack.
  7. *
  8. * Libre Blackjack is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * Libre Blackjack is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with Libre Blackjack. If not, see <http://www.gnu.org/licenses/>.
  20. *------------------- ------------ ---- -------- -- - - -
  21. */
  22. #ifndef TTY_H
  23. #define TTY_H
  24. #include <algorithm>
  25. #include <functional>
  26. #include <cctype>
  27. #include <locale>
  28. #include "blackjack.h"
  29. extern std::vector<std::string> commands;
  30. class Tty : public Player {
  31. public:
  32. Tty(Configuration &);
  33. ~Tty() { };
  34. int play(void) override;
  35. void info(Libreblackjack::Info = Libreblackjack::Info::None, int = 0, int = 0) override;
  36. // for readline's autocompletion
  37. static char *rl_command_generator(const char *, int);
  38. static char **rl_completion(const char *, int, int);
  39. static int list_index;
  40. static int len;
  41. private:
  42. void renderHand(Hand *, bool = false);
  43. void renderTable(void);
  44. #ifdef HAVE_LIBREADLINE
  45. char *input_buffer;
  46. #else
  47. std::string input_buffer;
  48. #endif
  49. std::size_t handToSplit;
  50. unsigned int cardToSplit;
  51. std::string arrow;
  52. std::string prompt;
  53. int delay = 200;
  54. bool color = true;
  55. std::string black;
  56. std::string red;
  57. std::string green;
  58. std::string yellow;
  59. std::string blue;
  60. std::string magenta;
  61. std::string cyan;
  62. std::string white;
  63. std::string reset;
  64. inline void ltrim(std::string &s) {
  65. s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { return !std::isspace(ch); }));
  66. };
  67. inline void rtrim(std::string &s) {
  68. s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(), s.end());
  69. };
  70. inline void trim(std::string &s) { ltrim(s); rtrim(s); };
  71. };
  72. #endif