(require 'url-util)
(require 'subr-x)
(require 'dns)
-(require 'ansi-color)
(require 'nsm)
(require 'gnutls)
+;;; ANSI colors or XTerm colors
+
+(or (require 'xterm-color nil t)
+ (require 'ansi-color))
+
+(defalias 'elpher-color-filter-apply
+ (if (fboundp 'xterm-color-filter)
+ (lambda (s)
+ (let ((xterm-color-render nil))
+ (xterm-color-filter s)))
+ 'ansi-color-filter-apply)
+ "A function to filter out ANSI escape sequences.")
+(defalias 'elpher-color-apply
+ (if (fboundp 'xterm-color-filter)
+ 'xterm-color-filter
+ 'ansi-color-apply)
+ "A function to apply ANSI escape sequences.")
;;; Global constants
;;
'("gophers" "gemini")))
" [TLS encryption]"
""))
- (header (concat display-string
- (propertize tls-string 'face 'bold))))
+ (header (url-unhex-string
+ (concat display-string
+ (propertize tls-string 'face 'bold)))))
(setq header-line-format header))))
(defmacro elpher-with-clean-buffer (&rest args)
(defun elpher-list-existing-certificates ()
"Return a list of the persistent certificates in `elpher-certificate-directory'."
+ (unless (file-directory-p elpher-certificate-directory)
+ (make-directory elpher-certificate-directory))
(mapcar
(lambda (file)
(file-name-sans-extension file))
(if type-map-entry
(let* ((margin-code (elt type-map-entry 2))
(face (elt type-map-entry 3))
- (filtered-display-string (ansi-color-filter-apply display-string))
+ (filtered-display-string (elpher-color-filter-apply display-string))
(page (elpher-make-page filtered-display-string address)))
(elpher-insert-margin margin-code)
(insert-text-button filtered-display-string
"Perform any desired processing of STRING prior to display as text.
Currently includes buttonifying URLs and processing ANSI escape codes."
(elpher-buttonify-urls (if elpher-filter-ansi-from-text
- (ansi-color-filter-apply string)
- (ansi-color-apply string))))
+ (elpher-color-filter-apply string)
+ (elpher-color-apply string))))
(defun elpher-render-text (data &optional _mime-type-string)
"Render DATA as text. MIME-TYPE-STRING is unused."
(insert elpher-gemini-link-string)
(if type-map-entry
(let* ((face (elt type-map-entry 3))
- (filtered-display-string (ansi-color-filter-apply display-string))
+ (filtered-display-string (elpher-color-filter-apply display-string))
(page (elpher-make-page filtered-display-string address)))
(insert-text-button filtered-display-string
'face face
(define-key map "\C-m" 'elpher-menu-this-window)
(define-key map "o" 'elpher-menu-other-window)
(define-key map "\C-o" 'elpher-menu-switch-other-window)
+ (define-key map "c" 'elpher-menu-copy-current-url)
(define-key map "d" 'Buffer-menu-delete)
(define-key map "k" 'Buffer-menu-delete)
(define-key map "\C-k" 'Buffer-menu-delete)
(t
(error "There's no entry on this line of the menu")))))
+(defun elpher-menu-copy-current-url ()
+ "Copy the URL of the current menu item."
+ (interactive)
+ (let ((data (tabulated-list-get-id)))
+ (cond ((bufferp data)
+ (with-current-buffer data
+ (elpher-copy-page-url elpher-current-page)))
+ ((listp data)
+ (elpher-copy-page-url (nth 2 data)))
+ (t
+ (error "There's no entry on this line of the menu")))))
+
+ (defun elpher-copy-current-url ()
+ "Copy URL of current page to `kill-ring'."
+ (interactive)
+ (elpher-copy-page-url elpher-current-page))
+
(defvar elpher-title nil)
(defun elpher-find-title ()