# HG changeset patch # User Mike Becker # Date 1738358848 -3600 # Node ID 1040ba37d4c90b121b095204a8c851311999b267 # Parent 60c2588b4455575b600e9953d7e7ff1f29b1e5bc improve alignment of month headers diff -r 60c2588b4455 -r 1040ba37d4c9 src/html.cpp --- a/src/html.cpp Fri Jan 31 22:11:04 2025 +0100 +++ b/src/html.cpp Fri Jan 31 22:27:28 2025 +0100 @@ -26,6 +26,9 @@ #include +#include +namespace chrono = std::chrono; + namespace html { static unsigned indentation; static const char *tabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; @@ -106,15 +109,33 @@ printf("

%s

\n", encode(heading).c_str()); } -void html::table_begin() { +void html::table_begin(int year) { + static constexpr const char* months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; + // compute the column spans, first + unsigned colspans[12] = {}; + { + unsigned total_cols = 0; + chrono::sys_days day{chrono::year_month_day{chrono::year{year}, chrono::month{1}, chrono::day{1}}}; + if (chrono::weekday{day}.iso_encoding() != 1) { + colspans[0] = 1; + total_cols = 1; + } + for (unsigned col = 0; col < 12; ++col) { + while (total_cols < html::columns && chrono::year_month_day{day}.month() <= chrono::month{col + 1}) { + ++total_cols; + ++colspans[col]; + day += chrono::days{7}; + } + } + } + + // now render the table heading indent(); puts(""); indent(1); puts(""); indent(1); puts(""); - static constexpr const char* months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - static constexpr int colspans[] = {5, 4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 5}; for (unsigned i = 0 ; i < 12 ; i++) { indent(); printf("\n", colspans[i], months[i]); diff -r 60c2588b4455 -r 1040ba37d4c9 src/html.h --- a/src/html.h Fri Jan 31 22:11:04 2025 +0100 +++ b/src/html.h Fri Jan 31 22:27:28 2025 +0100 @@ -36,7 +36,7 @@ void h1(const std::string& heading); void h2(const std::string& heading); - void table_begin(); + void table_begin(int year); void table_end(); void row_begin(unsigned int weekday); void row_end(); diff -r 60c2588b4455 -r 1040ba37d4c9 src/main.cpp --- a/src/main.cpp Fri Jan 31 22:11:04 2025 +0100 +++ b/src/main.cpp Fri Jan 31 22:27:28 2025 +0100 @@ -218,7 +218,7 @@ html::h1(repo); for (const auto &[author, entries] : authors) { html::h2(author); - html::table_begin(); + html::table_begin(year); // initialize counters unsigned column = 0, row = 0;
%s