From 5b631adfe4f061952a5d5a21efc1b768a7cf425e Mon Sep 17 00:00:00 2001 From: The_miro Date: Fri, 3 Jul 2026 10:49:27 +0200 Subject: [PATCH] implement txt2printr.sh to send ascii art to a parallel port needle printer writes raw bytes to /dev/lp0 (overridable via PRINTER_DEV): resets the printer with ESC @, converts LF to CRLF to avoid staircasing on raw device writes, then form-feeds to eject the page. --- txt2printr.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/txt2printr.sh b/txt2printr.sh index d16956c..99f6a45 100755 --- a/txt2printr.sh +++ b/txt2printr.sh @@ -1 +1,26 @@ #/bin/bash +# +# Sends an ascii-art text file to a parallel port needle/dot-matrix printer. +# +# Usage: ./txt2printr.sh [ascii-art.txt] +# Env: PRINTER_DEV - printer device node (default: /dev/lp0) + +infile="${1:-ascii-img.txt}" +dev="${PRINTER_DEV:-/dev/lp0}" + +if [ ! -f "$infile" ]; then + echo "txt2printr: file not found: $infile" >&2 + exit 1 +fi + +if [ ! -w "$dev" ]; then + echo "txt2printr: cannot write to printer device: $dev" >&2 + echo "txt2printr: set PRINTER_DEV to override, or check permissions/parport module" >&2 + exit 1 +fi + +{ + printf '\x1b\x40' # ESC @ - reset printer (ESC/P and IBM Proprinter compatible) + sed 's/$/\r/' "$infile" # CRLF line endings, needed for raw writes to avoid staircasing + printf '\x0c' # form feed - eject the page +} > "$dev"