- Thread Starter
- #51
Thank You !this will create a pdf out of aha's output |reads html from stdin, writes pdf to stdout
requires tcl, tdom, pdf4tcl but the get the latest version from sourceforge, port is buggy
Code:package require tdom #lappend auto_path /extra/fs/d/tcl86/Tcl-amd64/lib package require pdf4tcl proc mm2p { x } { return [expr {$x / 25.4 * 72}] } encoding system utf-8 set FONT_SIZE 18 pdf4tcl::new mypdf -margin 0 -paper A3 -landscape 1 pdf4tcl::loadBaseTrueTypeFont Baseunifont unifont-15.0.01.ttf pdf4tcl::createFont Baseunifont TestFont utf-8 mypdf setFont $FONT_SIZE TestFont mypdf setFillColor 0 0 0 mypdf rectangle 0 0 [mm2p 420] [mm2p 297] -filled 1 set fh [mypdf getFontMetric height] set fw [mypdf getCharWidth T] set html [read stdin] set doc [dom parse -keepEmpties -html $html ] set rootnode [$doc documentElement] set x0 [mm2p 5] set y0 [mm2p 5] set x $x0 set y $y0 set ppnodes [$rootnode selectNodes "//span/text()"] foreach node $ppnodes { set pnode [$node parent] set bold_hack 0 if { [$pnode hasAttribute style ] } { set stl [$pnode getAttribute style] set lsl [split $stl ";"] foreach s $lsl { if { $s == "" } { continue } set ss [split $s ":"] if { [llength $ss] == 2 } { switch [lindex $ss 0 ] { color { lappend gugu [list setFillColor [lindex $ss 1]] } background-color { lappend gugu [list setBgColor [lindex $ss 1]] } font-weight { if { [lindex $ss 1] == "bold" } { set bold_hack 1 } } } } } } set text [$node nodeValue] set ltext [split $text "\n"] set had_nl 0 set zz [string length $text] for { set i 0 } { $i < $zz } { incr i } { set shit [string range $text $i $i] if { ![info exists A($shit) ]} { set A($shit) 1 lappend Z [scan $shit %c] } } foreach str $ltext { if { $had_nl } { set x $x0 set y [expr {$y + $fh }] # puts "" } lappend gugu [list $str $x $y] if { $bold_hack } { lappend gugu [list $str [expr $x+0.3] [expr $y+0.3]] } set x [expr {$x +[string length $str] * $fw }] # puts -nonewline $str set had_nl 1 } } #puts $Z pdf4tcl::createFontSpecEnc Baseunifont CombinedFont $Z mypdf setFont $FONT_SIZE CombinedFont foreach cmd $gugu { set n [llength $cmd ] if { $n == 3 } { mypdf text [lindex $cmd 0] -x [lindex $cmd 1] -y [lindex $cmd 2] } else { mypdf [lindex $cmd 0] [lindex $cmd 1] } } mypdf write mypdf destroy
But screenshot still needed

Bpytop/btop just stay on screen 24/7, like top. I need something in background to "snap" an on-screen output (TUI, no GUI) to .jpg or .png and place it in certain dir.