From 731c69fdf098049018f0ce66a89a09a22892142a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Cuervo?= Date: Mon, 26 Feb 2024 17:08:08 -0500 Subject: Fix printing from editors - Fix a bug where each editor could only print once because of a mistaken use of /nobody/ in the print conditional - Add a timestamp to the print commit - Prevent printing the same code twice within a second --- virtual-programs/editor.folk | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/editor.folk b/virtual-programs/editor.folk index 00803b3b..201dc7bb 100644 --- a/virtual-programs/editor.folk +++ b/virtual-programs/editor.folk @@ -1,4 +1,3 @@ -set ::debug_print false set baseCode "Wish \$this is outlined green" # This makes all keyboards into editors automatically, so a keyboard @@ -302,24 +301,20 @@ When /page/ is a keyboard with path /kbPath/ & /page/ is an editor { } default { if {$modifier == "ctrl" & $currentCharacter == "p"} { - # TODO: Save time instead and prevent printing the same code within the same ... second? - When $id has printed /lastPrintedCode/ { - if {$lastPrintedCode == $code} { - Claim the $kbPath cursor is $cursor - if {$::debug_print} { - puts "Not printing the same code twice" + When $id has printed /lastPrintedCode/ at /previousTime/ { + if {($timestamp - $previousTime) < 1000} { + Commit "code$kbPath" { + Claim $id has program code $code + Claim $id has editor code $editorCode } + Claim the $kbPath cursor is $cursor return } } - When /nobody/ has printed /lastPrintedCode/ { - if {$::debug_print} { - puts "Printing $code" - } - Commit print { Claim $id has printed $code} - Wish to print $code with job id [expr {rand()}] - return - } + + Commit print { Claim $id has printed $code at $timestamp} + Wish to print $code with job id [expr {rand()}] + Commit "code$kbPath" { Claim $id has program code $code Claim $id has editor code $editorCode -- cgit v1.2.3