hwcurses.cpp 2.3 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.triggercounter, timer_input.triggercounter + x_offset,
  23. "test: █");
  24. }
  25. std::vector<int> mynumbers = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  26. std::vector<int> myothernumbers = {1, 4, 9, 8, 6, 2, 3, 5, 7};
  27. void displaynumbers(int startx, int starty, 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 - starty, i + startx, "%d,", input_numbers[i]);
  35. mvwvline_set(stdscr, LINES-1-input_numbers[i]-starty, i+startx, &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 myaction = std::make_unique<swapaction>(mynumbers);
  53. auto clocktimer =
  54. std::make_unique<timer>("secondsprinter", 1, 10, std::move(myaction));
  55. auto myothersort = std::make_unique<sortaction>(myothernumbers);
  56. auto sorttimer =
  57. std::make_unique<timer>("sorttimer", 0.1, std::move(myothersort));
  58. timermanager mytimermanager;
  59. mytimermanager.addtimer(std::move(clocktimer));
  60. mytimermanager.addtimer(std::move(sorttimer));
  61. while (true) {
  62. erase();
  63. mytimermanager.updatetimers();
  64. displaynumbers(0,0,mynumbers, my_c_char);
  65. displaynumbers(10, 10, myothernumbers, my_c_char);
  66. refresh();
  67. std::this_thread::sleep_for(std::chrono::milliseconds(500));
  68. }
  69. getch();
  70. endwin();
  71. return 0;
  72. }