Hi all,
I have a command line interface Perl application which I'm running on a Linux machine. I want to create a command that display it's output in table format. is there a Perl module that can help me with that. Currently I'm drawing my table as follows:
# print table header
# fields space allocation: underline, Path, Name, status, desc, reset
+underline
printf "\n\t%s%-20s| %-10s%-12s| %-20s%s\n", &colorParse('%u'), 'Path'
+, 'Name', '', 'Description', &colorParse('%n'); # header with some c
+olor characters
printf "\t%-20s| %-10s%-12s| %-20s\n", '', '', '', ''; # empty line u
+nder the header
while (my($key, $val) = each(%{$shares})) {
.... # extract $path, $name, $status, $desc
# color constants should be assigned with separate space in printf
+ (their space is deducted when we print)
# fields space allocation: pathColor, path, pathReset, shareName,
+statusColor, status, statusReset, desc
printf "\t%s%-20s%s| %-10s%s%-12s%s| %-20s\n", $pathColor, &trunca
+teStr($path, 20), $pathReset, &truncateStr($name, 10), $statusColor,
+$status, $statusReset, &truncateStr($desc, 20) || '';
}
parseColor() parses color control chars in the printed string,
trancateStr() trancates a long string according to the given size.
This works fine most of the times, but as you can see it's quite clumzy and hard to maintain. The output looks something like this:
Path | Name | Description
------------------------------------------------------------------
| |
/exadmin | testing | lalala
/ | test |
/test1 | test1 (inactive) | hello
RED - Directory is not accessible
Is there a better way?
Thanks