(use-modules (oop goops)) ;; ;; Pretext ;; (define (repeat n closure) "Execute closure n times." (if (not (and (exact? n) (integer? n) ; 'integer?' does not check for exactness ... (>= n 0))) (error "repeat: the parameter n must be an exact natural number or zero.") (let loop ((i 0)) (if (< i n) (begin (closure) (loop (1+ i)))) ))) ;; ;; Terminal ;; (define-class () ;; XXX guarantee rw access to the device (port #:init-value #f #:accessor get-port #:init-keyword #:port)) (define-method (control (terminal ) control-characters) (display (list->string control-characters) (get-port terminal))) (define-method (full-reset (terminal )) (control terminal '(#\esc #\c))) ;; ;; Control Sequence Introduction (define CSI '(#\esc #\[)) ;; ;; SRM: Send Receive Mode ;; turn terminal echo on or off (define-method (SRM-echo-off (terminal )) (control terminal (append CSI '(#\1 #\2 #\h)))) (define-method (SRM-echo-on (terminal )) (control terminal (append CSI '(#\1 #\2 #\l)))) ;; ;; CSI: Cursor Control (define-method (cursor-up (terminal )) (control terminal (append CSI '(#\A)))) (define-method (cursor-down (terminal )) (control terminal (append CSI '(#\B)))) (define-method (cursor-forward (terminal )) (control terminal (append CSI '(#\C)))) (define-method (cursor-backward (terminal )) (control terminal (append CSI '(#\D)))) ;; ;; si-nUI0 - test case (define term (make #:port (current-output-port))) (full-reset term) (display "Hallo World! This is si-nUI0.") (repeat 15 (lambda () (cursor-down term))) (repeat 20 (lambda () (cursor-forward term)))