Working on new model.
authorTim Vaughan <tgvaughan@gmail.com>
Fri, 19 Apr 2019 14:44:02 +0000 (16:44 +0200)
committerTim Vaughan <tgvaughan@gmail.com>
Fri, 19 Apr 2019 14:44:02 +0000 (16:44 +0200)
elopher.el

index 3aef080..96cd641 100644 (file)
   "Face used for image records.")
 (defcustom elopher-unknown-face '(foreground-color . "red")
   "Face used for unknown record types.")
-(defcustom elopher-margin-face '(foreground-color . "orange")
-  "Face used for record margin legend.")
+
+;;; Model
+;;
+
+(defun elopher-make-node (parent address &optional content)
+  (list parent address cache))
+
+(defun elopher-node-parent (node)
+  (car node))
+
+(defun elopher-node-address (node)
+  (cadr node))
+
+(defun elopher-node-content (node)
+  (caddr node))
+
+(defun elopher-reload-node (node after)
+  ())
 
 ;;; Global constants
 ;;
@@ -35,7 +51,7 @@
 (defconst elopher-margin-width 6
   "Width of left-hand margin used when rendering indicies.")
 
-(defvar elopher-start-page
+(defconst elopher-start-page
   (concat "i\tfake\tfake\t1\r\n"
           "i--------------------------------------------\tfake\tfake\t1\r\n"
           "i          Elopher Gopher Client             \tfake\tfake\t1\r\n"
@@ -55,7 +71,6 @@
           "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"))
 
-
 ;;; Mode and keymap
 ;;
 
 ;;; Index rendering
 ;;
 
+(defun elopher-insert-index (string)
+  "Inserts the index corresponding to STRING into the current buffer."
+  (dolist (line (split-string string "\r\n"))
+    (elopher-insert-index-record line)))
+
 (defun elopher-insert-margin (&optional type-name)
   (if type-name
-      (insert (propertize
-               (format (concat "%" (number-to-string elopher-margin-width) "s")
-                       (concat "[" type-name "] "))
-               'face elopher-margin-face))
+      (insert (format (concat "%" (number-to-string elopher-margin-width) "s"
+                              (concat
+                               (propertize "[" 'face '(foreground-color . "blue"))
+                               (propertize type-name 'face '(foreground-color . "white"))
+                               (propertize "]" 'face '(foreground-color . "blue"))))))
     (insert (make-string elopher-margin-width ?\s))))
 
-(defun elopher-render-record (line)
+(defun elopher-insert-index-record (line)
+  "Inserts the index record corresponding to LINE into the current buffer."
   (let* ((type (elt line 0))
          (fields (split-string (substring line 1) "\t"))
          (display-string (elt fields 0))
                               'face elopher-unknown-face))))
     (insert "\n")))
 
-(defvar elopher-incomplete-record "")
-
-(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-render-record line)))
-        (setq elopher-incomplete-record (elt lines idx))))))
-
-
 ;;; History management
 ;;