Added start page.
authorTim Vaughan <tgvaughan@gmail.com>
Tue, 16 Apr 2019 23:32:08 +0000 (01:32 +0200)
committerTim Vaughan <tgvaughan@gmail.com>
Tue, 16 Apr 2019 23:32:08 +0000 (01:32 +0200)
elopher.el

index fb790a7..2be607a 100644 (file)
@@ -6,18 +6,20 @@
 
 ;;; Code:
 
-(defvar elopher-mode-map
+(setq elopher-mode-map
   (let ((map (make-sparse-keymap)))
     (define-key map (kbd "<tab>") 'elopher-next-link)
     (define-key map (kbd "<S-tab>") '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.")
       (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
 
 (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
           (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)
   (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