diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-01-27 01:21:29 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-01-27 01:21:29 -0800 |
commit | e5756fbef85f4ab29370da16ef533c770e0dabc2 (patch) | |
tree | c0c7fe1ed6a5b05ec7fd25d0db058ad1b32c21a9 /mu.arc | |
parent | 465007f11e5ccfede71e0afda44510eb1eae0ec7 (diff) | |
download | mu-e5756fbef85f4ab29370da16ef533c770e0dabc2.tar.gz |
638 - quick spike: syntax highlighting in repl
Backspace kinda works. Parens are colored in three rotating colors which helps with balancing. Comments and strings are colored. But it's hard to handle backspace in all situations. Like if you backspace over a quote you have to either quit the string-slurping routine you're in, or return to string slurping mode. Similarly for comments; *there* you don't even have a end delimiter to let you know you're back in a comment. You have to keep track of what came before. I experimented with a library but it interacts poorly with the charterm library I'm already using. Ended up with a gross inefficient approach instead.
Diffstat (limited to 'mu.arc')
-rw-r--r-- | mu.arc | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/mu.arc b/mu.arc index 14d23f95..5de3f75d 100644 --- a/mu.arc +++ b/mu.arc @@ -462,7 +462,13 @@ ($:require "charterm/main.rkt") ($:require graphics/graphics) +;? ($:require "terminal-color/terminal-color/main.rkt") ;? 1 (= Viewport nil) +; http://rosettacode.org/wiki/Terminal_control/Coloured_text#Racket +($:define (tput . xs) (system (apply ~a 'tput " " (add-between xs " "))) (void)) +($:define (foreground color) (tput 'setaf color)) +($:define (background color) (tput 'setab color)) +($:define (reset) (tput 'sgr0)) ; run instructions from 'routine*' for 'time-slice' (def run-for-time-slice (time-slice) @@ -769,10 +775,48 @@ $quit (quit) $wait-for-key-from-host - (if ($.current-charterm) - ($.charterm-read-key) - ($.graphics-open?) - ($.get-key-press Viewport)) + (when ($.current-charterm) + (ret result ($.charterm-read-key) + (case result + ; charterm exceptions + return + (= result #\newline) + backspace + (= result #\backspace) + ))) + $print-key-to-host + (do1 nil +;? (write (m arg.0)) (pr " => ") (prn (type (m arg.0))) + (if (no ($.current-charterm)) + (pr (m arg.0)) + (caselet x (m arg.0) + ; todo: test these exceptions + #\newline + ($.charterm-newline) + #\backspace + ; backspace doesn't clear after moving the cursor + (do ($.charterm-display #\backspace) + ($.charterm-display #\space) + ($.charterm-display #\backspace)) + ctrl-c + (do ($.close-charterm) + (die "interrupted")) + ;else + (if (len> arg 2) + (do + ($.foreground (m arg.1)) + ($.background (m arg.2)) + (pr x) + ($.reset)) + (len> arg 1) + (do + ($.foreground (m arg.1)) + (pr x) + ($.reset)) +;? (print-with-fg x (m arg.1)) ;? 1 + :else + ($.charterm-display x)))) + ) $eval (new-string:repr:eval:read:to-arc-string (m arg.0)) |