Add screen-size-report

This commit is contained in:
Jay McCarthy 2018-01-02 15:42:41 -05:00 committed by Tony Garnock-Jones
parent 4fb5b44366
commit f415faab55
2 changed files with 38 additions and 21 deletions

View File

@ -143,6 +143,8 @@
(define-variable-arity-escape-sequence (define-area-qualification args) CSI args "o")
(define-escape-sequence (device-request-screen-size) CSI "18t")
(define-escape-sequence (scroll-left n) CSI n " @")
(define-escape-sequence (scroll-right n) CSI n " A")

View File

@ -1,12 +1,21 @@
#lang racket/base
;; Lowest Common Denominator terminal.
(module+ event-structs
(provide (struct-out key)
(struct-out any-mouse-event)
(struct-out mouse-focus-event)
(struct-out mouse-event)
(struct-out unknown-escape-sequence)
(struct-out position-report)
(struct-out screen-size-report)))
(provide (struct-out key)
(struct-out any-mouse-event)
(struct-out mouse-focus-event)
(struct-out mouse-event)
(struct-out unknown-escape-sequence)
(struct-out position-report)
(struct-out screen-size-report)
add-modifier
lex-lcd-input
lcd-terminal-utf-8?
@ -28,6 +37,7 @@
(struct unknown-escape-sequence (string) #:prefab)
(struct key (value modifiers) #:prefab)
(struct position-report (row column) #:prefab)
(struct screen-size-report (rows columns) #:prefab)
(struct any-mouse-event () #:prefab)
(struct mouse-focus-event any-mouse-event (focus-in?) #:prefab)
@ -63,7 +73,8 @@
[_ (simple-key (unknown-escape-sequence lexeme))]))
(define (analyze-vt-tildeish-key* lexeme ctor a b)
(decode-shifting-number b
(decode-shifting-number
b
(match a
[1 (ctor 'home)] ;; linux console
[2 (ctor 'insert)]
@ -105,7 +116,8 @@
["P" #:when (not params) (simple-key 'delete)] ;; st, http://st.suckless.org/
["P" (decode-shifting params 'f1)]
["Q" (decode-shifting params 'f2)]
["R" #:when (and (= (length params) 2) (> (car params) 1)) (apply position-report params)]
["R" #:when (and (= (length params) 2) (> (car params) 1))
(apply position-report params)]
["R" (decode-shifting params 'f3)]
["S" (decode-shifting params 'f4)]
["Z" (C-S- #\I)] ;; TODO: should this instead be a 'backtab key?
@ -114,6 +126,7 @@
["c" (S- 'right)]
["d" (S- 'left)]
["h" #:when (equal? params '(4)) (simple-key 'insert)] ;; st, http://st.suckless.org/
["t" #:when (equal? (car params) 8) (apply screen-size-report (cdr params))]
[_ (simple-key (unknown-escape-sequence lexeme))]))
(define (analyze-vt-O-mainchar lexeme mainchar)
@ -239,14 +252,16 @@
(regexp-try-match #px#"^\x9b([0-9]+(;[0-9]+)*)?(.)" port)) =>
(lambda (match-result)
(match-define (list lexeme parambytes _ mainbytes) match-result)
(define params (and parambytes
(define params
(and parambytes
(map string->number (string-split (bytes->string/utf-8 parambytes) ";"))))
(analyze-vt-bracket-key lexeme params (bytes->string/utf-8 mainbytes)))]
[(regexp-try-match #px"^\eO([0-9])(.)" port) =>
;; screen generates shifting escapes for the keypad like this
(lambda (match-result)
(match-define (list lexeme v-plus-one-bytes mainbytes) match-result)
(decode-shifting-number (string->number (bytes->string/utf-8 v-plus-one-bytes))
(decode-shifting-number
(string->number (bytes->string/utf-8 v-plus-one-bytes))
(analyze-vt-O-mainchar lexeme (bytes->string/utf-8 mainbytes))))]
[(regexp-try-match #px"^\eO(.)" port) =>
(lambda (match-result)