chiark
/
gitweb
/
~ianmdlvl
/
reprap-play.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
bf19d2a
)
commitid.scad.pl: make rjustt take $prefix (nfc as yet)
author
Ian Jackson
<ijackson@chiark.greenend.org.uk>
Fri, 5 Feb 2016 19:06:55 +0000
(19:06 +0000)
committer
Ian Jackson
<ijackson@chiark.greenend.org.uk>
Fri, 5 Feb 2016 19:06:55 +0000
(19:06 +0000)
commitid.scad.pl
patch
|
blob
|
history
diff --git
a/commitid.scad.pl
b/commitid.scad.pl
index ebdbe917a39a6cb73db24da322d83a22e85af045..fbeed6fe1a4518f42374901c003303f342b3d7c3 100755
(executable)
--- a/
commitid.scad.pl
+++ b/
commitid.scad.pl
@@
-268,16
+268,21
@@
our $do_git; # contains may chars 'c' (count) and/or 'o' (object)
our $do_git_untracked = 1;
our $argcounter;
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;
my $lw = length $whole;
- return $lw > $sz
- ? substr($whole, $lw-$sz)
- : sprintf "%${sz}s", $whole;
+ my $spare = $sz - $lw - (length $prefix);
+ return
+ $prefix.
+ ($spare > 0 ? (' ' x $spare) : '').
+ substr($whole, ($spare < 0 ? -$spare : 0));
}
}
-sub ljustt ($$
$) { # always includes $suffix
+sub ljustt ($$
;$) {
my ($sz, $whole, $suffix) = @_;
my ($sz, $whole, $suffix) = @_;
+ $suffix //= '';
$sz -= length $suffix;
return sprintf "%-${sz}.${sz}s%s", $whole, $suffix;
}
$sz -= length $suffix;
return sprintf "%-${sz}.${sz}s%s", $whole, $suffix;
}