diff --git a/src/gui/client/main-window.lisp b/src/gui/client/main-window.lisp index ca3b5e4..e655b6d 100644 --- a/src/gui/client/main-window.lisp +++ b/src/gui/client/main-window.lisp @@ -263,7 +263,6 @@ (gui:grid main-frame 0 0 :sticky :nswe) (gui-goodies:gui-resize-grid-all gui:*tk*))))) - ;; (let ((test-iri "gemini://omg.pebcak.club/")) ;; (slurp-gemini-stream test-iri ;; :process-function (lambda (lines) (misc:dbg "lines ~a" lines)))))))) diff --git a/src/gui/server/public-api-gemini-stream.lisp b/src/gui/server/public-api-gemini-stream.lisp index 755a5ab..bdbfa0e 100644 --- a/src/gui/server/public-api-gemini-stream.lisp +++ b/src/gui/server/public-api-gemini-stream.lisp @@ -17,9 +17,29 @@ (in-package :json-rpc-communication) +(defclass iri-complete-response (box) ()) + +(defmethod yason:encode ((object iri-complete-response) &optional (stream *standard-output*)) + (let ((json:*symbol-encoder* #'json:encode-symbol-as-lowercase) + (yason:*list-encoder* #'yason:encode-plist) + (json:*symbol-key-encoder* #'json:encode-symbol-as-lowercase)) + (yason:with-output (stream) + (yason:with-object () + (yason:with-object-element (:matches) + (yason:encode-array-elements (list->array (getf (unbox object) :matches)))) + (yason:with-object-element (:indices) + (json:with-array () + (loop for indices-group in (getf (unbox object) :indices) do + (yason:encode-array-elements (list->array (remove-if #'null indices-group)))))))))) + (defun complete-net-address (hint) (let ((prompt (ui:open-url-prompt))) - (funcall (complete:make-complete-gemini-iri-fn prompt) hint))) + (multiple-value-bind (matched-strings x indices) + (funcall (complete:make-complete-gemini-iri-fn prompt) hint) + (declare (ignore x)) + (make-instance 'iri-complete-response + :contents (list :matches matched-strings + :indices indices))))) (defun request-success-dispatched-fn (status code-description meta response socket iri parsed-iri) (declare (ignore iri))