From 0df328a4efe3a02f064fd0cb40945790caeb37cb Mon Sep 17 00:00:00 2001 From: Aleteoryx Date: Sun, 21 Sep 2025 14:29:27 -0400 Subject: [PATCH] sixels in motd --- ntalk.tcl | 84 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 25 deletions(-) diff --git a/ntalk.tcl b/ntalk.tcl index 7404babd8276d1e89bb0fb68c37bed085939ae1a..a551df12bba05c4aede116f6d2e29a920af87263 100755 --- a/ntalk.tcl +++ b/ntalk.tcl @@ -156,6 +156,31 @@ proc sixels2image {sixels} { return $image } +proc parseline {line} { + set chunks {} + + set idx1 -1 + set idx2 -1 + while {[set idx2 [string first "\\(" $line $idx1]] != -1} { + # insert the prefix text + lappend chunks [string range $line $idx1 $idx2-1] + + # get the sixels + set idx1 $idx2 + set idx2 [string first ")" $line $idx1+2] + if {$idx2 == -1} { set idx2 [string length $line] } + + # insert them + set image [sixels2image [string range $line $idx1+2 $idx2-1]] + lappend chunks [list [string range $line $idx1 $idx2] $image] + + set idx1 [expr {$idx2 + 1}] + } + lappend chunks [string range $line $idx1 end] + + return $chunks +} + ### FONT STUFF ### @@ -173,8 +198,7 @@ make16 ### UI SETUP ### -set motd "no MOTD yet! maybe you should send one..." -label .head -textvariable motd +label .motd frame .foot entry .foot.input @@ -190,7 +214,7 @@ pack .foot.ppl .foot.sep .foot.msgs -side right pack .foot.name -side left pack .foot.input -side bottom -fill x -pack .head -side top +pack .motd -side top pack .foot -side bottom -fill x pack .scroll -side right -fill y pack .buffer -fill both @@ -244,6 +268,27 @@ menu .menu.sixels.rm -tearoff 0 . configure -menu .menu +### MOTD ### + +proc setmotd {newmotd} { + global motd + + destroy {*}[winfo children .motd] + foreach {text image} [parseline $newmotd] { + set tlabel [label .motd.[incr i] -text $text] + pack $tlabel -side left + + if {$image != {}} { + lassign $image _ image + set ilabel [label .motd.[incr i] -image $image] + pack $ilabel -side left + } + } + + set motd $newmotd +} +setmotd "no MOTD yet! maybe you should send one..." + ### USER SIXEL LIBRARY ### @@ -454,11 +499,11 @@ proc bufpush {line} { set tag {} if {[string first "MOTD:" $line] == 0} { - set motd [string trim [string range $line 5 end]] + setmotd [string trim [string range $line 5 end]] set line "<<< $motd >>>" set tag motd } elseif {[string first "MOTD" $line] == 0} { - set motd [string trim [string range $line 4 end]] + setmotd [string trim [string range $line 4 end]] set line "<<< $motd >>>" set tag motd } elseif {[regexp "\[^\\w.\]${user}\[^\\w.\]" $line]} { @@ -466,28 +511,17 @@ proc bufpush {line} { } .buffer configure -state normal - - set idx1 -1 - set idx2 -1 - while {[set idx2 [string first "\\(" $line $idx1]] != -1} { - # insert the prefix text - .buffer insert end [string range $line $idx1 $idx2-1] $tag - - # get the sixels - set idx1 $idx2 - set idx2 [string first ")" $line $idx1+2] - if {$idx2 == -1} { set idx2 [string length $line] } - - # insert them - .buffer insert end [string range $line $idx1 $idx2] rawsixel - set image [sixels2image [string range $line $idx1+2 $idx2-1]] - .buffer image create end -image $image - - set idx1 [expr {$idx2 + 1}] + foreach {text image} [parseline $line] { + .buffer insert end $text $tag + + if {$image != {}} { + lassign $image raw image + .buffer insert end $raw [concat rawsixel $tag] + .buffer image create end -image $image + .buffer tag add $tag {end -1 chars} + } } - .buffer insert end [string range $line $idx1 end] $tag .buffer insert end "\n" $tag - .buffer configure -state disabled } proc bufdown {} {