From f5cc3f01fae31acdb35b9c70b739a130b059f05f Mon Sep 17 00:00:00 2001 From: sefidel Date: Sun, 6 Mar 2022 20:51:38 +0900 Subject: feat(ui): combine statusline into one file --- fnl/nvrc/ignite.fnl | 2 +- fnl/nvrc/statusline.fnl | 41 +++++++++++++++++++++++++++++++++++++ fnl/nvrc/ui/modules/diagnostics.fnl | 21 ------------------- fnl/nvrc/ui/statusline.fnl | 23 --------------------- 4 files changed, 42 insertions(+), 45 deletions(-) create mode 100644 fnl/nvrc/statusline.fnl delete mode 100644 fnl/nvrc/ui/modules/diagnostics.fnl delete mode 100644 fnl/nvrc/ui/statusline.fnl diff --git a/fnl/nvrc/ignite.fnl b/fnl/nvrc/ignite.fnl index 9eab014..fd3db9c 100644 --- a/fnl/nvrc/ignite.fnl +++ b/fnl/nvrc/ignite.fnl @@ -2,5 +2,5 @@ (require :nvrc.options) (require :nvrc.keymaps) (require :nvrc.events) -(require :nvrc.ui.statusline) +(require :nvrc.statusline) (require :nvrc.pack) diff --git a/fnl/nvrc/statusline.fnl b/fnl/nvrc/statusline.fnl new file mode 100644 index 0000000..fbac5a8 --- /dev/null +++ b/fnl/nvrc/statusline.fnl @@ -0,0 +1,41 @@ +(import-macros {: setl!} :nvrc.macro.set) +(import-macros {: ag! + : au!} :nvrc.macro.event) + +(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 + (.. " %#DiagnosticSignWarn#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#"))) + +(global statusline {}) +(set statusline.enable (fn [] + (table.concat ["%#StatusLineAccent#" + "▊ " + "%#StatusLine#" + "%#StatusLineAccentBold#" + "%f%m%r " + "%#StatusLine#" + "%l:%c | " + (diagnostics) + "%=" + "%#StatusLineAccentBold#" + "%y *%n "]))) + +(ag! ui-statusline + (au! [WinEnter BufEnter] * #(setl! statusline "%!v:lua.statusline.enable()")) + (au! [WinLeave BufLeave] * #(setl! statusline " "))) diff --git a/fnl/nvrc/ui/modules/diagnostics.fnl b/fnl/nvrc/ui/modules/diagnostics.fnl deleted file mode 100644 index 9cf6a02..0000000 --- a/fnl/nvrc/ui/modules/diagnostics.fnl +++ /dev/null @@ -1,21 +0,0 @@ -(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 - (.. " %#DiagnosticSignWarn#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/statusline.fnl b/fnl/nvrc/ui/statusline.fnl deleted file mode 100644 index c50bc81..0000000 --- a/fnl/nvrc/ui/statusline.fnl +++ /dev/null @@ -1,23 +0,0 @@ -(import-macros {: setl!} :nvrc.macro.set) -(import-macros {: ag! - : au!} :nvrc.macro.event) - -(local {: diagnostics} (require :nvrc.ui.modules.diagnostics)) - -(global statusline {}) -(set statusline.enable (fn [] - (table.concat ["%#StatusLineAccent#" - "▊ " - "%#StatusLine#" - "%#StatusLineAccentBold#" - "%f%m%r " - "%#StatusLine#" - "%l:%c | " - (diagnostics) - "%=" - "%#StatusLineAccentBold#" - "%y *%n "]))) - -(ag! ui-statusline - (au! [WinEnter BufEnter] * #(setl! statusline "%!v:lua.statusline.enable()")) - (au! [WinLeave BufLeave] * #(setl! statusline " "))) -- cgit 1.4.1