+(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 '(foreground-color . "orange")))
+ (insert (make-string elopher-margin-width ?\s))))
+
+(defun elopher-render-record (line)
+ (let* ((type (elt line 0))
+ (fields (split-string (substring line 1) "\t"))
+ (display-string (elt fields 0))
+ (selector (elt fields 1))
+ (hostname (elt fields 2))
+ (port (elt fields 3))
+ (address (list selector hostname port)))
+ (pcase type
+ (?i (elopher-insert-margin)
+ (insert (propertize display-string
+ 'face '(foreground-color . "gray"))))
+ (?0 (elopher-insert-margin "T")
+ (insert-text-button display-string
+ 'face '(foreground-color . "white")
+ 'link-getter #'elopher-get-text
+ 'link-address address
+ 'action #'elopher-click-link
+ 'follow-link t))
+ (?1 (elopher-insert-margin "/")
+ (insert-text-button display-string
+ 'face '(foreground-color . "cyan")
+ 'link-getter #'elopher-get-index
+ 'link-address address
+ 'action #'elopher-click-link
+ 'follow-link t))
+ (?p (elopher-insert-margin "img")
+ (insert-text-button display-string
+ 'face '(foreground-color . "cyan")
+ 'link-getter #'elopher-get-image
+ 'link-address address
+ 'action #'elopher-click-link
+ 'follow-link t))
+ (?.) ; Occurs at end of index, can safely ignore.
+ (tp (elopher-insert-margin (concat (char-to-string tp) "?"))
+ (insert (propertize display-string
+ 'face '(foreground-color . "red")))))
+ (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))))))
+
+(defun elopher-get-selector (selector host port filter &optional sentinel)
+ (switch-to-buffer "*elopher*")
+ (elopher-mode)
+ (let ((inhibit-read-only t))
+ (erase-buffer))
+ (make-network-process
+ :name "elopher-process"
+ :host host
+ :service (if port port 70)
+ :filter filter
+ :sentinel sentinel)
+ (process-send-string "elopher-process" (concat selector "\n")))
+
+(defun elopher-index-filter (proc string)