diff --git a/Makefile b/Makefile index 05348bd..8fafb7f 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CC = gcc CXX = g++ -CPPFLAGS = -std=c++20 -g -Wall -Wextra -Wpedantic #-O3 -ffast-math +CPPFLAGS = -std=c++26 -g -Wall -Wextra -Wpedantic #-O3 -ffast-math CFLAGS = -g -Wall -Wextra -Wpedantic #-O3 -ffast-math LDFLAGS = -g -Wall -Wextra -Wpedantic #-O3 -ffast-math LDLIBS = -lfltk -lcurl -lfltk_images diff --git a/src/images.cpp b/src/images.cpp index c6b2418..35b5676 100644 --- a/src/images.cpp +++ b/src/images.cpp @@ -1,3 +1,5 @@ +#include + unsigned char icon_inspect_file_png[] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, @@ -64,4 +66,4 @@ unsigned char icon_inspect_file_png[] = { 0x30, 0x7f, 0x3f, 0xa5, 0xb2, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82 }; -unsigned int icon_inspect_file_png_len = 761; +size_t icon_inspect_file_png_len = 761; diff --git a/src/main.cpp b/src/main.cpp index c8a7b5d..831ab3e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,6 +24,8 @@ #include +#include + struct Selected { @@ -203,7 +205,7 @@ void show_callback(Fl_Widget *w, void *data) { for (size_t i = 0; i < s; i++) { if (rdata->list->selected(i)) { - fl_alert("%s", rdata->list->text(i)); + //fl_alert("%s", rdata->list->text(i)); auto c = ComplexEntry(rdata->s.entries[ (size_t) rdata->list->data(i)]); rdata->summaryEditor->addComplex(c); } diff --git a/src/summarymanager.cpp b/src/summarymanager.cpp index c094297..6072acb 100644 --- a/src/summarymanager.cpp +++ b/src/summarymanager.cpp @@ -10,24 +10,39 @@ #include #include #include +#include +#include #include +#include +#include Fl_Text_Display::Style_Table_Entry table[] { - { FL_BLACK, FL_COURIER, FL_NORMAL_SIZE }, + { FL_BLACK, FL_COURIER, FL_NORMAL_SIZE}, { FL_RED, FL_COURIER, FL_NORMAL_SIZE }, + { FL_GREEN, FL_COURIER, FL_NORMAL_SIZE }, + { FL_BLUE, FL_COURIER, FL_NORMAL_SIZE }, + { FL_CYAN, FL_COURIER, FL_NORMAL_SIZE }, + { FL_MAGENTA, FL_COURIER, FL_NORMAL_SIZE }, }; +template +T P(T i) { + std::cout << i << std::endl; + return i; +} void SummaryCallback(Fl_Widget * w, void * data) { auto sum = (Summary *) w; if (Fl::callback_reason() == FL_REASON_CLOSED) { std::cout << "CLOSED " << sum->title << std::endl; + auto tabs = w->parent(); + Fl::delete_widget(w); + tabs->redraw(); + + } } - Fl::delete_widget(w); - w->parent()->redraw(); -} SummaryManager::SummaryManager(int x, int y, int w, int h) @@ -69,7 +84,88 @@ SummaryManager::SummaryManager(int x, int y, int w, int h) box(FL_FLAT_BOX); } -void style_unfinn_cb(int, void* a) {} +void style_unfinn_cb(int, void *a) {} + +std::string NumberToStyle(const int n) { + const int s = n % 5; + switch(s) { + case 0: return "B"; + case 1: return "C"; + case 2: return "D"; + case 3: return "E"; + case 4: return "F"; + default: throw "err"; + } +} + +std::string& replaceAllInPlace(std::string& in, std::string_view from, std::string_view to) { + size_t pos = in.find(from, 0); + + while(pos != std::string::npos) { + in.replace(pos, from.length(), to); + + + pos = in.find(from, pos); + + } + return in; +} + + + +std::string htmlCodesToNormal(std::string in) { + + replaceAllInPlace(in, ">", ">"); + replaceAllInPlace(in, "<", "<"); + + return in; + +} + + +void LoadReport(std::string s, Fl_Text_Buffer * text, Fl_Text_Buffer * style) { + std::istringstream stream(s); + + std::string line; + + std::string currentval = "A"; + + std::regex startcolorpatt(".*IMG SRC=\"http://moss[.]stanford[.]edu/bitmaps/tm_(\\d+)_(\\d+)[.]gif.*"); + + std::regex endcolorpatt("(.*)"); + + + while (std::getline(stream, line)) { + std::smatch matches; + std::string formatted = htmlCodesToNormal(line); + + if(std::regex_search(formatted, matches, startcolorpatt)) { + //std::cout << v << std::endl; + currentval = NumberToStyle(std::stoi(matches[1])); + continue; + } + + if(std::regex_search(formatted, matches, endcolorpatt)) { + formatted = matches[1]; + currentval = "A"; + } + + + + text->append(formatted.c_str()); + text->append("\n"); + + for (size_t i = 0; i < formatted.length()+1; i++) { + style->append(currentval.c_str()); + } + + } + + + +} + + Summary::Summary(ComplexEntry c, int x, int y, int w, int h) : Fl_Group(x, y, w, h, "Loading...") { title = c.basic.A.name + "+" + c.basic.B.name + "(" + std::to_string(c.basic.Apercent) + "%," + std::to_string(c.basic.Bpercent) + "%)"; @@ -80,17 +176,33 @@ Summary::Summary(ComplexEntry c, int x, int y, int w, int h) : Fl_Group(x, y, w, Fl_Group * text_boxes = new Fl_Group(0,0,w,h); Fl_Text_Display * s1 = new Fl_Text_Display(0, 0, w/2, h); - Fl_Text_Buffer * s1buff = new Fl_Text_Buffer(); - Fl_Text_Buffer * s1style_buff = new Fl_Text_Buffer(); - s1style_buff->insert(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); - s1->highlight_data(s1style_buff, table , 2, 'A', style_unfinn_cb, 0); + s1buff = new Fl_Text_Buffer(); + s1style_buff = new Fl_Text_Buffer(); + + s1->highlight_data(s1style_buff, table , sizeof(table)/sizeof(table[0]), 'A', style_unfinn_cb, 0); s1->buffer(s1buff); - std::cout << c.A_buf.c_str() << std::endl; - s1->insert(c.A_buf.c_str()); + + Fl_Text_Display * s2 = new Fl_Text_Display(w/2, 0, w/2, h); - Fl_Text_Buffer * s2buff = new Fl_Text_Buffer(); + s2buff = new Fl_Text_Buffer(); + s2style_buff = new Fl_Text_Buffer(); + + s2->highlight_data(s2style_buff, table, sizeof(table)/sizeof(table[0]), 'A', style_unfinn_cb, 0); s2->buffer(s2buff); - s2->buffer()->insert(0, c.B_buf.c_str()); + + + + // s1style_buff->insert(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); + // std::cout << c.A_buf.c_str() << std::endl; + // s1->insert(c.A_buf.c_str()); + + LoadReport(c.A_buf, s1buff, s1style_buff); + LoadReport(c.B_buf, s2buff, s2style_buff); + + // s2->buffer()->insert(0, c.B_buf.c_str()); + + + text_boxes->end(); win->end(); this->end(); @@ -98,7 +210,17 @@ Summary::Summary(ComplexEntry c, int x, int y, int w, int h) : Fl_Group(x, y, w, win->resizable(text_boxes); this->callback(SummaryCallback); +} + +Summary::~Summary() { + std::cout << "HERE" << std::endl; + + this->clear(); + delete s1buff; + delete s2buff; + delete s1style_buff; + delete s2style_buff; } diff --git a/src/summarymanager.hpp b/src/summarymanager.hpp index 91a22f7..eb4c8f9 100644 --- a/src/summarymanager.hpp +++ b/src/summarymanager.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -17,7 +18,13 @@ void SummaryCallback(Fl_Widget * w, void * data); struct Summary : Fl_Group { std::string title; - Summary(ComplexEntry c, int x, int y, int w, int h); + Fl_Text_Buffer * s1buff; + Fl_Text_Buffer * s1style_buff; + Fl_Text_Buffer * s2buff; + Fl_Text_Buffer * s2style_buff; + + Summary(ComplexEntry c, int x, int y, int w, int h); + ~Summary(); };