hwcurses.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "timer.hpp"
  2. #include "timeractions.hpp"
  3. #include <chrono>
  4. #include <clocale>
  5. #include <cstdio>
  6. #include <ctime>
  7. #include <memory>
  8. #include <ncurses.h>
  9. #include <thread>
  10. #include <unistd.h>
  11. #include <utility>
  12. #include <vector>
  13. /*
  14. todo
  15. figure out namespaces, using, and auto
  16. read about std function and std bind
  17. try to do with objects / classes instead
  18. centralize into event sender and subscriber
  19. */
  20. void myupdatedisplay(const Timer &timer_input) {
  21. int x_offset = COLS / 4;
  22. mvprintw(timer_input.trigger_counter, timer_input.trigger_counter + x_offset,
  23. "test: █");
  24. }
  25. std::vector<int> my_numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  26. std::vector<int> my_other_numbers = {4, 9, 8, 6, 2, 1, 10, 3, 5, 7};
  27. void displaynumbers(int start_x, int start_y, std::vector<int> &input_numbers, cchar_t &input_char) {
  28. for (size_t i = 0; i < input_numbers.size(); i++) {
  29. /**
  30. I make a horizontal line of i chars, which are supposed to represent mynumbers
  31. above that, I want a line of bars.
  32. _all_ bars stretch from LINES-1 to LINES-1-numbervalue
  33. **/
  34. mvprintw(LINES -1 - start_y, i + start_x, "%d,", input_numbers[i]);
  35. mvwvline_set(stdscr, LINES-1-input_numbers[i]-start_y, i+start_x, &input_char, input_numbers[i]);
  36. }
  37. }
  38. void myinitialize() {
  39. setlocale(LC_ALL, "");
  40. initscr();
  41. nodelay(stdscr, FALSE);
  42. refresh();
  43. start_color();
  44. init_pair(1, COLOR_RED, COLOR_GREEN);
  45. attron(COLOR_PAIR(1));
  46. printw("Hello World! 🌍 テスト 测试");
  47. }
  48. int main() {
  49. myinitialize();
  50. cchar_t my_c_char = {.attr= A_NORMAL, .chars={L'█'}, .ext_color = 0};
  51. //create actions, then put them in timers, then put them into the timermanager
  52. auto my_action = std::make_unique<SwapAction>(my_numbers);
  53. auto clock_timer =
  54. std::make_unique<Timer>("secondsprinter", 1, 10, std::move(my_action));
  55. auto my_other_sort = std::make_unique<SortAction>(my_other_numbers);
  56. auto sort_timer =
  57. std::make_unique<Timer>("sorttimer", 0.5, std::move(my_other_sort));
  58. TimerManager my_timer_manager;
  59. my_timer_manager.addtimer(std::move(clock_timer));
  60. my_timer_manager.addtimer(std::move(sort_timer));
  61. while (true) {
  62. erase();
  63. my_timer_manager.updatetimers();
  64. displaynumbers(0,0,my_numbers, my_c_char);
  65. displaynumbers(10, 10, my_other_numbers, my_c_char);
  66. refresh();
  67. std::this_thread::sleep_for(std::chrono::milliseconds(50));
  68. }
  69. getch();
  70. endwin();
  71. return 0;
  72. }