about summary refs log tree commit diff
path: root/fnl/nvrc/ui
diff options
context:
space:
mode:
Diffstat (limited to 'fnl/nvrc/ui')
-rw-r--r--fnl/nvrc/ui/modules/diagnostics.fnl21
-rw-r--r--fnl/nvrc/ui/modules/misc.fnl14
-rw-r--r--fnl/nvrc/ui/modules/vi_mode.fnl40
-rw-r--r--fnl/nvrc/ui/statusline.fnl28
4 files changed, 103 insertions, 0 deletions
diff --git a/fnl/nvrc/ui/modules/diagnostics.fnl b/fnl/nvrc/ui/modules/diagnostics.fnl
new file mode 100644
index 0000000..a1e2530
--- /dev/null
+++ b/fnl/nvrc/ui/modules/diagnostics.fnl
@@ -0,0 +1,21 @@
+(fn diagnostics []
+  (let [count {}
+        levels {:errors :Error :warnings :Warn :info :Info :hints :Hint}]
+    (each [k level (pairs levels)]
+      (tset count k (vim.tbl_count (vim.diagnostic.get 0 {:severity level}))))
+    (var errors "")
+    (var warnings "")
+    (var hints "")
+    (var info "")
+    (when (not= (. count :errors) 0)
+      (set errors (.. "%#DiagnosticSignError#E" (. count :errors))))
+    (when (not= (. count :warnings) 0)
+      (set warnings
+           (.. " %#DiagnosticSignWarning#W" (. count :warnings))))
+    (when (not= (. count :hints) 0)
+      (set hints (.. " %#DiagnosticSignHint#H" (. count :hints))))
+    (when (not= (. count :info) 0)
+      (set info (.. " %#DiagnosticSignInformation#I" (. count :info))))
+    (.. errors warnings hints info "%#StatusLine#")))
+
+{: diagnostics}
diff --git a/fnl/nvrc/ui/modules/misc.fnl b/fnl/nvrc/ui/modules/misc.fnl
new file mode 100644
index 0000000..24d84f9
--- /dev/null
+++ b/fnl/nvrc/ui/modules/misc.fnl
@@ -0,0 +1,14 @@
+(fn file-size []
+  "feline.nvim's file size calculation module."
+  (let [suffix [:b :k :M :G :T :P :E]]
+    (var index 1)
+    (var fsize (vim.fn.getfsize (vim.api.nvim_buf_get_name 0)))
+    (when (< fsize 0)
+      (set fsize 0))
+    (while (and (> fsize 1024) (< index 7))
+      (set fsize (/ fsize 1024))
+      (set index (+ index 1)))
+    (string.format (or (and (= index 1) "%g%s | ") "%.2f%s | ") fsize
+                   (. suffix index))))
+
+{: file-size}
diff --git a/fnl/nvrc/ui/modules/vi_mode.fnl b/fnl/nvrc/ui/modules/vi_mode.fnl
new file mode 100644
index 0000000..1b9f1a1
--- /dev/null
+++ b/fnl/nvrc/ui/modules/vi_mode.fnl
@@ -0,0 +1,40 @@
+(local modes {:n :NORMAL
+              :no :NORMAL
+              :v :VISUAL
+              :V "V-LINE"
+              "\022" "V-BLOCK"
+              :s :SELECT
+              :S "L-SELECT"
+              "\019" "B-SELECT"
+              :i :INSERT
+              :ic :INSERT
+              :R :REPLACE
+              :Rv "V-REPLACE"
+              :c :COMMAND
+              :cv "VIM-EX"
+              :ce :EX
+              :r :PROMPT
+              :rm :MOAR
+              :r? :CONFIRM
+              :! :SHELL
+              :t :TERMINAL})
+
+(fn mode []
+  (let [current-mode (. (vim.api.nvim_get_mode) :mode)]
+    (: (string.format "%s " (. modes current-mode)) :upper)))
+
+(fn update-mode-colors []
+  (let [current-mode (. (vim.api.nvim_get_mode) :mode)]
+    (var mode-color "%#StatuslineAccent#")
+    (if (= current-mode :n) (set mode-color "%#StatuslineAccent#")
+        (or (= current-mode :i) (= current-mode :ic))
+        (set mode-color "%#StatuslineInsertAccent#")
+        (or (or (= current-mode :v) (= current-mode :V))
+            (= current-mode "\022"))
+        (set mode-color "%#StatusLineVisualAccent#") (= current-mode :R)
+        (set mode-color "%#StatusLineReplaceAccent#") (= current-mode :c)
+        (set mode-color "%#StatusLineCmdLineAccent#") (= current-mode :t)
+        (set mode-color "%#StatusLineTerminalAccent#"))
+    mode-color))
+
+{: mode : update-mode-colors}
diff --git a/fnl/nvrc/ui/statusline.fnl b/fnl/nvrc/ui/statusline.fnl
new file mode 100644
index 0000000..49afa7f
--- /dev/null
+++ b/fnl/nvrc/ui/statusline.fnl
@@ -0,0 +1,28 @@
+(import-macros {: setl!} :nvrc.macro.set)
+(import-macros {: ag!
+                : au!} :nvrc.macro.event)
+
+(local {: mode : update-mode-colors} (require :nvrc.ui.modules.vi_mode))
+(local {: diagnostics} (require :nvrc.ui.modules.diagnostics))
+(local {: file-size} (require :nvrc.ui.modules.misc))
+
+(global statusline {})
+(set statusline.enable (fn []
+                         (table.concat ["%#StatusLinePad#"
+                                        "▊ "
+                                        "%#StatusLine#"
+                                        (update-mode-colors)
+                                        (mode)
+                                        "%#StatusLineFile#"
+                                        "%f%m%r "
+                                        "%#StatusLine#"
+                                        (file-size)
+                                        "%l:%c | "
+                                        (diagnostics)
+                                        "%="
+                                        "%#StatusLineFileData#"
+                                        "%y %n"])))
+
+(ag! ui-statusline
+  (au! [WinEnter BufEnter] * #(setl! statusline "%!v:lua.statusline.enable()"))
+  (au! [WinLeave BufLeave] * #(setl! statusline "")))