From fbe0aadb19baac5ba28f81cd9c5e3c5fa8bdb7ac Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 5 Feb 2016 19:06:55 +0000 Subject: [PATCH] commitid.scad.pl: make rjustt take $prefix (nfc as yet) --- commitid.scad.pl | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/commitid.scad.pl b/commitid.scad.pl index ebdbe91..fbeed6f 100755 --- 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; -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 + $prefix. + ($spare > 0 ? (' ' x $spare) : ''). + 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; } -- 2.30.2