1
0
Fork 0

- [GUI] removed inefficent code to render the gemtext;

- added dummy function as link callback.
This commit is contained in:
cage 2023-02-28 18:48:34 +01:00
parent 03ea768033
commit 283824f74a
1 changed files with 41 additions and 18 deletions

View File

@ -190,6 +190,13 @@
(gen-ir-access href) (gen-ir-access href)
(gen-ir-access pre-alt-text)
(defun link-click-mouse-1-callback (link-value main-window &key (use-cache t))
(declare (ignore link-value))
(lambda ()
(funcall (start-stream-iri-clsr main-window :use-cache use-cache))))
(defun collect-ir-lines (main-window lines) (defun collect-ir-lines (main-window lines)
(with-accessors ((ir-lines ir-lines) (with-accessors ((ir-lines ir-lines)
(ir-rendered-lines ir-rendered-lines) (ir-rendered-lines ir-rendered-lines)
@ -249,7 +256,7 @@
(gui-conf:gemini-quote-justification)) (gui-conf:gemini-quote-justification))
(:pre (:pre
(gui-conf:gemini-preformatted-text-justification)))) (gui-conf:gemini-preformatted-text-justification))))
(linkify (line) (linkify (line 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 (gui-conf:gemini-link-font-configuration)) (let* ((link-font (gui-conf:gemini-link-font-configuration))
@ -272,7 +279,7 @@
(t (t
(format nil "~a~a" prefix-other link-name)))))) (format nil "~a~a" prefix-other link-name))))))
(vector-push-extend link-text ir-rendered-lines) (vector-push-extend link-text ir-rendered-lines)
(let ((new-text-line-start (gui:raw-coordinates gemtext-widget))) (let ((new-text-line-start `(:line ,line-number :char 0)))
(gui:append-text gemtext-widget (a:last-elt ir-rendered-lines)) (gui:append-text gemtext-widget (a:last-elt ir-rendered-lines))
(gui:make-link-button gemtext-widget (gui:make-link-button gemtext-widget
new-text-line-start new-text-line-start
@ -280,19 +287,19 @@
link-font link-font
link-fg link-fg
link-bg link-bg
(lambda () t)) (link-click-mouse-1-callback link-value main-window))
(gui:append-line gemtext-widget ""))))) (gui:append-line gemtext-widget "")))))
(render-line (key text) (render-line (key text line-number)
(let ((font (key->font key)) (let ((font (key->font key))
(justification (key->justification key)) (justification (key->justification key))
(new-text-line-start (gui:raw-coordinates gemtext-widget))) (start-index `(:line ,line-number :char 0)))
(gui:append-text gemtext-widget text) (gui:append-text gemtext-widget text)
(if font (if font
(multiple-value-bind (background foreground) (multiple-value-bind (background foreground)
(key->colors key) (key->colors key)
(let ((tag (gui:tag-create gemtext-widget (let ((tag (gui:tag-create gemtext-widget
(gui::create-tag-name) (gui::create-tag-name)
new-text-line-start start-index
(gui:make-indices-end)))) (gui:make-indices-end))))
(gui:tag-configure gemtext-widget (gui:tag-configure gemtext-widget
tag tag
@ -305,42 +312,58 @@
(progn (progn
(gui:append-line gemtext-widget "") (gui:append-line gemtext-widget "")
nil))))) nil)))))
(loop for line in lines do (loop with render-line-count = 0
with starting-pre-block-line = -1
with ending-pre-block-line = -1
with current-pre-block-alt-text = nil
for line in lines do
(vector-push-extend line ir-lines) (vector-push-extend line ir-lines)
(let ((type (ir-type line))) (let ((type (ir-type line)))
(ecase (format-keyword type) (ecase (format-keyword type)
(:vertical-space (:vertical-space
(vector-push-extend (format nil "") ir-rendered-lines) (vector-push-extend (format nil "") ir-rendered-lines)
(render-line :vertical-space (a:last-elt ir-rendered-lines))) (incf render-line-count)
(render-line :vertical-space (a:last-elt ir-rendered-lines) render-line-count))
(:as-is (:as-is
(vector-push-extend (ir-line line) ir-rendered-lines) (vector-push-extend (ir-line line) ir-rendered-lines)
(render-line :as-is (a:last-elt ir-rendered-lines))) (incf render-line-count)
(render-line :as-is (a:last-elt ir-rendered-lines) render-line-count))
(:text (:text
(vector-push-extend (ir-line line) ir-rendered-lines) (vector-push-extend (ir-line line) ir-rendered-lines)
(render-line :text (a:last-elt ir-rendered-lines))) (incf render-line-count)
(render-line :text (a:last-elt ir-rendered-lines) render-line-count))
(:h1 (:h1
(push-prefixed (gui-conf:gemini-h1-prefix) line) (push-prefixed (gui-conf:gemini-h1-prefix) line)
(render-line :h1 (a:last-elt ir-rendered-lines))) (incf render-line-count)
(render-line :h1 (a:last-elt ir-rendered-lines) render-line-count))
(:h2 (:h2
(push-prefixed (gui-conf:gemini-h1-prefix) line) (push-prefixed (gui-conf:gemini-h1-prefix) line)
(render-line :h2 (a:last-elt ir-rendered-lines))) (incf render-line-count)
(render-line :h2 (a:last-elt ir-rendered-lines) render-line-count))
(:h3 (:h3
(push-prefixed (gui-conf:gemini-h1-prefix) line) (push-prefixed (gui-conf:gemini-h1-prefix) line)
(render-line :h3 (a:last-elt ir-rendered-lines))) (incf render-line-count)
(render-line :h3 (a:last-elt ir-rendered-lines) render-line-count))
(:li (:li
(push-prefixed (gui-conf:gemini-bullet-prefix) line) (push-prefixed (gui-conf:gemini-bullet-prefix) line)
(render-line :li (a:last-elt ir-rendered-lines))) (incf render-line-count)
(render-line :li (a:last-elt ir-rendered-lines) render-line-count))
(:quote (:quote
(push-prefixed (gui-conf:gemini-quote-prefix) line) (push-prefixed (gui-conf:gemini-quote-prefix) line)
(render-line :quote (a:last-elt ir-rendered-lines))) (incf render-line-count)
(render-line :quote (a:last-elt ir-rendered-lines) render-line-count))
(:pre (:pre
(vector-push-extend (format nil "") ir-rendered-lines) (vector-push-extend (format nil "") ir-rendered-lines)
(render-line :pre (a:last-elt ir-rendered-lines))) (setf starting-pre-block-line (1+ render-line-count))
(setf current-pre-block-alt-text (ir-pre-alt-text line))
(render-line :pre (a:last-elt ir-rendered-lines) render-line-count))
(:pre-end (:pre-end
(vector-push-extend (format nil "") ir-rendered-lines) (vector-push-extend (format nil "") ir-rendered-lines)
(render-line :pre-end (a:last-elt ir-rendered-lines))) (setf ending-pre-block-line (1+ render-line-count))
(render-line :pre-end (a:last-elt ir-rendered-lines) render-line-count))
(:a (:a
(linkify line)))))))) (incf render-line-count)
(linkify line render-line-count))))))))
(defun displace-gemini-response (response) (defun displace-gemini-response (response)
(values (getf response :status) (values (getf response :status)