summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Rizwan <omar@omar.website>2022-06-10 21:02:29 +0000
committerOmar Rizwan <omar@omar.website>2022-06-10 21:02:29 +0000
commitd331deaf6c656daf71d25d710ec739712e73151c (patch)
tree0cbaf92de94cdc7e643cd9c3db6e788e9a936fdd
parenthalf-duplex tcp connection (goal: you can also look up statements) (diff)
downloadfolk-d331deaf6c656daf71d25d710ec739712e73151c.tar.gz
folk-d331deaf6c656daf71d25d710ec739712e73151c.zip
add viewStatements support
-rw-r--r--Makefile4
-rw-r--r--main.tcl14
2 files changed, 17 insertions, 1 deletions
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 ""
}