1
0
Fork 0

- [gemini] fixed rendering of quoted lines;

- [gemini] do not set, always append, source text when refreshing a gemini window.
This commit is contained in:
cage 2021-04-05 14:47:57 +02:00
parent fac77297e8
commit eaf23afb58
4 changed files with 42 additions and 17 deletions

View File

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

View File

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

View File

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

View File

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