From f0b3bfc16da84f6809639360568ea07cd3fc3916 Mon Sep 17 00:00:00 2001 From: "pls.153" Date: Wed, 2 Mar 2022 23:32:42 +0100 Subject: [PATCH] revision of example 'swank-server' --- examples/swank-server/lisp/eval.lisp | 51 ++++++++---------- examples/swank-server/lisp/ui-vars.lisp | 4 +- examples/swank-server/qml/ext/Flickable2.qml | 16 ------ examples/swank-server/qml/ext/Repl.qml | 54 +++++++++++++------- examples/swank-server/readme.md | 3 -- 5 files changed, 59 insertions(+), 69 deletions(-) delete mode 100644 examples/swank-server/qml/ext/Flickable2.qml diff --git a/examples/swank-server/lisp/eval.lisp b/examples/swank-server/lisp/eval.lisp index 265c47d..2c5876d 100644 --- a/examples/swank-server/lisp/eval.lisp +++ b/examples/swank-server/lisp/eval.lisp @@ -33,14 +33,13 @@ (if *prompt* (let ((pkg (if (zerop n) "QML-USER" (current-package-name))) (counter (princ-to-string (incf n)))) - (format t "~%~A [~A] ~A~%~A" + (format t "~A [~A]~%~A" pkg counter - (make-string (- 50 (length counter) (length pkg)) :initial-element #\-) str)) - (format t "~A~%~%~A" #.(make-string 50 :initial-element #\_) str)) + (format t "~%~%~A" str)) ;; run eval in its own thread, so UI will remain responsive - (update-output) + (update-output t) (when progress (show-progress-bar)) (qsingle-shot 50 (lambda () @@ -48,6 +47,7 @@ (mp:process-run-function "LQML REPL top-level" (lambda () (do-eval str)))))))))) +(defvar *color-text* "#c0c0c0") (defvar *color-values* "#80b0ff") (defvar *color-read-error* "orange") (defvar *color-error* "#ff8080") @@ -81,8 +81,7 @@ (defun eval-exited () (update-output) - (show-progress-bar nil) - (q> |contentX| ui:*flick-output* 0)) + (show-progress-bar nil)) (defun show-error (error color) (let ((e1 (prin1-to-string error)) @@ -96,32 +95,22 @@ ;;; output -(defun update-output () - (let ((chunk (get-output-stream-string *output-buffer*))) - (unless (x:empty-string chunk) - (let ((text (x:string-substitute "
" (string #\Newline) (qescape chunk)))) - ;; "insert" is cleaner with formatting than "append" - (q! |insert| ui:*repl-output* - (q< |length| ui:*repl-output*) - (format nil "
~A
" - (x:if-it (search "[LQML:err]" text) - (let ((error-text (subseq text x:it))) - (x:string-substitute (format nil "~A" - *color-error* - error-text) - error-text - text)) - text)))) - (q> |cursorPosition| ui:*repl-output* - (q< |length| ui:*repl-output*))))) +(defun update-output (&optional line) + (let ((text (get-output-stream-string *output-buffer*))) + (unless (x:empty-string text) + (let ((err (search "[LQML:err]" text))) + (qjs |appendText| ui:*repl-model* + (list :m-text (if err (subseq text err) text) + :m-color (if err *color-error* *color-text*) + :m-bold nil + :m-line line)))))) -(defun append-output (text &optional (color "#c0c0c0") bold) - (q! |append| ui:*repl-output* - (format nil "
~A~A~A
" - color - (if bold "" "") - (x:string-substitute "
" (string #\Newline) (qescape text)) - (if bold "
" "")))) +(defun append-output (text &optional (color *color-text*) bold) + (qjs |appendText| ui:*repl-model* + (list :m-text text + :m-color color + :m-bold bold + :m-line nil))) ;;; command history diff --git a/examples/swank-server/lisp/ui-vars.lisp b/examples/swank-server/lisp/ui-vars.lisp index cb076fb..20b81bf 100644 --- a/examples/swank-server/lisp/ui-vars.lisp +++ b/examples/swank-server/lisp/ui-vars.lisp @@ -6,7 +6,8 @@ #:*history-forward* #:*progress* #:*repl-input* - #:*repl-output*)) + #:*repl-output* + #:*repl-model*)) (in-package :ui) @@ -16,3 +17,4 @@ (defparameter *progress* "progress") (defparameter *repl-input* "repl_input") (defparameter *repl-output* "repl_output") +(defparameter *repl-model* "repl_model") diff --git a/examples/swank-server/qml/ext/Flickable2.qml b/examples/swank-server/qml/ext/Flickable2.qml deleted file mode 100644 index 0a643d5..0000000 --- a/examples/swank-server/qml/ext/Flickable2.qml +++ /dev/null @@ -1,16 +0,0 @@ -import QtQuick 2.15 - -Flickable { - clip: true - - function ensureVisible(r) { - if (contentX >= r.x) - contentX = r.x; - else if (contentX + width <= r.x + r.width) - contentX = r.x + r.width - width; - if (contentY >= r.y) - contentY = r.y; - else if (contentY + height <= r.y + r.height) - contentY = r.y + r.height - height; - } -} diff --git a/examples/swank-server/qml/ext/Repl.qml b/examples/swank-server/qml/ext/Repl.qml index 084ec66..6d9ffff 100644 --- a/examples/swank-server/qml/ext/Repl.qml +++ b/examples/swank-server/qml/ext/Repl.qml @@ -1,7 +1,6 @@ import QtQuick 2.15 import QtQuick.Controls 2.15 import Lisp 1.0 -import "." Item { id: repl @@ -34,25 +33,44 @@ Item { height: repl.parent.height / 4 color: "#101010" - Flickable2 { - id: flick - objectName: "flick_output" + ListView { + id: replOutput + objectName: "repl_output" anchors.fill: parent - contentWidth: output.paintedWidth - contentHeight: output.paintedHeight + contentWidth: parent.width * 4 + clip: true + model: replModel + flickableDirection: Flickable.HorizontalAndVerticalFlick - TextEdit { - id: output - objectName: "repl_output" - width: flick.width - height: flick.height - textMargin: 4 - textFormat: TextEdit.RichText - font.pixelSize: 16 - color: "#c0c0c0" - readOnly: true + delegate: Column { + Rectangle { + width: replOutput.contentWidth + height: 1 + color: "#707070" + visible: mLine + } - onCursorRectangleChanged: flick.ensureVisible(cursorRectangle) + Text { + x: 2 + padding: 2 + textFormat: Text.PlainText + font.family: fontHack.name + font.pixelSize: 16 + font.bold: mBold + text: mText + color: mColor + } + } + } + + ListModel { + id: replModel + objectName: "repl_model" + + function appendText(data) { + append(data) + replOutput.contentX = 0 + replOutput.positionViewAtEnd() } } } @@ -65,8 +83,8 @@ Item { objectName: "repl_input" width: repl.parent.width - 2 * back.width font.family: fontHack.name - font.bold: true font.pixelSize: 16 + font.bold: true color: "#c0c0c0" inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText focus: show.checked diff --git a/examples/swank-server/readme.md b/examples/swank-server/readme.md index f910c77..7515375 100644 --- a/examples/swank-server/readme.md +++ b/examples/swank-server/readme.md @@ -40,6 +40,3 @@ means: * install a fresh copy of Quicklisp on some desktop device, and copy over the whole directory `quicklisp` under `platforms/ios/assets/Library/` of this example - -* after installing the app on the iOS device, command `:q` will then simply - load `quicklisp/setup` from the locally installed version