diff options
| author | Omar Rizwan <omar@omar.website> | 2024-05-30 22:49:19 +0000 |
|---|---|---|
| committer | Omar Rizwan <omar@omar.website> | 2024-05-30 22:49:19 +0000 |
| commit | 6fe9264a2ed7b68792a669c19af50c607d8a1649 (patch) | |
| tree | 0d35651dd1b26c44c12366523fb2df6f3d650883 /virtual-programs | |
| parent | Layout printed programs over multiple pages (diff) | |
| download | folk-6fe9264a2ed7b68792a669c19af50c607d8a1649.tar.gz folk-6fe9264a2ed7b68792a669c19af50c607d8a1649.zip | |
print: Add fallback to bare lpr so printer config not needed
Fix other quirks. Disable print on back since we don't use it anyway
Diffstat (limited to 'virtual-programs')
| -rw-r--r-- | virtual-programs/print.folk | 62 |
1 files changed, 27 insertions, 35 deletions
diff --git a/virtual-programs/print.folk b/virtual-programs/print.folk index 84029c40..ed912b8e 100644 --- a/virtual-programs/print.folk +++ b/virtual-programs/print.folk @@ -9,7 +9,7 @@ # Claim printer my-printer can print double-sided a4 paper # Claim printer alt-printer can print single-sided indexcard paper # -# Use "two-sided" if the printer supports printing on both sides of the paper in a single printing operation. +# Use "double-sided" if the printer supports printing on both sides of the paper in a single printing operation. # # Lastly, you need to declare a default printer and default paper format: # (make sure that the default printer supports the default paper format) @@ -252,7 +252,7 @@ When /someone/ wishes to print /code/ with /...options/ { When /someone/ wishes to print program /id/ with /...options/ { if {$::thisNode eq "folk-beads" || $::thisNode eq "folk-convivial"} { # HACK: Forward the print request to folk0. - remotePrintRequest "folk0" [list $::thisNode wishes to print progam $id with {*}$options] + remotePrintRequest "folk0" [list $::thisNode wishes to print program $id with {*}$options] return } @@ -269,51 +269,46 @@ When /someone/ wishes to print program /id/ with /...options/ { if {![dict exists $options format]} { lappend defaultStatements & /someone/ claims paper format /format/ is the default paper format } + # TODO: we don't use /sided/ for anything right now. set query {/someone/ claims printer /printer/ can print /sided/ /format/ paper} # first try to satisfy given constraints and any remaining defaults set results [Statements::findMatchesJoining [list $query $defaultStatements] $options] - if {$results eq ""} { + if {[llength $results] == 0} { # fall back to solving only for explicit constraints set results [Statements::findMatchesJoining [list $query] $options] } - if {$results eq ""} { - error "Couldn't find a matching printer" - } - - set results [lindex $results 0] - dict with results { - set args [list -P $printer -o media=$format] - dict set ::printjobs $jobid [list $id $args] - - set code [dict get $options code] - set ps [programToPs $id $code $format] - if {$sided eq "single-sided"} { - lappend args -o page-ranges=1 + if {[llength $results] > 0} { + set result [lindex $results 0] + dict with result { + set args [list -P $printer -o media=$format] } + } else { + puts stderr "print.folk: Couldn't find a matching configured printer; using bare lpr command" + set args [list] + set format letter + } - # save code and ps to disk - if {[file exists "$::env(HOME)/folk-printed-programs/$id.folk"]} { - error "Program $id already exists on disk. Aborting print." - } - set fp [open "$::env(HOME)/folk-printed-programs/$id.folk" w] - puts $fp $code - close $fp + dict set ::printjobs $jobid [list $id $args] - set fp [open "$::env(HOME)/folk-printed-programs/$id.ps" w] - puts $fp $ps - close $fp + set code [dict get $options code] + set ps [programToPs $id $code $format] - exec ps2pdf $::env(HOME)/folk-printed-programs/$id.ps $::env(HOME)/folk-printed-programs/$id.pdf - puts [list lpr {*}$args $::env(HOME)/folk-printed-programs/$id.pdf] + # save code and ps to disk + if {[file exists "$::env(HOME)/folk-printed-programs/$id.folk"]} { + error "Program $id already exists on disk. Aborting print." } -} + set fp [open "$::env(HOME)/folk-printed-programs/$id.folk" w] + puts $fp $code + close $fp -When /someone/ wishes to print the back of job-id /jobid/ { - lassign [dict get $::printjobs $jobid] id args + set fp [open "$::env(HOME)/folk-printed-programs/$id.ps" w] + puts $fp $ps + close $fp - puts [list lpr {*}$args -o page-ranges=2 $::env(HOME)/folk-printed-programs/$id.pdf] + exec ps2pdf $::env(HOME)/folk-printed-programs/$id.ps $::env(HOME)/folk-printed-programs/$id.pdf + exec lpr {*}$args $::env(HOME)/folk-printed-programs/$id.pdf } # legacy syntax @@ -323,6 +318,3 @@ When /someone/ wishes to print /code/ with job id /id/ { When /someone/ wishes to print program /id/ with /code/ with job id /id/ { Say $::thisNode wishes to print program $id with $code with job-id $id } -When /someone/ wishes to print the back of job id /jobid/ { - Say $::thisNode wishes to print the back of job-id $id -} |
