revision of example 'swank-server'

This commit is contained in:
pls.153 2022-03-02 23:32:42 +01:00
parent f37a94e108
commit f0b3bfc16d
5 changed files with 59 additions and 69 deletions

View file

@ -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 "<br>" (string #\Newline) (qescape chunk))))
;; "insert" is cleaner with formatting than "append"
(q! |insert| ui:*repl-output*
(q< |length| ui:*repl-output*)
(format nil "<pre><font face='Hack'>~A</font></pre>"
(x:if-it (search "[LQML:err]" text)
(let ((error-text (subseq text x:it)))
(x:string-substitute (format nil "<font color='~A'>~A</font>"
*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 "<pre><font face='Hack' color='~A'>~A~A~A</font></pre>"
color
(if bold "<b>" "")
(x:string-substitute "<br>" (string #\Newline) (qescape text))
(if bold "</b>" ""))))
(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

View file

@ -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")

View file

@ -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;
}
}

View file

@ -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

View file

@ -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