From: Tim Vaughan Date: Tue, 16 Apr 2019 23:32:08 +0000 (+0200) Subject: Added start page. X-Git-Tag: v1.0.0~76 X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=1f1bf8f3603af22926a34a4cca05f90dad95d223;p=elpher.git Added start page. --- diff --git a/elopher.el b/elopher.el index fb790a7..2be607a 100644 --- a/elopher.el +++ b/elopher.el @@ -6,18 +6,20 @@ ;;; Code: -(defvar elopher-mode-map +(setq elopher-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "") 'elopher-next-link) (define-key map (kbd "") 'elopher-prev-link) (define-key map (kbd "u") 'elopher-history-back) + (define-key map (kbd "g") 'elopher-go) (when (require 'evil nil t) (evil-define-key 'normal map (kbd "C-]") 'elopher-follow-closest-link (kbd "C-t") 'elopher-history-back - (kbd "u") 'elopher-history-back)) - map) - "Keymap for gopher client.") + (kbd "u") 'elopher-history-back + (kbd "g") 'elopher-go)) + map)) + ;; "Keymap for gopher client.") (define-derived-mode elopher-mode special-mode "elopher" "Major mode for elopher, an elisp gopher client.") @@ -29,10 +31,10 @@ (insert (propertize (format (concat "%" (number-to-string elopher-margin-width) "s") (concat "[" type-name "] ")) - 'face '(foreground-color . "yellow"))) + 'face '(foreground-color . "orange"))) (insert (make-string elopher-margin-width ?\s)))) -(defun elopher-process-record (line) +(defun elopher-render-record (line) (let* ((type (elt line 0)) (fields (split-string (substring line 1) "\t")) (display-string (elt fields 0)) @@ -53,7 +55,7 @@ 'follow-link t)) (?1 (elopher-insert-margin "/") (insert-text-button display-string - 'face '(foreground-color . "yellow") + 'face '(foreground-color . "cyan") 'link-getter #'elopher-get-index 'link-address address 'action #'elopher-click-link @@ -73,14 +75,14 @@ (defvar elopher-incomplete-record "") -(defun elopher-process-complete-records (string) +(defun elopher-render-complete-records (string) (let* ((til-now (string-join (list elopher-incomplete-record string))) (lines (split-string til-now "\r\n"))) (dotimes (idx (length lines)) (if (< idx (- (length lines) 1)) (let ((line (elt lines idx))) (unless (string-empty-p line) - (elopher-process-record line))) + (elopher-render-record line))) (setq elopher-incomplete-record (elt lines idx)))))) (defun elopher-get-selector (selector host port filter &optional sentinel) @@ -88,7 +90,6 @@ (elopher-mode) (let ((inhibit-read-only t)) (erase-buffer)) - (setq elopher-incomplete-record "") (make-network-process :name "elopher-process" :host host @@ -105,10 +106,11 @@ (set-marker marker 0 (current-buffer))) (save-excursion (goto-char marker) - (elopher-process-complete-records string) + (elopher-render-complete-records string) (set-marker marker (point)))))) (defun elopher-get-index (selector host port) + (setq elopher-incomplete-record "") (elopher-get-selector selector host port #'elopher-index-filter)) (defun elopher-text-filter (proc string) @@ -159,12 +161,41 @@ (interactive) (push-button)) -(defun elopher () - "Start gopher client." +(defun elopher-go () + "Go to a particular gopher site." (interactive) (elopher-get-index "" (read-from-minibuffer "Gopher host: ") 70)) +(defun elopher () + "Start elopher with default landing page." + (interactive) + (switch-to-buffer "*elopher*") + (elopher-mode) + (let ((inhibit-read-only t)) + (erase-buffer) + (save-excursion + (elopher-render-complete-records + (concat "i\tfake\tfake\t1\r\n" + "i--------------------------------------------\tfake\tfake\t1\r\n" + "i Elopher Gopher Client \tfake\tfake\t1\r\n" + "i version 1.0 \tfake\tfake\t1\r\n" + "i--------------------------------------------\tfake\tfake\t1\r\n" + "i\tfake\tfake\t1\r\n" + "iBasic usage:\tfake\tfake\t1\r\n" + "i - tab/shift-tab: next/prev directory entry\tfake\tfake\t1\r\n" + "i - RET/mouse-1: open directory entry\tfake\tfake\t1\r\n" + "i - u: return to parent directory entry\tfake\tfake\t1\r\n" + "i - g: go to a particular site\tfake\tfake\t1\r\n" + "i\tfake\tfake\t1\r\n" + "iPlaces to start exploring Gopherspace:\tfake\tfake\t1\r\n" + "1Floodgap Systems Gopher Server\t\tgopher.floodgap.com\t70\r\n" + "1Super-Dimensional Fortress\t\tgopher.floodgap.com\t70\r\n" + "i\tfake\tfake\t1\r\n" + "iTest entries:\tfake\tfake\t1\r\n" + "pXKCD comic image\t/fun/xkcd/comics/2130/2137/text_entry.png\tgopher.floodgap.com\t70\r\n"))))) + +(elopher) ;; (elopher-get-index "" "gopher.floodgap.com" 70) -(elopher-get-image "/fun/xkcd/comics/2130/2137/text_entry.png" "gopher.floodgap.com" 70) +;; (elopher-get-image "/fun/xkcd/comics/2130/2137/text_entry.png" "gopher.floodgap.com" 70) ;;; elopher.el ends here