chiark / gitweb /
commitid.scad.pl: put dirty marker to lh of cout
[reprap-play.git] / commitid.scad.pl
index ebdbe917a39a6cb73db24da322d83a22e85af045..de571668f8d9d64df1b7b4d408f5a91c57c1a0d6 100755 (executable)
@@ -268,16 +268,21 @@ our $do_git; # contains may chars 'c' (count) and/or 'o' (object)
 our $do_git_untracked = 1;
 our $argcounter;
 
-sub rjustt ($$) { # right justify and truncate (ie, pad and truncate at left)
-    my ($sz, $whole) = @_;
+sub rjustt ($$;$) { # right justify and truncate (ie, pad and truncate at left)
+                    # always includes prefix
+    my ($sz, $whole, $prefix) = @_;
+    $prefix //= '';
     my $lw = length $whole;
-    return $lw > $sz
-       ? substr($whole, $lw-$sz)
-       : sprintf "%${sz}s", $whole;
+    my $spare = $sz - $lw - (length $prefix);
+    return
+       ($spare > 0 ? (' ' x $spare) : '').
+       $prefix.
+       substr($whole, ($spare < 0 ? -$spare : 0));
 }
 
-sub ljustt ($$$) { # always includes $suffix
+sub ljustt ($$;$) {
     my ($sz, $whole, $suffix) = @_;
+    $suffix //= '';
     $sz -= length $suffix;
     return sprintf "%-${sz}.${sz}s%s", $whole, $suffix;
 }
@@ -356,7 +361,7 @@ sub do_git () {
     foreach my $sz (3..10) {
        gentextmodule_demo_start_batch($sz-3);
 
-       gentextmodule_plusq("Small$sz", rjustt($sz, $git_count.$git_dirty))
+       gentextmodule_plusq("Small$sz", rjustt($sz, $git_count$git_dirty))
            if defined $git_count;
 
        gentextmodule_plusq("Git$sz", ljustt($sz, $git_object, $git_dirty))
@@ -364,8 +369,8 @@ sub do_git () {
 
        if (defined $git_count && defined $git_object) {
            gentextmodule("Full$sz",
-                         ljustt($sz, $git_object, ''),
-                         rjustt($sz, $git_count.$git_dirty));
+                         ljustt($sz, $git_object),
+                         rjustt($sz, $git_count$git_dirty));
 
            if (!($sz % 2)) {
                my $e = $sz/2;