1
0
Fork 0

- reverted method of rendering of text in message window to a

line-based one.

The old method that packed text got from gemini stream in single event
was ugly and blocked the UI.

This version  revert to a line  by line rendering but  it is optimized
and does not gets slow with the size of the text the window holds.
This commit is contained in:
cage 2021-03-09 11:32:09 +01:00
parent 6beb2e9bfc
commit b73f982408
4 changed files with 43 additions and 37 deletions

View File

@ -384,11 +384,7 @@
(return-from download-loop nil)))) (return-from download-loop nil))))
(if (not (downloading-allowed-p wrapper-object)) (if (not (downloading-allowed-p wrapper-object))
(ui:notify (_ "Gemini document downloading aborted")) (ui:notify (_ "Gemini document downloading aborted"))
(let ((compact-event (make-instance 'program-events:gemini-compact-lines-event (progn
:download-iri (download-iri wrapper-object)
:priority
program-events:+maximum-event-priority+)))
(program-events:push-event compact-event)
(ui:notify (_ "Gemini document downloading completed")) (ui:notify (_ "Gemini document downloading completed"))
(setf (stream-status wrapper-object) :completed))) (setf (stream-status wrapper-object) :completed)))
;; (allow-downloading wrapper-object) ;; (allow-downloading wrapper-object)

View File

@ -136,38 +136,41 @@
(defgeneric search-regex (object regex)) (defgeneric search-regex (object regex))
(defmethod prepare-for-rendering ((object message-window) &key (jump-to-first-row t)) (defun text->rendered-lines-rows (window text)
(flet ((fit-lines (lines) (flet ((fit-lines (lines)
(let ((res ())) (let ((res ()))
(loop for line in lines do (loop for line in lines do
(if (string-empty-p line) (if (string-empty-p line)
(push nil res) (push nil res)
(loop (loop
for fitted-line in for fitted-line in
(flush-left-mono-text (split-words line) (flush-left-mono-text (split-words line)
(win-width-no-border object)) (win-width-no-border window))
do do
(push fitted-line res)))) (push fitted-line res))))
(reverse res)))) (reverse res))))
(with-accessors ((source-text source-text)) object (let* ((lines (split-lines text))
(when hooks:*before-prepare-for-rendering-message* (fitted-lines (fit-lines lines))
(hooks:run-hook 'hooks:*before-prepare-for-rendering-message* object)) (color-re (swconf:color-regexps))
(let* ((lines (split-lines source-text)) (new-rows (loop for line in fitted-lines collect
(fitted-lines (fit-lines lines)) (let ((res line))
(color-re (swconf:color-regexps)) (loop for re in color-re do
(new-rows (loop for line in fitted-lines collect (setf res (colorize-line res re)))
(let ((res line)) (colorized-line->tui-string res)))))
(loop for re in color-re do (mapcar (lambda (text-line)
(setf res (colorize-line res re))) (make-instance 'line
(colorized-line->tui-string res))))) :normal-text text-line))
(setf (rows object) new-rows))))
(mapcar (lambda (text-line)
(make-instance 'line (defmethod prepare-for-rendering ((object message-window) &key (jump-to-first-row t))
:normal-text text-line)) (with-accessors ((source-text source-text)) object
new-rows)) (when hooks:*before-prepare-for-rendering-message*
(when jump-to-first-row (hooks:run-hook 'hooks:*before-prepare-for-rendering-message* object))
(select-row object 0)) (setf (rows object)
object)))) (text->rendered-lines-rows object source-text))
(when jump-to-first-row
(select-row object 0))
object))
(defmethod append-source-text ((object message-window) text (defmethod append-source-text ((object message-window) text
&key &key

View File

@ -1905,6 +1905,7 @@
:gemini-window-p :gemini-window-p
:display-gemini-text-p :display-gemini-text-p
:display-chat-p :display-chat-p
:text->rendered-lines-rows
:prepare-for-display-status-mode :prepare-for-display-status-mode
:append-source-text :append-source-text
:scroll-down :scroll-down

View File

@ -1028,10 +1028,16 @@
(let* ((win specials:*message-window*) (let* ((win specials:*message-window*)
(window-metadata (message-window:metadata win))) (window-metadata (message-window:metadata win)))
(if append-text (if append-text
(progn (with-accessors ((rows message-window::rows)) win
(message-window:append-source-text win rendered-text :prepare-for-rendering t) (let ((new-rows (message-window:text->rendered-lines-rows win
(gemini-viewer:append-metadata-link window-metadata links) rendered-text))
(gemini-viewer:append-metadata-source window-metadata source)) (reversed-rows (reverse rows)))
(message-window:append-source-text win rendered-text :prepare-for-rendering nil)
(gemini-viewer:append-metadata-link window-metadata links)
(gemini-viewer:append-metadata-source window-metadata source)
(loop for new-row in new-rows do
(push new-row reversed-rows))
(setf rows (reverse reversed-rows))))
(progn (progn
(setf (message-window:source-text win) rendered-text) (setf (message-window:source-text win) rendered-text)
(setf (gemini-viewer:gemini-metadata-source-file window-metadata) source) (setf (gemini-viewer:gemini-metadata-source-file window-metadata) source)