From 063626d150bfa5cb81dd1df2d552964e03de2c73 Mon Sep 17 00:00:00 2001 From: The_miro Date: Tue, 14 Jul 2026 10:28:33 +0200 Subject: [PATCH] add ruler mode to pagetest.sh for exact chars-per-line calibration Repeating-digit and prefixed-number test lines make it hard to read off exactly where a printer truncates a line. `./pagetest.sh ruler` prints a single line marking every 10th column with its tens digit and every 5th with '+', so the real cutoff column can be read directly off the page instead of estimated. Co-Authored-By: Claude Sonnet 5 --- pagetest.sh | 66 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/pagetest.sh b/pagetest.sh index 3a3c6b8..ac6576f 100755 --- a/pagetest.sh +++ b/pagetest.sh @@ -1,34 +1,58 @@ #!/bin/bash # -# Generates a page-break diagnostic file: numbered lines padded with '#' to -# a fixed width, so you can see exactly where a printer's real page length -# and line width limits are instead of guessing from paper geometry. +# Generates printer diagnostic files, so you can read a printer's real page +# capacity straight off the paper instead of guessing from paper geometry. # -# Usage: ./pagetest.sh [width] [lines] -# width - characters per line, including the "NNN " prefix (default 64) -# lines - number of lines to generate (default 100) +# Usage: +# ./pagetest.sh [width] [lines] - numbered lines padded with '#', to find +# a printer's real lines-per-page (the +# last line number printed on page 1) +# (default width=64, lines=100) +# ./pagetest.sh ruler [width] - a single long ruler line marking every +# 10th column with its tens digit and +# every 5th with '+', to find a +# printer's real chars-per-line exactly +# (default width=200) # -# Print the result with PRINTER_A4=false in printer.conf (no rotation), so -# the line numbers read straight off the page: +# Print the result with PRINTER_A4=false in printer.conf (no rotation): # ./txt2printr.sh pagetest.txt dir="$(dirname "$0")" -width="${1:-64}" -lines="${2:-100}" outfile="$dir/pagetest.txt" -awk -v width="$width" -v lines="$lines" ' - BEGIN { - for (i = 1; i <= lines; i++) { - prefix = sprintf("%03d ", i) - fill = width - length(prefix) - if (fill < 0) fill = 0 - line = prefix - for (j = 0; j < fill; j++) line = line "#" +if [ "$1" = "ruler" ]; then + width="${2:-200}" + awk -v width="$width" ' + BEGIN { + line = "" + for (i = 1; i <= width; i++) { + if (i % 10 == 0) line = line (int(i / 10) % 10) + else if (i % 5 == 0) line = line "+" + else line = line "-" + } print line } - } -' > "$outfile" + ' > "$outfile" + echo "Wrote a $width-char ruler line to $outfile" + echo "Every 10th column is marked with its tens digit (column 40 -> '4'," + echo "column 100 -> '0'), every 5th with '+'. Read off the last marker" + echo "that fully prints to get your printer's exact chars-per-line." +else + width="${1:-64}" + lines="${2:-100}" + awk -v width="$width" -v lines="$lines" ' + BEGIN { + for (i = 1; i <= lines; i++) { + prefix = sprintf("%03d ", i) + fill = width - length(prefix) + if (fill < 0) fill = 0 + line = prefix + for (j = 0; j < fill; j++) line = line "#" + print line + } + } + ' > "$outfile" + echo "Wrote $lines lines x $width chars to $outfile" +fi -echo "Wrote $lines lines x $width chars to $outfile" echo "Print it with: PRINTER_DEV=/dev/lp0 \"$dir/txt2printr.sh\" \"$outfile\""