hwcurses.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include <algorithm>
  2. #include <chrono>
  3. #include <clocale>
  4. #include <cstdio>
  5. #include <ctime>
  6. #include <functional>
  7. #include <iostream>
  8. #include <memory>
  9. #include <ncurses.h>
  10. #include <string>
  11. #include <thread>
  12. #include <unistd.h>
  13. #include "timer.hpp"
  14. #include <vector>
  15. /*
  16. todo
  17. figure out namespaces, using, and auto
  18. formalize timer struct
  19. read about std function and std bind
  20. try to do with objects / classes instead
  21. centralize into event sender and subscriber
  22. */
  23. void myupdatedisplay(const timer &timer_input) {
  24. int x_offset = COLS / 4;
  25. mvprintw(timer_input.triggercounter, timer_input.triggercounter+x_offset, "test: █");
  26. }
  27. void createbalk(const timer &timer_input, cchar_t &input_char) {
  28. int ticnt = timer_input.triggercounter;
  29. mvwvline_set(stdscr, LINES-ticnt, ticnt, &input_char, ticnt);
  30. }
  31. int main() {
  32. setlocale(LC_ALL, "");
  33. initscr();
  34. nodelay(stdscr, FALSE);
  35. refresh();
  36. start_color();
  37. init_pair(1, COLOR_BLUE, COLOR_WHITE);
  38. attron(COLOR_PAIR(1));
  39. printw("Hello World! 🌍 テスト 测试");
  40. const wchar_t mywch = L'█';
  41. cchar_t myc_char;
  42. setcchar(&myc_char, &mywch, A_NORMAL, 0, NULL);
  43. // printf("verification\n");
  44. auto starttime = std::chrono::steady_clock::now(); // initial starttime
  45. auto clocktimer = std::make_unique<timer>("secondsprinter", 1, 10, [&myc_char](const timer& t){createbalk(t,myc_char);});
  46. timermanager mytimermanager;
  47. mytimermanager.addtimer(std::move(clocktimer));
  48. mvprintw(5, 5, "timer added");
  49. // calculate delta between current and previous time
  50. while (true) {
  51. auto currenttime = std::chrono::steady_clock::now();
  52. std::chrono::duration<double> myDeltaTime = currenttime - starttime;
  53. double dtime = myDeltaTime.count();
  54. mytimermanager.updatetimers(dtime);
  55. starttime = currenttime;
  56. std::this_thread::sleep_for(std::chrono::milliseconds(500));
  57. }
  58. getch();
  59. endwin();
  60. return 0;
  61. }