hwcurses.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "timer.hpp"
  2. #include <chrono>
  3. #include <clocale>
  4. #include <cstdio>
  5. #include <ctime>
  6. #include <memory>
  7. #include <ncurses.h>
  8. #include <thread>
  9. #include <unistd.h>
  10. #include <utility>
  11. #include <vector>
  12. /*
  13. todo
  14. figure out namespaces, using, and auto
  15. read about std function and std bind
  16. try to do with objects / classes instead
  17. centralize into event sender and subscriber
  18. */
  19. void myupdatedisplay(const timer &timer_input) {
  20. int x_offset = COLS / 4;
  21. mvprintw(timer_input.triggercounter, timer_input.triggercounter + x_offset,
  22. "test: █");
  23. }
  24. void createbalk(const timer &timer_input, cchar_t &input_char) {
  25. int ticnt = timer_input.triggercounter;
  26. mvwvline_set(stdscr, LINES - ticnt, ticnt, &input_char, ticnt);
  27. }
  28. std::vector<int> mynumbers = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  29. void displaynumbers(int myy, std::vector<int> &input_numbers) {
  30. for (size_t i = 0; i < input_numbers.size(); i++) {
  31. mvprintw(myy, 10 + i, "%d,", input_numbers[i]);
  32. }
  33. }
  34. void myinitialize() {
  35. setlocale(LC_ALL, "");
  36. initscr();
  37. nodelay(stdscr, FALSE);
  38. refresh();
  39. start_color();
  40. init_pair(1, COLOR_RED, COLOR_GREEN);
  41. attron(COLOR_PAIR(1));
  42. printw("Hello World! 🌍 テスト 测试");
  43. }
  44. int main() {
  45. myinitialize();
  46. cchar_t my_c_char = {.attr= A_NORMAL, .chars={L'█'}, .ext_color = 0};
  47. auto myaction = std::make_unique<swapaction>(mynumbers);
  48. auto clocktimer = std::make_unique<timer>("secondsprinter", 1, 10, std::move(myaction));
  49. timermanager mytimermanager;
  50. mytimermanager.addtimer(std::move(clocktimer));
  51. displaynumbers(2, mynumbers);
  52. // calculate delta between current and previous time
  53. while (true) {
  54. erase();
  55. mytimermanager.updatetimers();
  56. displaynumbers(3, mynumbers);
  57. refresh();
  58. std::this_thread::sleep_for(std::chrono::milliseconds(500));
  59. }
  60. getch();
  61. endwin();
  62. return 0;
  63. }