add --styles-and-script option to output default CSS and Javascript for page composition

Fri, 06 Feb 2026 16:22:33 +0100

author
Mike Becker <universe@uap-core.de>
date
Fri, 06 Feb 2026 16:22:33 +0100
changeset 73
707f42bb0484
parent 72
93de83b09c2d
child 74
bae9922f4681

add --styles-and-script option to output default CSS and Javascript for page composition

CHANGELOG file | annotate | diff | comparison | revisions
Makefile file | annotate | diff | comparison | revisions
src/html.cpp file | annotate | diff | comparison | revisions
src/html.h file | annotate | diff | comparison | revisions
src/main.cpp file | annotate | diff | comparison | revisions
src/settings.h file | annotate | diff | comparison | revisions
--- a/CHANGELOG	Tue Dec 16 21:23:39 2025 +0100
+++ b/CHANGELOG	Fri Feb 06 16:22:33 2026 +0100
@@ -1,3 +1,7 @@
+Version 1.2.0 - tbd
+
+- Add --styles-and-script option to output the default CSS and Javascript
+
 Version 1.1.2 - 2025-12-15
 
 - Fix that backslashes in commit messages were not escaped in the JSON
--- a/Makefile	Tue Dec 16 21:23:39 2025 +0100
+++ b/Makefile	Fri Feb 06 16:22:33 2026 +0100
@@ -21,7 +21,7 @@
 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-VERSION=1.1.2
+VERSION=1.2.0
 
 all: compile FORCE
 
--- a/src/html.cpp	Tue Dec 16 21:23:39 2025 +0100
+++ b/src/html.cpp	Fri Feb 06 16:22:33 2026 +0100
@@ -73,17 +73,8 @@
     }
 }
 
-void html::open(bool fragment, unsigned char fragment_indent) {
-    if (fragment) {
-        indent(fragment_indent);
-        puts("<div class=\"heatmap-content\">");
-        indentation++;
-    } else {
-        puts(R"(<!DOCTYPE html>
-<html>
-    <head>
-        <meta charset="UTF-8">
-        <style>
+void html::styles_and_script() {
+    puts(R"(        <style>
             table.heatmap {
                 table-layout: fixed;
                 border-collapse: separate;
@@ -273,8 +264,21 @@
                     }
                 });
             });
-        </script>
-    </head>
+        </script>)");
+}
+
+void html::open(bool fragment, unsigned char fragment_indent) {
+    if (fragment) {
+        indent(fragment_indent);
+        puts("<div class=\"heatmap-content\">");
+        indentation++;
+    } else {
+        puts(R"(<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="UTF-8">)");
+        styles_and_script();
+        puts(R"(    </head>
     <body>
         <div class="heatmap-content">)");
         indentation = 3;
--- a/src/html.h	Tue Dec 16 21:23:39 2025 +0100
+++ b/src/html.h	Fri Feb 06 16:22:33 2026 +0100
@@ -38,6 +38,7 @@
     static constexpr unsigned columns = 53;
 
     void open(bool fragment, unsigned char fragment_indent = 0);
+    void styles_and_script();
     void close(bool fragment);
 
     void chart_begin(const std::string& repo, const std::string& author);
--- a/src/main.cpp	Tue Dec 16 21:23:39 2025 +0100
+++ b/src/main.cpp	Fri Feb 06 16:22:33 2026 +0100
@@ -38,7 +38,7 @@
 
 using namespace std::chrono;
 
-static constexpr auto program_version = "1.1.2";
+static constexpr auto program_version = "1.2.0-preview";
 
 static void print_help() {
     fputs(
@@ -52,6 +52,7 @@
         "   -h, --help                Print this help message\n"
         "   -p, --pull                Try to pull the repositories\n"
         "   -s, --separate            Output a separate heat map for each repository\n"
+        "       --styles-and-script   Output the default CSS and Javascript and quit\n"
         "   -V, --version             Output the version of this program and exit\n"
         "   -y, --year <year>         The year for which to create the heat map\n"
         "       --hg <path>           Path to hg binary (default: /usr/bin/hg)\n"
@@ -88,6 +89,9 @@
         "single HTML div container without any header or footer that can be embedded in\n"
         "your custom web page. You can optionally specify an indentation for that\n"
         "container (default is 0 and maximum is 12).\n"
+        "When you want to combine this with the default style and scripts, you can use\n"
+        "the \033[1m--styles-and-script\033[22m option print the defaults to stdout and redirect them\n"
+        "into a file when you are composing your custom HTML page.\n"
         , stderr);
 }
 
@@ -171,6 +175,12 @@
                 fputs("--git is expecting a path\n", stderr);
                 return -1;
             }
+        } else if (chk_arg(argv[i], "--styles-and-script", nullptr)) {
+            settings.styles_and_script = true;
+            if (argc != 2) {
+                fputs("Error: --styles-and-script must be the only option when present\n", stderr);
+                return -1;
+            }
         } else if (argv[i][0] == '-') {
             fprintf(stderr, "Unknown option: %s\n", argv[i]);
             return -1;
@@ -193,6 +203,12 @@
         return result < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
     }
 
+    // check special options
+    if (settings.styles_and_script) {
+        html::styles_and_script();
+        return 0;
+    }
+
     // check hg and git
     fm::process proc;
     proc.setbin(settings.hg);
--- a/src/settings.h	Tue Dec 16 21:23:39 2025 +0100
+++ b/src/settings.h	Fri Feb 06 16:22:33 2026 +0100
@@ -45,6 +45,7 @@
     bool update_repos = false;
     bool separate = false;
     bool fragment = false;
+    bool styles_and_script = false;
     unsigned char fragment_indent = 0;
     unsigned short year = settings_current_year;
 

mercurial