statusline.lisp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. (in-package #:nyxt-user)
  2. (ql:quickload 'sera)
  3. (ql:quickload 'spinneret)
  4. (defun list-modes (buffer)
  5. "List all the enabled modes of the given buffer"
  6. (format nil "~{~a~^ ~}" (mapcar #'format-mode (modes buffer))))
  7. (defun format-status-modes (buffer window)
  8. "I'm not sure what this is?"
  9. (spinneret:with-html-string
  10. (when (nosave-buffer-p buffer) (:span "履Incogneto")) ; If you're in a nosave buffer display it
  11. (:a :class "button"
  12. :href (lisp-url '(nyxt:toggle-modes))
  13. :title (str:concat "Enabled modes: " (list-modes buffer)) "✚") ; Where is this displaying?
  14. (loop for mode in
  15. (sera:filter #'visible-in-status-p (modes buffer)) ; for modes in buffer?
  16. collect
  17. (let*
  18. (
  19. (formatted-mode
  20. (if (glyph-mode-presentation-p (status-buffer window))
  21. (glyph mode) (format-mode mode)))
  22. ;; Parsing HTML is a valid way to know if HTML it is.
  23. (parsed-mode (ignore-errors (plump:parse formatted-mode)))
  24. )
  25. (if (and
  26. (sera:single (plump:children parsed-mode))
  27. (plump:text-node-p (elt (plump:children parsed-mode) 0)))
  28. (:a :class "button"
  29. :href (lisp-url `(describe-class ',(mode-name mode)))
  30. :title (format nil "Describe ~a" (mode-name mode))
  31. formatted-mode) (:raw formatted-mode))))))
  32. (defun format-status-buttons ()
  33. "Section meant for button controls"
  34. (spinneret:with-html-string
  35. (:a :class "button" :title "Backwards" :href (lisp-url '(nyxt/web-mode:history-backwards)) "«")
  36. (:a :class "button" :title "Reload" :href (lisp-url '(nyxt:reload-current-buffer)) "↺")
  37. (:a :class "button" :title "Forwards" :href (lisp-url '(nyxt/web-mode:history-forwards)) "»")
  38. ;(:a :class "button" :title "Execute" :href (lisp-url '(nyxt:execute-command)) "≡"))
  39. )
  40. (defun format-status-vi-mode (&optional (buffer (current-buffer)))
  41. (spinneret:with-html-string
  42. (cond
  43. ((find-submode buffer 'vi-normal-mode)
  44. (:div
  45. (:a :class "button"
  46. :title "command"
  47. :href (lisp-url '(nyxt/vi-mode:vi-insert-mode)) "C")))
  48. ((find-submode buffer 'vi-insert-mode)
  49. (:div
  50. (:a :class "button"
  51. :title "insert"
  52. :href (lisp-url '(nyxt/vi-mode:vi-normal-mode)) "I")))
  53. (t (:span "")))))
  54. (defun format-status-load-status (buffer)
  55. (spinneret:with-html-string
  56. (:div
  57. :class (if (and
  58. (web-buffer-p buffer)
  59. (eq (slot-value buffer 'load-status) :loading))
  60. "Loading Page..." ""))))
  61. (defun format-status-url (buffer)
  62. (spinneret:with-html-string
  63. (:a :class "button"
  64. :href (lisp-url '(nyxt:set-url))
  65. (format nil "~a"
  66. (render-url (url buffer))
  67. (title buffer)))))
  68. (defun format-status-tabs ()
  69. (spinneret:with-html-string
  70. (loop for domain in
  71. ;(remove-duplicates
  72. ; (sera:filter-map #'quri:uri-domain (mapcar #'url (sort-by-time (buffer-list))))
  73. ; :test #'equal)
  74. collect (:a :class "tab"
  75. :href (lisp-url `(nyxt::switch-buffer-or-query-domain ,domain))
  76. (format nil "~a" (title domain))))))
  77. (defun format-status (window)
  78. "Final status function that control the entire bar"
  79. (let*
  80. (
  81. (buffer (current-buffer window))
  82. (vi-class (cond ; Find vi mode mode
  83. ((find-submode buffer 'vi-normal-mode) "command")
  84. ((find-submode buffer 'vi-insert-mode) "insert")))
  85. )
  86. (spinneret:with-html-string
  87. (:div :id (if vi-class "container-vi" "container")
  88. (:td
  89. (:tr
  90. (:div :id "tabs"
  91. (:raw (format-status-tabs))))
  92. (:tr
  93. (:div :id "url" :class "rounded"
  94. (:raw (format-status-load-status buffer) (format-status-url buffer)))) ; <load status> <current url>
  95. (:tr
  96. (:div :id "buttons" :class "rounded-right" ; Try to make status bar sections rounded
  97. (:raw (format-status-buttons)))
  98. (when vi-class
  99. (:div :id "vi-mode" :class "rounded-right"
  100. (:raw (format-status-vi-mode buffer)))) ; <current vi mode>
  101. (:div :id "modes" :class "rounded-left"
  102. ; :title (list-modes buffer) ; why does this have this?
  103. (:raw (format-status-modes buffer window)))))))))