Better explicit control over utf-8 input mode
This commit is contained in:
parent
45b89d9682
commit
46d97f0926
|
@ -145,7 +145,7 @@
|
||||||
[(<= #x20 b #x7e) (simple-key (integer->char b))]
|
[(<= #x20 b #x7e) (simple-key (integer->char b))]
|
||||||
[(= b #x7f) (simple-key 'backspace)]))
|
[(= b #x7f) (simple-key 'backspace)]))
|
||||||
|
|
||||||
(define (lex-lcd-input port)
|
(define (lex-lcd-input port #:utf-8? [utf-8? (lcd-terminal-utf-8?)])
|
||||||
(cond
|
(cond
|
||||||
[(eof-object? (peek-byte port)) eof]
|
[(eof-object? (peek-byte port)) eof]
|
||||||
[(or (regexp-try-match #px"^\e\\[([0-9]+(;[0-9]+)*)?(.)" port)
|
[(or (regexp-try-match #px"^\e\\[([0-9]+(;[0-9]+)*)?(.)" port)
|
||||||
|
@ -168,8 +168,8 @@
|
||||||
;; Characters between #\u80 and #\uff are ambiguous because in
|
;; Characters between #\u80 and #\uff are ambiguous because in
|
||||||
;; some terminals, the high bit is set to indicate meta, and in
|
;; some terminals, the high bit is set to indicate meta, and in
|
||||||
;; others, they are plain UTF-8 characters. We let the user
|
;; others, they are plain UTF-8 characters. We let the user
|
||||||
;; distinguish via the lcd-terminal-utf-8? parameter.
|
;; distinguish via the #:utf-8? keyword argument.
|
||||||
[(not (lcd-terminal-utf-8?))
|
[(not utf-8?)
|
||||||
(define b (read-byte port))
|
(define b (read-byte port))
|
||||||
(if (< b 128)
|
(if (< b 128)
|
||||||
(interpret-ascii-code b)
|
(interpret-ascii-code b)
|
||||||
|
|
|
@ -9,6 +9,12 @@
|
||||||
(define (main)
|
(define (main)
|
||||||
(tty-raw!)
|
(tty-raw!)
|
||||||
|
|
||||||
|
(define utf-8?
|
||||||
|
(match (current-command-line-arguments)
|
||||||
|
[(or '#() '#("--utf-8")) #t]
|
||||||
|
['#("--no-utf-8") #f]
|
||||||
|
[_ (error 'main "Usage: test-raw [ --utf-8 / --no-utf-8 ]")]))
|
||||||
|
|
||||||
(plumber-add-flush! (current-plumber)
|
(plumber-add-flush! (current-plumber)
|
||||||
(lambda (handle)
|
(lambda (handle)
|
||||||
(display (reset-mode x11-any-event-mouse-tracking-mode))))
|
(display (reset-mode x11-any-event-mouse-tracking-mode))))
|
||||||
|
@ -19,7 +25,7 @@
|
||||||
(display "Type keys. Press control-D to exit.\r\n")
|
(display "Type keys. Press control-D to exit.\r\n")
|
||||||
(let loop ()
|
(let loop ()
|
||||||
(flush-output)
|
(flush-output)
|
||||||
(match (lex-lcd-input (current-input-port))
|
(match (lex-lcd-input (current-input-port) #:utf-8? utf-8?)
|
||||||
[(? eof-object?) (void)]
|
[(? eof-object?) (void)]
|
||||||
[(== (key #\D (set 'control))) (void)]
|
[(== (key #\D (set 'control))) (void)]
|
||||||
[key
|
[key
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
key-reader ;; InputPort -> Key
|
key-reader ;; InputPort -> Key
|
||||||
[displayed-screen #:mutable] ;; Screen
|
[displayed-screen #:mutable] ;; Screen
|
||||||
[pending-screen #:mutable] ;; Screen
|
[pending-screen #:mutable] ;; Screen
|
||||||
|
[utf-8-input? #:mutable] ;; Boolean
|
||||||
) #:prefab)
|
) #:prefab)
|
||||||
|
|
||||||
(define (make-screen rows columns pen)
|
(define (make-screen rows columns pen)
|
||||||
|
@ -80,7 +81,14 @@
|
||||||
(current-output-port)
|
(current-output-port)
|
||||||
ansi:lex-lcd-input
|
ansi:lex-lcd-input
|
||||||
(make-screen 24 80 tty-default-pen)
|
(make-screen 24 80 tty-default-pen)
|
||||||
(make-screen 24 80 tty-default-pen)))
|
(make-screen 24 80 tty-default-pen)
|
||||||
|
(match (getenv "RMACS_UTF8_INPUT")
|
||||||
|
[(or #f "yes" "true" "1") #t]
|
||||||
|
[(or "no" "false" "0") #f]
|
||||||
|
[v (error 'RMACS_UTF8_INPUT
|
||||||
|
"Environment variable RMACS_UTF8_INPUT value ~v invalid: must be in ~v"
|
||||||
|
v
|
||||||
|
(list "yes" "true" "1" "no" "false" "0"))])))
|
||||||
(reset *stdin-tty*)
|
(reset *stdin-tty*)
|
||||||
(plumber-add-flush! (current-plumber)
|
(plumber-add-flush! (current-plumber)
|
||||||
(lambda (h)
|
(lambda (h)
|
||||||
|
@ -360,7 +368,7 @@
|
||||||
;; Input
|
;; Input
|
||||||
|
|
||||||
(define (tty-next-key tty)
|
(define (tty-next-key tty)
|
||||||
(define k (ansi:lex-lcd-input (tty-input tty)))
|
(define k (ansi:lex-lcd-input (tty-input tty) #:utf-8? (tty-utf-8-input? tty)))
|
||||||
(if (equal? k (ansi:key #\[ (set 'control))) ;; ESC
|
(if (equal? k (ansi:key #\[ (set 'control))) ;; ESC
|
||||||
(or (sync/timeout 0.5
|
(or (sync/timeout 0.5
|
||||||
(handle-evt (tty-next-key-evt tty)
|
(handle-evt (tty-next-key-evt tty)
|
||||||
|
|
Loading…
Reference in New Issue