[mdlug] printline - print a line of text within fields defined by column location
Jeff Hanson
jhansonxi at gmail.com
Mon Dec 1 03:06:42 EST 2014
https://github.com/jhansonxi/printline
This is a wrapper around a function I wrote to make it easier to print
complex data in a terminal with some auto-adjustment for terminal width.
Fields can be absolutely or relatively positioned and it supports boundary,
overflow, and non-printing characters (ANSI terminal escapes). It's part of
a large script project I've been working on. It started off as a simple
function to center text within a terminal window. After a ridiculous amount
of feature creep it turned it into a general-purpose print function. There
is some overlap with printf (and it relies on it) but its focus is more
towards reports. It's been tested with Dash and Bash on Xubuntu 14.04.
License is GPL3.
While it solved my problem I don't think it is the best solution to
generating reports in a terminal. It's slow and doesn't support wide
characters or column wrapping (wrapping can be faked with the last column
via a "fold|while read|printline" loop). I would rather see something like
printf + sed or xmlstarlet addressing where I could define templates for
field positions for a header, body, and footer, then pipe in data and have
it print a header, body text until it encounters a row limit or EOF, then
the footer, and repeat if necessary.
More information about the mdlug
mailing list