mirror of
https://gitlab.com/eql/lqml.git
synced 2025-12-06 18:40:56 -08:00
add new example 'debug-ui' (to be integrated in your mobile app)
This commit is contained in:
parent
ee72fc8847
commit
3b1934f3bf
16 changed files with 461 additions and 0 deletions
53
examples/debug-ui/lisp/d-input-hook.lisp
Normal file
53
examples/debug-ui/lisp/d-input-hook.lisp
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
;;; idea & most code from "ecl-readline.lisp"
|
||||
|
||||
(defpackage input-hook
|
||||
(:use :cl)
|
||||
(:export
|
||||
#:add))
|
||||
|
||||
(provide :input-hook)
|
||||
|
||||
(in-package :input-hook)
|
||||
|
||||
(defvar *functions* nil)
|
||||
|
||||
(defun add (function)
|
||||
(let ((stream (make-instance 'input-hook-stream)))
|
||||
(push (cons stream function) *functions*)
|
||||
stream))
|
||||
|
||||
(defclass input-hook-stream (gray:fundamental-character-input-stream)
|
||||
((buffer :initform (make-string 0))
|
||||
(index :initform 0)))
|
||||
|
||||
(defmethod gray:stream-read-char ((stream input-hook-stream))
|
||||
(if (ensure-stream-data stream)
|
||||
(with-slots (buffer index) stream
|
||||
(let ((ch (char buffer index)))
|
||||
(incf index)
|
||||
ch))
|
||||
:eof))
|
||||
|
||||
(defmethod gray:stream-unread-char ((stream input-hook-stream) character)
|
||||
(with-slots (index) stream
|
||||
(when (> index 0)
|
||||
(decf index))))
|
||||
|
||||
(defmethod gray:stream-listen ((stream input-hook-stream))
|
||||
nil)
|
||||
|
||||
(defmethod gray:stream-clear-input ((stream input-hook-stream))
|
||||
nil)
|
||||
|
||||
(defmethod gray:stream-peek-char ((stream input-hook-stream))
|
||||
(if (ensure-stream-data stream)
|
||||
(with-slots (buffer index) stream
|
||||
(char buffer index))
|
||||
:eof))
|
||||
|
||||
(defun ensure-stream-data (stream)
|
||||
(with-slots (buffer index) stream
|
||||
(when (= index (length buffer))
|
||||
(setf buffer (funcall (cdr (assoc stream *functions*)))
|
||||
index 0))
|
||||
buffer))
|
||||
Loading…
Add table
Add a link
Reference in a new issue