Finding the width of a term -- library(printlength)

library(printlength) provides four predicates to determine how wide a term would be if written:


print_length(+Command, -Length)
This succeeds when Command would write Length characters to the current output stream, none of them being newline characters. print_length/2 allows you to determine how many columns an atom (or other term) would take if printed according to Command. The length of the output of any command at all can be determined this way, provided that it writes to the current stream, and not to a stream argument. print_length/2 fails if Command fails.
print_length(+Command, ?StartColumn, ?EndColumn)
This succeeds when executing Command would write EndColumn-StartColumn characters. Either StartColumn or EndColumn should be instantiated to an integer. Then one can solve for the other argument. Quintus Prolog numbers columns starting from 0 (think of line_position as "the number of characters that have already been read from/written on this line"), so print_length/3 will fail if StartColumn is negative. print_length/3 fails if Command fails.
print_lines(+Command, -Lines)
is true when Command would write Lines new-line characters to the current output stream. One use of this is to tell whether there would be any point in calling print_length/2.
tab_to(+Column)
Ensure that line_position(Current_output, Column) is true by writing 0 or 1 newlines and at most Column spaces to the Current_output stream.