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))))
(if (not (downloading-allowed-p wrapper-object))
(ui:notify (_ "Gemini document downloading aborted"))
(let ((compact-event (make-instance 'program-events:gemini-compact-lines-event
:download-iri (download-iri wrapper-object)
:priority
program-events:+maximum-event-priority+)))
(program-events:push-event compact-event)
(progn
(ui:notify (_ "Gemini document downloading completed"))
(setf (stream-status wrapper-object) :completed)))
;; (allow-downloading wrapper-object)

View File

@ -136,38 +136,41 @@
(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)
(let ((res ()))
(loop for line in lines do
(if (string-empty-p line)
(push nil res)
(loop
for fitted-line in
(flush-left-mono-text (split-words line)
(win-width-no-border object))
do
(push fitted-line res))))
(if (string-empty-p line)
(push nil res)
(loop
for fitted-line in
(flush-left-mono-text (split-words line)
(win-width-no-border window))
do
(push fitted-line res))))
(reverse res))))
(with-accessors ((source-text source-text)) object
(when hooks:*before-prepare-for-rendering-message*
(hooks:run-hook 'hooks:*before-prepare-for-rendering-message* object))
(let* ((lines (split-lines source-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)))))
(setf (rows object)
(mapcar (lambda (text-line)
(make-instance 'line
:normal-text text-line))
new-rows))
(when jump-to-first-row
(select-row object 0))
object))))
(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)))))
(mapcar (lambda (text-line)
(make-instance 'line
:normal-text text-line))
new-rows))))
(defmethod prepare-for-rendering ((object message-window) &key (jump-to-first-row t))
(with-accessors ((source-text source-text)) object
(when hooks:*before-prepare-for-rendering-message*
(hooks:run-hook 'hooks:*before-prepare-for-rendering-message* object))
(setf (rows 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
&key

View File

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

View File

@ -1028,10 +1028,16 @@
(let* ((win specials:*message-window*)
(window-metadata (message-window:metadata win)))
(if append-text
(progn
(message-window:append-source-text win rendered-text :prepare-for-rendering t)
(gemini-viewer:append-metadata-link window-metadata links)
(gemini-viewer:append-metadata-source window-metadata source))
(with-accessors ((rows message-window::rows)) win
(let ((new-rows (message-window:text->rendered-lines-rows win
rendered-text))
(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
(setf (message-window:source-text win) rendered-text)
(setf (gemini-viewer:gemini-metadata-source-file window-metadata) source)