1
0
Fork 0

- [GUI] fixed rendering of gemtext's slices

Rendering was working only when the  whole gemtext was received in a
  single block  over the net.  If not  the rendering code  printed the
  text lines out of order or even replicating the first lines.
This commit is contained in:
cage 2023-06-30 14:45:54 +02:00
parent 3d642b4531
commit 6335419058
1 changed files with 41 additions and 42 deletions

View File

@ -136,7 +136,7 @@
(funcall process-function stream-wrapper last-lines-fetched)) (funcall process-function stream-wrapper last-lines-fetched))
(when (not (or (funcall aborting-function) (when (not (or (funcall aborting-function)
(and (stream-exausted-p) (and (stream-exausted-p)
next-start-fetching))) (<= next-start-fetching 0))))
(loop-fetch (+ last-lines-fetched-count (loop-fetch (+ last-lines-fetched-count
next-start-fetching)))))))) next-start-fetching))))))))
(loop-fetch) (loop-fetch)
@ -561,7 +561,7 @@
(incf skip-index (length emoji-code-points))) (incf skip-index (length emoji-code-points)))
(incf skip-index))))))) (incf skip-index)))))))
(defun render-ir-lines (request-iri main-window) (defun render-ir-lines (request-iri main-window &key (starting-index 0))
(with-accessors ((ir-lines ir-lines) (with-accessors ((ir-lines ir-lines)
(ir-rendered-lines ir-rendered-lines) (ir-rendered-lines ir-rendered-lines)
(gemtext-font-scaling gemtext-font-scaling) (gemtext-font-scaling gemtext-font-scaling)
@ -614,17 +614,17 @@
(gui-conf:gemini-quote-justification)) (gui-conf:gemini-quote-justification))
((:pre :pre-end :as-is) ((:pre :pre-end :as-is)
(gui-conf:gemini-preformatted-text-justification)))) (gui-conf:gemini-preformatted-text-justification))))
(render-link (line line-number) (render-link (line link-rendered-label line-number)
(multiple-value-bind (link-bg link-fg) (multiple-value-bind (link-bg link-fg)
(gui-conf:gemini-link-colors) (gui-conf:gemini-link-colors)
(let ((link-font (scale-font (gui-conf:gemini-link-font-configuration) (let ((link-font (scale-font (gui-conf:gemini-link-font-configuration)
gemtext-font-scaling))) gemtext-font-scaling)))
(multiple-value-bind (link-rendered-label link-name link-value) (multiple-value-bind (x link-name link-value)
(linkify line) (linkify line)
(declare (ignore x))
(let ((target-iri (absolutize-link request-iri link-value)) (let ((target-iri (absolutize-link request-iri link-value))
(new-text-line-start `(:line ,line-number :char 0))) (new-text-line-start `(:line ,line-number :char 0)))
(vector-push-extend link-rendered-label ir-rendered-lines) (gui:append-text gemtext-widget link-rendered-label)
(gui:append-text gemtext-widget (a:last-elt ir-rendered-lines))
(let ((tag-link (gui:make-link-button gemtext-widget (let ((tag-link (gui:make-link-button gemtext-widget
new-text-line-start new-text-line-start
`(- :end 1 :chars) `(- :end 1 :chars)
@ -667,12 +667,10 @@
;; does not works because of a TK bug ;; does not works because of a TK bug
;;(colorize-emoji main-window (1- line-number)) ;;(colorize-emoji main-window (1- line-number))
(gui:tag-lower gemtext-widget tag)))))) (gui:tag-lower gemtext-widget tag))))))
(loop with render-line-count = 0 (loop with render-line-count = starting-index
with starting-pre-block-line = -1
with ending-pre-block-line = -1
with current-pre-block-alt-text = nil with current-pre-block-alt-text = nil
for rendered-line across ir-rendered-lines for rendered-line across (subseq ir-rendered-lines starting-index)
for ir-line across ir-lines for ir-line across (subseq ir-lines starting-index)
do do
(let ((type (ir-type ir-line))) (let ((type (ir-type ir-line)))
(ecase (format-keyword type) (ecase (format-keyword type)
@ -711,19 +709,17 @@
(render-line :quote rendered-line render-line-count)) (render-line :quote rendered-line render-line-count))
(:pre (:pre
(incf render-line-count) (incf render-line-count)
(setf starting-pre-block-line (1+ render-line-count))
(setf current-pre-block-alt-text (ir-pre-alt-text ir-line)) (setf current-pre-block-alt-text (ir-pre-alt-text ir-line))
(render-line :pre (render-line :pre
rendered-line rendered-line
render-line-count render-line-count
:wrap :none)) :wrap :none))
(:pre-end (:pre-end
(setf ending-pre-block-line (1+ render-line-count))
(incf render-line-count) (incf render-line-count)
(render-line :pre-end rendered-line render-line-count)) (render-line :pre-end rendered-line render-line-count))
(:a (:a
(incf render-line-count) (incf render-line-count)
(render-link ir-line render-line-count)))))))) (render-link ir-line rendered-line render-line-count))))))))
(defun collect-ir-lines (request-iri main-window lines) (defun collect-ir-lines (request-iri main-window lines)
(with-accessors ((ir-lines ir-lines) (with-accessors ((ir-lines ir-lines)
@ -735,33 +731,36 @@
(vector-push-extend raw-line ir-rendered-lines))) (vector-push-extend raw-line ir-rendered-lines)))
(collect-link (line) (collect-link (line)
(vector-push-extend (linkify line) ir-rendered-lines))) (vector-push-extend (linkify line) ir-rendered-lines)))
(loop for line in lines do (let ((starting-index (if (not (vector-empty-p ir-lines))
(vector-push-extend line ir-lines) 0
(let ((type (ir-type line))) (length ir-lines))))
(ecase (format-keyword type) (loop for line in lines do
(:vertical-space (vector-push-extend line ir-lines)
(vector-push-extend (format nil "") ir-rendered-lines)) (let ((type (ir-type line)))
(:as-is (ecase (format-keyword type)
(vector-push-extend (ir-line line) ir-rendered-lines)) (:vertical-space
(:text (vector-push-extend (format nil "") ir-rendered-lines))
(vector-push-extend (ir-line line) ir-rendered-lines)) (:as-is
(:h1 (vector-push-extend (ir-line line) ir-rendered-lines))
(push-prefixed (gui-conf:gemini-h1-prefix) line)) (:text
(:h2 (vector-push-extend (ir-line line) ir-rendered-lines))
(push-prefixed (gui-conf:gemini-h1-prefix) line)) (:h1
(:h3 (push-prefixed (gui-conf:gemini-h1-prefix) line))
(push-prefixed (gui-conf:gemini-h1-prefix) line)) (:h2
(:li (push-prefixed (gui-conf:gemini-h1-prefix) line))
(push-prefixed (gui-conf:gemini-bullet-prefix) line)) (:h3
(:quote (push-prefixed (gui-conf:gemini-h1-prefix) line))
(push-prefixed (gui-conf:gemini-quote-prefix) line)) (:li
(:pre (push-prefixed (gui-conf:gemini-bullet-prefix) line))
(vector-push-extend (format nil "") ir-rendered-lines)) (:quote
(:pre-end (push-prefixed (gui-conf:gemini-quote-prefix) line))
(vector-push-extend (format nil "") ir-rendered-lines)) (:pre
(:a (vector-push-extend (format nil "") ir-rendered-lines))
(collect-link line))))) (:pre-end
(render-ir-lines request-iri main-window)))) (vector-push-extend (format nil "") ir-rendered-lines))
(:a
(collect-link line)))))
(render-ir-lines request-iri main-window :starting-index starting-index)))))
(defun displace-gemini-response (response) (defun displace-gemini-response (response)
(values (getf response :status) (values (getf response :status)
@ -973,7 +972,7 @@
(initialize-ir-lines main-window) (initialize-ir-lines main-window)
(start-streaming-thread main-window (start-streaming-thread main-window
iri iri
:use-cache nil :use-cache t
:status status :status status
:process-function :process-function
(lambda (stream-wrapper lines) (lambda (stream-wrapper lines)