diff options
Diffstat (limited to 'virtual-programs/editor.folk')
| -rw-r--r-- | virtual-programs/editor.folk | 160 |
1 files changed, 69 insertions, 91 deletions
diff --git a/virtual-programs/editor.folk b/virtual-programs/editor.folk index 624b9387..6ac074dd 100644 --- a/virtual-programs/editor.folk +++ b/virtual-programs/editor.folk @@ -15,8 +15,8 @@ When /page/ is a keyboard with path /kbPath/ &\ Claim $id has region [region move $r up 210%] When /nobody/ claims $id has program code /c/ { Commit "code$kbPath" { - Claim $id has program code $baseCode - Claim $id has editor code $baseCode + Claim $id has program code $baseCode + Claim $id has editor code $baseCode } } @@ -191,7 +191,7 @@ proc getCurrentLineLength {lines cursor} { When /page/ is a keyboard with path /kbPath/ & /page/ is an editor { set id "$page$kbPath" - Every time keyboard $kbPath claims key /currentCharacter/ is /keyState/ with modifiers /modifier/ timestamp /timestamp/ &\ + Every time keyboard $kbPath claims key /currentCharacter/ is /keyState/ with timestamp /timestamp/ &\ the $kbPath cursor is /cursor/ &\ $id has program code /code/ &\ $id has editor code /editorCode/ &\ @@ -199,7 +199,7 @@ When /page/ is a keyboard with path /kbPath/ & /page/ is an editor { if {($keyState == "down" || $keyState == "repeat") & $timestamp > ($startTime * 1000) } { Commit "cursor$kbPath" { switch $currentCharacter { - UP { + Up { set updatedCursor [updateCursor $cursor {y -1}] set currentLineLength [getCurrentLineLength $editorCode $updatedCursor] if {[x $updatedCursor] > $currentLineLength} { @@ -208,7 +208,7 @@ When /page/ is a keyboard with path /kbPath/ & /page/ is an editor { Claim the $kbPath cursor is $updatedCursor } } - DOWN { + Down { set linecount [llength [split $editorCode "\n"]] set updatedCursor [updateCursor $cursor {y 1}] set currentLineLength [getCurrentLineLength $editorCode $updatedCursor] @@ -222,7 +222,7 @@ When /page/ is a keyboard with path /kbPath/ & /page/ is an editor { Claim the $kbPath cursor is $updatedCursor } } - RIGHT { + Right { set currentLineLength [getCurrentLineLength $editorCode $cursor] if {[x $cursor] == $currentLineLength} { if {[y $cursor] == [expr {[llength [split $editorCode "\n"]] - 1}]} { @@ -235,7 +235,7 @@ When /page/ is a keyboard with path /kbPath/ & /page/ is an editor { Claim the $kbPath cursor is [updateCursor $cursor {x 1}] } } - LEFT { + Left { if {[x $cursor] == 0 && [y $cursor] == 0} { Claim the $kbPath cursor is $cursor } elseif {[x $cursor] == 0} { @@ -247,7 +247,7 @@ When /page/ is a keyboard with path /kbPath/ & /page/ is an editor { Claim the $kbPath cursor is [updateCursor $cursor {x -1}] } } - BACKSPACE { + Remove { # if cursor is at the beginning of the line, delete the newline if {[x $cursor] == 0 && [y $cursor] > 0} { set newCursor [updateCursor $cursor {y -1}] @@ -262,14 +262,14 @@ When /page/ is a keyboard with path /kbPath/ & /page/ is an editor { Claim $id has editor code [deleteCharacter $editorCode $cursor] } } - SPACE { + space { Claim the $kbPath cursor is [updateCursor $cursor {x 1}] Commit "code$kbPath" { Claim $id has program code $code Claim $id has editor code [insertCharacter $editorCode " " $cursor] } } - ENTER { + Return { set updatedCursor [updateCursor $cursor {y 1}] Claim the $kbPath cursor is [list 0 [y $updatedCursor]] Commit "code$kbPath" { @@ -277,99 +277,77 @@ When /page/ is a keyboard with path /kbPath/ & /page/ is an editor { Claim $id has editor code [insertNewline $editorCode $cursor] } } - DELETE - - INSERT - - MUTE - - VOLUMEUP - - VOLUMEDOWN - - ESC - - TAB - - CAPSLOCK - - LEFTSHIFT - - RIGHTSHIFT - - LEFTALT - - RIGHTALT - - LEFTCTRL - - RIGHTCTRL { - # TODO: Implement DELETE, operates like BACKSPACE, but in the opposite direction - # TODO: MUTE VOLUMEUP VOLUMEDOWN - # implement sound.folk that allows a system-wide - # volume setting to be adjusted. - # Perhaps `Wish $system volume is 0.5` or something - - Claim the $kbPath cursor is $cursor - } - default { - if {$modifier == "ctrl" & $currentCharacter == "p"} { - 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 + # TODO: Implement DELETE, operates like BACKSPACE, but in the opposite direction + # TODO: MUTE VOLUMEUP VOLUMEDOWN + # implement sound.folk that allows a system-wide + # volume setting to be adjusted. + # Perhaps `Wish $system volume is 0.5` or something + Control_p { + 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 } + } - Commit print { Claim $id has printed $code at $timestamp} - Wish to print $code with job-id [expr {rand()}] + 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 - } - Claim the $kbPath cursor is $cursor - return + Commit "code$kbPath" { + Claim $id has program code $code + Claim $id has editor code $editorCode } - if {$modifier == "ctrl" & $currentCharacter == "r"} { - Commit "code$kbPath" { - Claim $id has program code $baseCode - Claim $id has editor code $baseCode - } - Claim the $kbPath cursor is [list 0 0] - return + Claim the $kbPath cursor is $cursor + } + Control_r { + Commit "code$kbPath" { + Claim $id has program code $baseCode + Claim $id has editor code $baseCode } - if {$modifier == "ctrl" & $currentCharacter == "s"} { - Commit "code$kbPath" { - Claim $id has program code $editorCode - Claim $id has editor code $editorCode - } - Claim the $kbPath cursor is $cursor - return + Claim the $kbPath cursor is [list 0 0] + } + Control_s { + Commit "code$kbPath" { + Claim $id has program code $editorCode + Claim $id has editor code $editorCode } - if {$modifier == "ctrl" & $currentCharacter == "a"} { - Commit "code$kbPath" { - Claim $id has program code $code - Claim $id has editor code $editorCode - } - lassign $cursor x y - Claim the $kbPath cursor is [list 0 $y] - return + Claim the $kbPath cursor is $cursor + } + Control_a { + Commit "code$kbPath" { + Claim $id has program code $code + Claim $id has editor code $editorCode } - if {$modifier == "ctrl" & $currentCharacter == "e"} { - Commit "code$kbPath" { - Claim $id has program code $code - Claim $id has editor code $editorCode - } - lassign $cursor x y - Claim the $kbPath cursor is [list [getLineLength $editorCode $cursor] $y] - return + lassign $cursor x y + Claim the $kbPath cursor is [list 0 $y] + } + Control_e { + Commit "code$kbPath" { + Claim $id has program code $code + Claim $id has editor code $editorCode } - if {$modifier == "ctrl" & $currentCharacter == "u"} { - # delete from cursor back to 0 and move cursor to 0 + lassign $cursor x y + Claim the $kbPath cursor is [list [getLineLength $editorCode $cursor] $y] + } + Control_u { + # delete from cursor back to 0 and move cursor to 0 + Commit "code$kbPath" { + Claim $id has program code $code + Claim $id has editor code [deleteToBeginning $editorCode $cursor] + } + lassign $cursor x y + Claim the $kbPath cursor is [list 0 $y] + } + default { + if {[set printable [keymap::printable $currentCharacter]] neq ""} { + Claim the $kbPath cursor is [updateCursor $cursor {x 1}] Commit "code$kbPath" { Claim $id has program code $code - Claim $id has editor code [deleteToBeginning $editorCode $cursor] + Claim $id has editor code [insertCharacter $editorCode $printable $cursor] } - lassign $cursor x y - Claim the $kbPath cursor is [list 0 $y] - return - } - Claim the $kbPath cursor is [updateCursor $cursor {x 1}] - Commit "code$kbPath" { - Claim $id has program code $code - Claim $id has editor code [insertCharacter $editorCode $currentCharacter $cursor] } } } |
