| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #include "timer.hpp"
- #include <chrono>
- #include <clocale>
- #include <cstdio>
- #include <ctime>
- #include <memory>
- #include <ncurses.h>
- #include <thread>
- #include <unistd.h>
- #include <utility>
- #include <vector>
- /*
- todo
- figure out namespaces, using, and auto
- 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);
- }
- std::vector<int> mynumbers = {1, 2, 3, 4, 5, 6, 7, 8, 9};
- void displaynumbers(int myy, std::vector<int> &input_numbers) {
- for (size_t i = 0; i < input_numbers.size(); i++) {
- mvprintw(myy, 10 + i, "%d,", input_numbers[i]);
- }
- }
- void myinitialize() {
- setlocale(LC_ALL, "");
- initscr();
- nodelay(stdscr, FALSE);
- refresh();
- start_color();
- init_pair(1, COLOR_RED, COLOR_GREEN);
- attron(COLOR_PAIR(1));
- printw("Hello World! 🌍 テスト 测试");
- }
- int main() {
- myinitialize();
- cchar_t my_c_char = {.attr= A_NORMAL, .chars={L'█'}, .ext_color = 0};
-
- auto myaction = std::make_unique<swapaction>(mynumbers);
- auto clocktimer = std::make_unique<timer>("secondsprinter", 1, 10, std::move(myaction));
- timermanager mytimermanager;
- mytimermanager.addtimer(std::move(clocktimer));
- displaynumbers(2, mynumbers);
-
- // calculate delta between current and previous time
- while (true) {
- erase();
-
- mytimermanager.updatetimers();
- displaynumbers(3, mynumbers);
-
- refresh();
- std::this_thread::sleep_for(std::chrono::milliseconds(500));
- }
- getch();
- endwin();
- return 0;
- }
|