From 42fff2c311f585befc430a23bb1bb743deb8654e Mon Sep 17 00:00:00 2001 From: Pat Thoyts Date: Wed, 24 Jul 2024 09:05:05 +0100 Subject: [PATCH] Limit the length of lines on the UI. Tk text widget has very poor performance with really long single lines of text but is improved by splitting up such lines into a number of shorter lines. Just show the timestamp for the first such line. --- bin/sockspy.tcl | 70 ++++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/bin/sockspy.tcl b/bin/sockspy.tcl index 95ba377..18a732f 100644 --- a/bin/sockspy.tcl +++ b/bin/sockspy.tcl @@ -99,6 +99,7 @@ array set state { timeFormat "" timeFormatDefault "%H:%M:%S " myaddr localhost + maxlinelen 160 } # variables to save across runs @@ -115,6 +116,7 @@ set saveList { state(fontSize) state(showsockname) state(myaddr) + state(maxlinelen) extract(client) extract(server) extract(meta2) @@ -513,48 +515,56 @@ proc insertData {who data {time {}} {force 0}} { array set prefix {meta = meta2 = client > server <} if {$time == ""} { ;# If not set, then set to now - set time [clock seconds] + set time [clock seconds] } set timestamp [timestamp $time] DoExtract $who $data $timestamp ;# Display any extracted data if {! $force && ! $state(capture)} return ;# No display w/o capture on lappend state(playback) $who $data $time ;# Save for redraw and saving - + if {$state(ascii) || [regexp {^meta2?$} $who] } { - regsub -all \r $data "" data - foreach line [split $data \n] { - set line [printable $line] - set tag $who - if {$tag == "client" && [regexp -nocase {^get |^post } $line]} { - lappend tag client2 - } - if {$state(gui)} { - .out insert end "$timestamp" time_$tag \ + regsub -all \r $data "" data + foreach line [split $data \n] { + set line [printable $line] + if {[string length $line] > $state(maxlinelen)} { + set indent [string repeat " " [string length $timestamp]] + for {set ndx 0} {$ndx < [string length $line]} {incr ndx $state(maxlinelen)} { + append line2 [string range $line $ndx [expr {$ndx + $state(maxlinelen) - 1}]]\n$indent + } + set line $line2; unset line2 + } + set tag $who + if {$tag == "client" && [regexp -nocase {^get |^post } $line]} { + lappend tag client2 + } + if {$state(gui)} { + .out insert end "$timestamp" time_$tag \ "$sockname " [concat $tag sockname] \ - "$line\n" $tag - } else { - puts "$timestamp$prefix($who)$line" - } - } - } else { ;# Hex output - while {[string length $data]} { - set line [string range $data 0 15] - set data [string range $data [string length $line] end] - binary scan $line H* hex - regsub -all {([0-9a-f][0-9a-f])} $hex {\1 } hex - set line [format "%-48.48s %-16.16s\n" $hex [printable $line 1]] - if {$state(gui)} { - .out insert end "$timestamp" time_$who \ + "$line" $tag \ + "\n" $tag + } else { + puts "$timestamp$prefix($who)${line}" + } + } + } else { ;# Hex output + while {[string length $data]} { + set line [string range $data 0 15] + set data [string range $data [string length $line] end] + binary scan $line H* hex + regsub -all {([0-9a-f][0-9a-f])} $hex {\1 } hex + set line [format "%-48.48s %-16.16s\n" $hex [printable $line 1]] + if {$state(gui)} { + .out insert end "$timestamp" time_$who \ "$sockname " [list $who sockname] \ "$line" $who - } else { - puts "$timestamp$prefix(who)$line" - } - } + } else { + puts "$timestamp$prefix(who)$line" + } + } } if {$state(autoscroll) && $state(gui)} { - .out see end + .out see end } } ##+########################################################################## -- 2.23.0