'((t :inherit font-lock-constant-face))
"Face used for Spartan type directory records.")
+(defface elpher-spartan-post
+ '((t :inherit font-lock-string-face))
+ "Face used for Spartan type directory records.")
+
(defface elpher-other-url
'((t :inherit font-lock-comment-face))
"Face used for other URL type links records.")
the URL library.)"
(url-port address))
+(defun elpher-address-path-and-query (address)
+ "Retrieve path and query portion of ADDRESS as a pair."
+ (let ((path-and-query (url-path-and-query address)))
+ (cons (car path-and-query)
+ (url-unhex-string (cdr path-and-query)))))
+
(defun elpher-gopher-address-selector (address)
"Retrieve gopher selector from ADDRESS object."
(if (member (url-filename address) '("" "/"))
(defun elpher-gemini-get-link-display-string (link-line)
"Extract the display string portion of LINK-LINE, a gemini map file link line.
Return nil if this portion is not provided."
- (let* ((rest (string-trim (elt (split-string link-line "=>") 1)))
+ (let* ((rest (string-trim (substring link-line 2)))
(idx (string-match "[ \t]" rest)))
(and idx
(elpher-color-filter-apply (string-trim (substring rest (+ idx 1)))))))
(elpher-gemini-insert-preformatted-line line preformatted))
((pred (string-prefix-p "=>"))
(elpher-gemini-insert-link line))
+ ((pred (string-prefix-p "=:"))
+ (elpher-spartan-insert-query line))
((pred (string-prefix-p "#"))
(elpher-gemini-insert-header line))
(_ (elpher-gemini-insert-text line))))
(defun elpher-get-spartan-response (address renderer)
"Get response string from spartan server at ADDRESS and render using RENDERER."
- (elpher-get-host-response address 300
- (concat (elpher-address-host address) " "
- (elpher-address-filename address) " "
- "0\r\n") ; No uploads for now
- (lambda (response-string)
- (elpher-process-spartan-response response-string renderer))))
+ (let* ((host (elpher-address-host address))
+ (path-and-query (elpher-address-path-and-query address))
+ (filename (car path-and-query))
+ (data (cdr path-and-query))
+ (data-len (length data)))
+ (elpher-get-host-response address 300
+ (concat host " "
+ filename " "
+ (number-to-string data-len) "\r\n"
+ data)
+ (lambda (response-string)
+ (elpher-process-spartan-response response-string renderer)))))
(defun elpher-parse-spartan-response (response)
"Parse the RESPONSE string and return a list of components.
(if (member redirect-address elpher-spartan-redirect-chain)
(error "Redirect loop detected"))
(elpher-page-set-address elpher-current-page redirect-address)
- (add-to-list 'elpher-gemini-redirect-chain redirect-address)
+ (add-to-list 'elpher-spartan-redirect-chain redirect-address)
(elpher-get-spartan-response redirect-address renderer)))
(?4 ; Client error
(error "Spartan server reports CLIENT ERROR for this request: %s %s"
(error "Spartan server response unknown: %s %s"
response-code response-meta))))))
+(defun elpher-spartan-insert-query (query-line)
+ "Insert link described by QUERY-LINE into a text/gemini document."
+ (let ((url (elpher-gemini-get-link-url query-line)))
+ (when url
+ (let* ((address (elpher-address-from-gemini-url url))
+ (given-display-string (elpher-gemini-get-link-display-string query-line))
+ (fill-prefix (make-string (+ 1 (length elpher-gemini-link-string)) ?\s)))
+ (insert elpher-gemini-link-string)
+ (let ((display-string (or given-display-string url)))
+ (insert-text-button display-string
+ 'face 'elpher-spartan-post
+ 'display-string display-string
+ 'url (elpher-address-to-url address)
+ 'action #'elpher-spartan-post
+ 'follow-link t
+ 'help-echo #'elpher--page-button-help))
+ (newline)))))
+
+(defun elpher-spartan-post (button)
+ "Function called when the spartan post link BUTTON is clicked."
+ (let* ((display-string (button-get button 'display-string))
+ (url (button-get button 'url))
+ (post-url (concat url "?" (url-hexify-string (read-string "Text to post: ")))))
+ (elpher-visit-page (elpher-make-page
+ display-string
+ (elpher-address-from-url post-url)))))
+
;; Finger page connection
(defun elpher-get-finger-page (renderer)