From eaf23afb58faaf8e2b0e599b8458662d6d679759 Mon Sep 17 00:00:00 2001 From: cage Date: Mon, 5 Apr 2021 14:47:57 +0200 Subject: [PATCH] - [gemini] fixed rendering of quoted lines; - [gemini] do not set, always append, source text when refreshing a gemini window. --- src/gemini/gemini-parser.lisp | 21 ++++++++++++++++----- src/gemini/package.lisp | 4 +++- src/message-window.lisp | 28 ++++++++++++++++++++-------- src/program-events.lisp | 6 +++--- 4 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/gemini/gemini-parser.lisp b/src/gemini/gemini-parser.lisp index aee2bd2..b69ee62 100644 --- a/src/gemini/gemini-parser.lisp +++ b/src/gemini/gemini-parser.lisp @@ -336,6 +336,16 @@ (defun make-pre-end () (make-instance 'pre-end)) +(defclass quoted-lines () + ((lines + :initform () + :initarg :lines + :accessor lines))) + +(defun make-quoted-lines (text-lines) + (make-instance 'quoted-lines + :lines (split-lines text-lines))) + (defun sexp->text-rows (parsed-gemini theme) (labels ((header-prefix (prefix header) (strcat prefix header)) @@ -361,11 +371,12 @@ (format nil "~a~a~%" (link-prefix-gemini theme) link-name) (format nil "~a~a~%" (link-prefix-other theme) link-name))) (fit-quote-lines (line win-width) - (join-with-strings (mapcar (lambda (a) (strcat (quote-prefix theme) a)) - (flush-left-mono-text (split-words line) - (- win-width - (length (quote-prefix theme))))) - (format nil "~%"))) + (let* ((justified (flush-left-mono-text (split-words line) + (- win-width + (length (quote-prefix theme))))) + (lines (mapcar (lambda (a) (strcat (quote-prefix theme) a)) + justified))) + (make-quoted-lines (join-with-strings lines (format nil "~%"))))) (pre-alt-text (node) (trim (html-utils:attribute-value (html-utils:find-attribute :alt node))))) (let ((win-width (message-window:viewport-width (viewport theme)))) diff --git a/src/gemini/package.lisp b/src/gemini/package.lisp index 7a4cd48..7a1e09f 100644 --- a/src/gemini/package.lisp +++ b/src/gemini/package.lisp @@ -65,8 +65,10 @@ :quote-prefix :bullet-prefix :pre-start - :pre-end :value + :pre-end + :quoted-lines + :lines :sexp->text-rows :sexp->text :parse-gemini-response-header diff --git a/src/message-window.lisp b/src/message-window.lisp index 37ea1b3..7546452 100644 --- a/src/message-window.lisp +++ b/src/message-window.lisp @@ -147,13 +147,30 @@ :normal-text "")) (defmethod text->rendered-lines-rows (window (text list)) - (flatten (loop for i in text collect - (text->rendered-lines-rows window i)))) + (flatten (loop for i in text + collect + (text->rendered-lines-rows window i)))) (defmethod text->rendered-lines-rows (window (text complex-string)) (make-instance 'line :normal-text text)) +(defun colorize-lines (lines) + (let ((color-re (swconf:color-regexps))) + (loop for line in lines + collect + (let ((res line)) + (loop for re in color-re do + (setf res (colorize-line res re))) + (colorized-line->tui-string res))))) + +(defmethod text->rendered-lines-rows (window (text gemini-parser:quoted-lines)) + (let ((colorized-lines (colorize-lines (gemini-parser:lines text)))) + (loop for i in colorized-lines + collect + (make-instance 'line + :normal-text i)))) + (defmethod text->rendered-lines-rows (window (text string)) (labels ((fit-lines (lines) (let ((res ())) @@ -172,12 +189,7 @@ :normal-text nil) (let* ((lines (split-lines text)) (fitted-lines (fit-lines lines)) - (color-re (swconf:color-regexps)) - (new-rows (loop for line in fitted-lines collect - (let ((res line)) - (loop for re in color-re do - (setf res (colorize-line res re))) - (colorized-line->tui-string res))))) + (new-rows (colorize-lines fitted-lines))) (mapcar (lambda (text-line) (make-instance 'line :normal-text text-line)) diff --git a/src/program-events.lisp b/src/program-events.lisp index d51805b..62c4f12 100644 --- a/src/program-events.lisp +++ b/src/program-events.lisp @@ -1063,8 +1063,8 @@ nil parent-dir :comes-from-local-file t)) - (ir-text (gemini-parser:sexp->text-rows parsed - gemini-client:*gemini-page-theme*)) + (ir-text (gemini-parser:sexp->text-rows parsed + gemini-client:*gemini-page-theme*)) (flat-text (gemini-parser:sexp->text parsed gemini-client:*gemini-page-theme*))) (gemini-viewer:maybe-initialize-metadata window) @@ -1114,7 +1114,7 @@ (loop for new-row in new-rows do (push new-row reversed-rows)) (setf rows (reverse reversed-rows)) - (setf (message-window:source-text win) rendered-text) + (message-window:append-source-text win rendered-text :prepare-for-rendering nil) (setf (gemini-viewer:gemini-metadata-source-file window-metadata) source) (setf (gemini-viewer:gemini-metadata-links window-metadata) links))))))