From af5252f7329d764237d50a523b901b6b137416f1 Mon Sep 17 00:00:00 2001 From: PoliEcho Date: Thu, 6 Mar 2025 18:54:51 +0100 Subject: [PATCH] add basic timetable structure --- src/timetable.cpp | 53 ++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/src/timetable.cpp b/src/timetable.cpp index 260a829..0e1cafe 100644 --- a/src/timetable.cpp +++ b/src/timetable.cpp @@ -1,32 +1,43 @@ #include "timetable.h" -#include -#include #include "net.h" +#include +#include #include +#include +#include +#include using nlohmann::json; -#define NLINES 10 -#define NCOLS 40 - -#define DEFAULT_X_OFFSET 10 -#define DEFAULT_Y_OFFSET 2 - -#define DEFAULT_PADDING 4 - void timetable_page() { - // DONT FORGET TO UNCOMMENT - // json resp_from_api = bakaapi::get_data_from_endpoint("api/3/timetable/actual"); - std::ifstream f("test-data/timetable.json"); - json resp_from_api = json::parse(f); + // DONT FORGET TO UNCOMMENT + // json resp_from_api = + // bakaapi::get_data_from_endpoint("api/3/timetable/actual"); + std::ifstream f("test-data/timetable.json"); + json resp_from_api = json::parse(f); - // calculate table size - - uint8_t column_number = 0; - for(uint8_t i = 0; i < resp_from_api["Days"].size(); i++) { - (resp_from_api["Days"][i]["Atoms"].size() > column_number) ? (column_number = resp_from_api["Days"][i]["Atoms"].size()); + // calculate table size + // some lambda dark magic + const uint8_t num_of_columns = [&]() -> uint8_t { + uint8_t result = 0; + for (uint8_t i = 0; i < resp_from_api["Days"].size(); i++) { + uint8_t currentSize = resp_from_api["Days"][i]["Atoms"].size(); + if (currentSize > result) { + result = currentSize; + } } - - + return result; + }(); + const uint8_t num_of_rows = resp_from_api["Days"].size(); + + setlocale(LC_ALL, ""); + /* Initialize curses */ + initscr(); + start_color(); + cbreak(); + noecho(); + keypad(stdscr, TRUE); + + printw("LINES: %d COLS: %d", LINES, COLS); } \ No newline at end of file