From d331deaf6c656daf71d25d710ec739712e73151c Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Fri, 10 Jun 2022 17:02:29 -0400 Subject: add viewStatements support --- Makefile | 4 ++++ main.tcl | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e76caaef..af116775 100644 --- a/Makefile +++ b/Makefile @@ -13,3 +13,7 @@ Folk.app: rm -r /tmp/folk.vfs; mkdir /tmp/folk.vfs cp -r * /tmp/folk.vfs cd /tmp; tclsh ~/Downloads/sdx*kit wrap folk -runtime $(TCLKIT) + +NODE := localhost +view-statements: + echo viewStatements | nc $(NODE) 4273 diff --git a/main.tcl b/main.tcl index 3415af7e..d04256e6 100644 --- a/main.tcl +++ b/main.tcl @@ -102,6 +102,16 @@ proc evaluate {} { } +# pretty-prints latest statement set +proc viewStatements {} { + return [join [lmap statement [dict keys $::statements] { + lmap word $statement {expr { + [string length $word] > 20 ? + "[string range $word 0 20]..." : + $word + }} + }] "\n"] +} proc accept {chan addr port} { # (mostly for the Pi) # we want to be able to asynchronously receive statements @@ -109,8 +119,10 @@ proc accept {chan addr port} { while {[gets $chan line] != -1} { append script $line\n if {[info complete $script]} { - catch { + if {[catch { puts $chan [eval $script]; flush $chan + } ret]} { + puts $chan $ret; flush $chan } set script "" } -- cgit v1.2.3