diff --git a/etc/init.lisp b/etc/init.lisp index daa4152..f88505b 100644 --- a/etc/init.lisp +++ b/etc/init.lisp @@ -137,8 +137,6 @@ ;; global keymap -(define-key "M-k >" #'kami-open-url) - (define-key "q" #'quit) ; here we are calling the custom ; function defined above (define-key "C-a" #'show-about-window) @@ -155,7 +153,7 @@ (define-key "!" #'gemini-search) -(define-key ">" #'open-gemini-address) +(define-key ">" #'open-net-address) (define-key "M-c" #'open-chats-list-window) diff --git a/src/kami/client.lisp b/src/kami/client.lisp index ed02567..e84ee04 100644 --- a/src/kami/client.lisp +++ b/src/kami/client.lisp @@ -1,5 +1,7 @@ (in-package :kami) +(a:define-constant +kami-scheme+ "np" :test #'string=) + (a:define-constant +download-buffer+ (expt 2 24) :test #'=) (a:define-constant +octect-type+ '(unsigned-byte 8) :test #'equalp) diff --git a/src/kami/package.lisp b/src/kami/package.lisp index a0dc62f..ed06d88 100644 --- a/src/kami/package.lisp +++ b/src/kami/package.lisp @@ -8,5 +8,6 @@ (:local-nicknames (:9p :purgatory) (:a :alexandria)) (:export + :+kami-scheme+ :generate-filesystem-window-handlers :iri->filesystem-window-handlers)) diff --git a/src/open-message-link-window.lisp b/src/open-message-link-window.lisp index c05bd9b..34afd56 100644 --- a/src/open-message-link-window.lisp +++ b/src/open-message-link-window.lisp @@ -80,7 +80,7 @@ (ui:close-open-message-link-window)) (cond ((string= gemini-constants:+gemini-scheme+ scheme) - (db:insert-in-history (ui:gemini-open-url-prompt) url) + (db:insert-in-history (ui:open-url-prompt) url) (db:gemlog-mark-as-seen url) (gemini-viewer:ensure-just-one-stream-rendering) (gemini-viewer:load-gemini-url url diff --git a/src/package.lisp b/src/package.lisp index 8073310..bda0ee2 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -2740,7 +2740,8 @@ :chat-create-new :chat-list-go-up :chat-list-go-down - :gemini-open-url-prompt + :open-url-prompt + :open-net-address :open-gemini-address :gemini-history-back :gemini-view-source @@ -2805,7 +2806,7 @@ :load-script-file :view-user-avatar :open-file-explorer - :kami-open-url + :open-kami-address :file-explorer-expand-path :file-explorer-close-path :file-explorer-rename-path diff --git a/src/ui-goodies.lisp b/src/ui-goodies.lisp index 7c75379..e13049a 100644 --- a/src/ui-goodies.lisp +++ b/src/ui-goodies.lisp @@ -1895,23 +1895,30 @@ mot recent updated to least recent" ;;;; gemini -(defun gemini-open-url-prompt () +(defun open-url-prompt () "This is used when opening gemini link too, see: open-message-link-window:open-message-link" - (_ "Open Gemini url: ")) + (_ "Open url: ")) -(defun open-gemini-address () - "Ask for a gemini address and try to load it" +(defun open-net-address () + "Ask for an internet address and try to load it. +Currently the only recognized protocols are gemini and kami." (flet ((on-input-complete (url) - (gemini-viewer:load-gemini-url (trim-blanks url) - :use-cached-file-if-exists t - :priority program-events:+maximum-event-priority+))) - - (let ((prompt (gemini-open-url-prompt))) + (let ((trimmed-url (trim-blanks url))) + (if (text-utils:string-starts-with-p kami:+kami-scheme+ trimmed-url) + (open-kami-address trimmed-url) + (open-gemini-address trimmed-url))))) + (let ((prompt (open-url-prompt))) (ask-string-input #'on-input-complete :prompt prompt :complete-fn (complete:make-complete-gemini-iri-fn prompt))))) + +(defun open-gemini-address (url) + (gemini-viewer:load-gemini-url url + :use-cached-file-if-exists t + :priority program-events:+maximum-event-priority+)) + (defun gemini-history-back () "Reopen a previous visited gemini address" (push-event (make-instance 'gemini-back-event))) @@ -2208,8 +2215,8 @@ gemini page the program is rendering." :prompt (format nil (_ "Insert certificate key file: ")) :complete-fn #'complete:directory-complete))) (on-cert-key-path-input-complete (key-path) - (let ((prompt-history (gemini-open-url-prompt)) - (prompt (_ "Insert the gemini IRI where where credential are valid: "))) + (let ((prompt-history (open-url-prompt)) + (prompt (_ "Insert the gemini address where where credential are valid: "))) (when (file-valid-p key-path) (setf cert-key-file key-path) (ui:ask-string-input #'on-valid-uri-complete @@ -2294,7 +2301,7 @@ gemini page the program is rendering." (push-event event))) (defun generate-latest-visited-url () - (let ((history (remove-duplicates (db:history-prompt->values (gemini-open-url-prompt)) + (let ((history (remove-duplicates (db:history-prompt->values (open-url-prompt)) :test #'string=))) (with-output-to-string (stream) (format stream (gemini-parser:geminize-h1 (_ "Latest visited addresses~2%"))) @@ -2420,33 +2427,25 @@ printed, on the main window." (filesystem-tree-window:init actual-root) (focus-to-filesystem-explorer-window)))) -(defun kami-open-url-prompt () - (_ "Open kami url: ")) - -(defun kami-open-url () - (flet ((on-input-complete (url) - (with-enqueued-process () - (tui:with-notify-errors - (let ((handlers (kami:iri->filesystem-window-handlers url))) - (if handlers - (let* ((path (uri:path (iri:iri-parse url))) - (path-to-dir-p (fs:path-referencing-dir-p path)) - (init-path (if path-to-dir-p - path - (fs:parent-dir-path path)))) - (filesystem-tree-window:init init-path handlers) - (if path-to-dir-p - (focus-to-filesystem-explorer-window) - (progn - (%file-explorer-download-path path) - (file-explorer-close-path)))) - (error-message (format nil - (_ "~s is not a valid kami address") - url)))))))) - (let ((prompt (kami-open-url-prompt))) - (ask-string-input #'on-input-complete - :prompt prompt - :complete-fn (complete:make-complete-gemini-iri-fn prompt))))) +(defun open-kami-address (url) + (with-enqueued-process () + (tui:with-notify-errors + (let ((handlers (kami:iri->filesystem-window-handlers url))) + (if handlers + (let* ((path (uri:path (iri:iri-parse url))) + (path-to-dir-p (fs:path-referencing-dir-p path)) + (init-path (if path-to-dir-p + path + (fs:parent-dir-path path)))) + (filesystem-tree-window:init init-path handlers) + (if path-to-dir-p + (focus-to-filesystem-explorer-window) + (progn + (%file-explorer-download-path path) + (file-explorer-close-path)))) + (error-message (format nil + (_ "~s is not a valid kami address") + url))))))) (defun file-explorer-expand-path () (when-let* ((win *filesystem-explorer-window*)