From 82de38f89173e20c38d654afb422f3e717fdc502 Mon Sep 17 00:00:00 2001 From: cage Date: Fri, 17 Mar 2023 12:27:46 +0100 Subject: [PATCH] - [GUI] fixed test for checking if a stream is exhausted; - [RPC] force a maximum width for the TOC entry. --- src/gui/client/main-window.lisp | 33 ++++++++++---------- src/gui/server/public-api-gemini-stream.lisp | 9 +++--- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/gui/client/main-window.lisp b/src/gui/client/main-window.lisp index 7f2b464..580c8c0 100644 --- a/src/gui/client/main-window.lisp +++ b/src/gui/client/main-window.lisp @@ -118,24 +118,25 @@ (aborting-function (constantly nil))) (enqueue-request-notify-error :gemini-request 1 iri use-cache) (labels ((stream-exausted-p () - (let ((status-completed (enqueue-request-notify-error :gemini-stream-completed-p - 1 - iri))) - + (let ((status-completed (cev:enqueue-request-and-wait-results :gemini-stream-completed-p + 1 + ev:+maximum-event-priority+ + iri))) status-completed)) (loop-fetch (&optional (last-lines-fetched-count 0)) - (when (not (or (funcall aborting-function) - (stream-exausted-p))) - (ev:with-enqueued-process-and-unblock () - (with-notify-errors - (let* ((last-lines-fetched (comm:make-request :gemini-stream-parsed-line-slice - 1 - iri - last-lines-fetched-count - nil)) - (next-start-fetching (length last-lines-fetched))) - (when last-lines-fetched - (funcall process-function stream-wrapper last-lines-fetched)) + (ev:with-enqueued-process-and-unblock () + (with-notify-errors + (let* ((last-lines-fetched (comm:make-request :gemini-stream-parsed-line-slice + 1 + iri + last-lines-fetched-count + nil)) + (next-start-fetching (length last-lines-fetched))) + (when last-lines-fetched + (funcall process-function stream-wrapper last-lines-fetched)) + (when (not (or (funcall aborting-function) + (and (stream-exausted-p) + next-start-fetching))) (loop-fetch (+ last-lines-fetched-count next-start-fetching)))))))) (loop-fetch))) diff --git a/src/gui/server/public-api-gemini-stream.lisp b/src/gui/server/public-api-gemini-stream.lisp index 969943c..41132a1 100644 --- a/src/gui/server/public-api-gemini-stream.lisp +++ b/src/gui/server/public-api-gemini-stream.lisp @@ -408,7 +408,7 @@ (let ((status (gemini-stream-status iri))) (eq status :completed))) -(defun build-gemini-toc (iri) +(defun build-gemini-toc (iri width) (a:when-let* ((ordered-headers-tag '(:h1 :h2 :h3)) (stream-wrapper (gw:find-db-stream-url iri)) (parsed-lines (gw:parsed-lines stream-wrapper)) @@ -464,7 +464,7 @@ for text in toc-entries-text collect (list :header-group-id (getf toc-entry :group-id) - :text text)) + :text (ellipsize text width))) toc))))) (defclass gemini-toc (box) ()) @@ -478,8 +478,9 @@ (loop for element in list do (json:encode-array-element element)))))) -(defun gemini-table-of-contents (iri) - (make-instance 'gemini-toc :contents (build-gemini-toc iri))) +(defun gemini-table-of-contents (iri width) + (make-instance 'gemini-toc + :contents (build-gemini-toc iri width))) (defmethod yason:encode ((object gemini-toc) &optional (stream *standard-output*)) (encode-flat-array-of-plists (unbox object) stream))