| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #include <algorithm>
- #include <chrono>
- #include <clocale>
- #include <cstdio>
- #include <ctime>
- #include <functional>
- #include <iostream>
- #include <memory>
- #include <ncurses.h>
- #include <string>
- #include <thread>
- #include <unistd.h>
- #include "timer.hpp"
- #include <vector>
- /*
- todo
- figure out namespaces, using, and auto
- formalize timer struct
- read about std function and std bind
- try to do with objects / classes instead
- centralize into event sender and subscriber
- */
- void myupdatedisplay(const timer &timer_input) {
- int x_offset = COLS / 4;
- mvprintw(timer_input.triggercounter, timer_input.triggercounter+x_offset, "test: █");
- }
- void createbalk(const timer &timer_input, cchar_t &input_char) {
- int ticnt = timer_input.triggercounter;
- mvwvline_set(stdscr, LINES-ticnt, ticnt, &input_char, ticnt);
- }
- int main() {
- setlocale(LC_ALL, "");
- initscr();
- nodelay(stdscr, FALSE);
- refresh();
- start_color();
- init_pair(1, COLOR_BLUE, COLOR_WHITE);
- attron(COLOR_PAIR(1));
- printw("Hello World! 🌍 テスト 测试");
- const wchar_t mywch = L'█';
- cchar_t myc_char;
- setcchar(&myc_char, &mywch, A_NORMAL, 0, NULL);
- // printf("verification\n");
- auto starttime = std::chrono::steady_clock::now(); // initial starttime
- auto clocktimer = std::make_unique<timer>("secondsprinter", 1, 10, [&myc_char](const timer& t){createbalk(t,myc_char);});
- timermanager mytimermanager;
- mytimermanager.addtimer(std::move(clocktimer));
- mvprintw(5, 5, "timer added");
- // calculate delta between current and previous time
- while (true) {
- auto currenttime = std::chrono::steady_clock::now();
- std::chrono::duration<double> myDeltaTime = currenttime - starttime;
- double dtime = myDeltaTime.count();
- mytimermanager.updatetimers(dtime);
- starttime = currenttime;
- std::this_thread::sleep_for(std::chrono::milliseconds(500));
- }
- getch();
- endwin();
- return 0;
- }
|