nvim: heirline improvements
This commit is contained in:
parent
e23936b1dc
commit
f99d9a48e5
5 changed files with 283 additions and 230 deletions
|
@ -1,13 +1,32 @@
|
|||
(let [mod {}
|
||||
terminal-class (require :toggleterm.terminal)
|
||||
terminal terminal-class.Terminal]
|
||||
(local elixir (terminal:new {:cmd :iex :close_on_exit true}))
|
||||
(local erlang (terminal:new {:cmd :erl :close_on_exit true}))
|
||||
(local fennel (terminal:new {:cmd "fennel --repl" :close_on_exit true}))
|
||||
(local fish (terminal:new {:cmd :fish :close_on_exit true}))
|
||||
(local javascript (terminal:new {:cmd :node :close_on_exit true}))
|
||||
(local nix (terminal:new {:cmd "nix repl" :close_on_exit true}))
|
||||
(local ruby (terminal:new {:cmd :irb :close_on_exit true}))
|
||||
(fn repl-setup []
|
||||
(set vim.b.nifoc_shell_mode :REPL))
|
||||
|
||||
(fn shell-setup []
|
||||
(set vim.b.nifoc_shell_mode :SHELL))
|
||||
|
||||
(local elixir (terminal:new {:cmd :iex
|
||||
:on_open repl-setup
|
||||
:close_on_exit true}))
|
||||
(local erlang (terminal:new {:cmd :erl
|
||||
:on_open repl-setup
|
||||
:close_on_exit true}))
|
||||
(local fennel (terminal:new {:cmd "fennel --repl"
|
||||
:on_open repl-setup
|
||||
:close_on_exit true}))
|
||||
(local fish (terminal:new {:cmd :fish
|
||||
:on_open shell-setup
|
||||
:close_on_exit true}))
|
||||
(local javascript (terminal:new {:cmd :node
|
||||
:on_open repl-setup
|
||||
:close_on_exit true}))
|
||||
(local nix (terminal:new {:cmd "nix repl"
|
||||
:on_open repl-setup
|
||||
:close_on_exit true}))
|
||||
(local ruby
|
||||
(terminal:new {:cmd :irb :on_open repl-setup :close_on_exit true}))
|
||||
;; Map filetype to REPL
|
||||
(local repl-map {: elixir : erlang : fennel : fish : javascript : nix : ruby})
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
(let [mod {:heirline {}}
|
||||
(let [mod {}
|
||||
api vim.api
|
||||
heirline-utils (require :heirline.utils)
|
||||
heirline-conditions (require :heirline.conditions)
|
||||
|
@ -13,17 +13,16 @@
|
|||
(. cl 1)))
|
||||
|
||||
(fn get-total-lines []
|
||||
(vim.api.nvim_buf_line_count 0))
|
||||
(api.nvim_buf_line_count 0))
|
||||
|
||||
;; Utils
|
||||
(set mod.heirline.default-hl
|
||||
(fn []
|
||||
(set mod.default-hl (fn []
|
||||
{:bg colors.black}))
|
||||
(set mod.heirline.space {:provider " "})
|
||||
(set mod.heirline.spacer {:provider " " :hl {:fg colors.bg :bg colors.bg}})
|
||||
(set mod.space {:provider " "})
|
||||
(set mod.spacer {:provider " " :hl {:fg colors.bg :bg colors.bg}})
|
||||
(set mod.push-right {:provider "%="})
|
||||
;; Mode
|
||||
(set mod.heirline.vi-mode
|
||||
{:init (fn [self]
|
||||
(set mod.vi-mode {:init (fn [self]
|
||||
(let [mode (. (api.nvim_get_mode) :mode)]
|
||||
(set self.mode mode)))
|
||||
:static {:mode-names {:n :NORMAL
|
||||
|
@ -61,35 +60,59 @@
|
|||
:r? :CONFIRM
|
||||
:! :SHELL
|
||||
:t :TERMINAL}
|
||||
:mode-hl {:n {:fg colors.black :bg colors.purple :bold true}
|
||||
:i {:fg colors.black :bg colors.green :bold true}
|
||||
:v {:fg colors.black :bg colors.pink :bold true}
|
||||
:V {:fg colors.black :bg colors.pink :bold true}
|
||||
"\022" {:fg colors.black :bg colors.pink :bold true}
|
||||
:c {:fg colors.black :bg colors.yellow :bold true}
|
||||
:s {:fg colors.black :bg colors.orange :bold true}
|
||||
:S {:fg colors.black :bg colors.orange :bold true}
|
||||
:mode-hl {:n {:fg colors.black
|
||||
:bg colors.purple
|
||||
:bold true}
|
||||
:i {:fg colors.black
|
||||
:bg colors.green
|
||||
:bold true}
|
||||
:v {:fg colors.black
|
||||
:bg colors.pink
|
||||
:bold true}
|
||||
:V {:fg colors.black
|
||||
:bg colors.pink
|
||||
:bold true}
|
||||
"\022" {:fg colors.black
|
||||
:bg colors.pink
|
||||
:bold true}
|
||||
:c {:fg colors.black
|
||||
:bg colors.yellow
|
||||
:bold true}
|
||||
:s {:fg colors.black
|
||||
:bg colors.orange
|
||||
:bold true}
|
||||
:S {:fg colors.black
|
||||
:bg colors.orange
|
||||
:bold true}
|
||||
"\019" {:fg colors.black
|
||||
:bg colors.orange
|
||||
:bold true}
|
||||
:R {:fg colors.black :bg colors.yellow :bold true}
|
||||
:r {:fg colors.black :bg colors.yellow :bold true}
|
||||
:! {:fg colors.black :bg colors.purple :bold true}
|
||||
:t {:fg colors.black :bg colors.purple :bold true}}}
|
||||
:R {:fg colors.black
|
||||
:bg colors.yellow
|
||||
:bold true}
|
||||
:r {:fg colors.black
|
||||
:bg colors.yellow
|
||||
:bold true}
|
||||
:! {:fg colors.black
|
||||
:bg colors.purple
|
||||
:bold true}
|
||||
:t {:fg colors.black
|
||||
:bg colors.purple
|
||||
:bold true}}}
|
||||
:provider (fn [self]
|
||||
(.. " " (. self :mode-names self.mode) " "))
|
||||
:hl (fn [self]
|
||||
(let [short-mode (self.mode:sub 1 1)]
|
||||
(. self :mode-hl short-mode)))})
|
||||
;; Filetype
|
||||
(set mod.heirline.filetype-block
|
||||
(set mod.filetype-block
|
||||
{:init (fn [self]
|
||||
(set self.filename (api.nvim_buf_get_name 0)))})
|
||||
(set mod.heirline.file-icon
|
||||
{:init (fn [self]
|
||||
(set mod.file-icon {:init (fn [self]
|
||||
(let [filename self.filename
|
||||
ext (vim.fn.fnamemodify filename ":e")
|
||||
(icon color) (web-devicons.get_icon_color filename ext
|
||||
(icon color) (web-devicons.get_icon_color filename
|
||||
ext
|
||||
{:default true})]
|
||||
(set self.icon icon)
|
||||
(set self.icon-color color)))
|
||||
|
@ -98,27 +121,22 @@
|
|||
(.. self.icon " ")))
|
||||
:hl (fn [self]
|
||||
{:fg self.icon-color})})
|
||||
(set mod.heirline.filetype
|
||||
{:provider (fn []
|
||||
(set mod.filetype {:provider (fn []
|
||||
(let [ft vim.bo.filetype]
|
||||
(if (> (ft:len) 0) ft "no ft")))
|
||||
:hl {:fg colors.white}})
|
||||
(set mod.heirline.filetype-block
|
||||
(heirline-utils.insert mod.heirline.filetype-block
|
||||
mod.heirline.file-icon mod.heirline.filetype))
|
||||
(set mod.filetype-block
|
||||
(heirline-utils.insert mod.filetype-block mod.file-icon mod.filetype))
|
||||
;; git
|
||||
(set mod.heirline.git {:condition heirline-conditions.is_git_repo
|
||||
(set mod.git {:condition heirline-conditions.is_git_repo
|
||||
:init (fn [self]
|
||||
(let [git-status vim.b.gitsigns_status_dict]
|
||||
(set self.git-head git-status.head)
|
||||
(set self.git-added (or git-status.added 0))
|
||||
(set self.git-removed
|
||||
(or git-status.removed 0))
|
||||
(set self.git-changed
|
||||
(or git-status.changed 0))
|
||||
(set self.git-removed (or git-status.removed 0))
|
||||
(set self.git-changed (or git-status.changed 0))
|
||||
(set self.has-changes?
|
||||
(or (> self.git-added 0)
|
||||
(> self.git-removed 0)
|
||||
(or (> self.git-added 0) (> self.git-removed 0)
|
||||
(> self.git-changed 0)))))
|
||||
1 {:provider (fn [self]
|
||||
(.. " " self.git-head " "))
|
||||
|
@ -127,17 +145,14 @@
|
|||
self.has-changes?)
|
||||
:provider " "}
|
||||
3 {:provider (fn [self]
|
||||
(let [spacer (if (or (> self.git-removed
|
||||
0)
|
||||
(> self.git-changed
|
||||
0))
|
||||
(let [spacer (if (or (> self.git-removed 0)
|
||||
(> self.git-changed 0))
|
||||
" " "")]
|
||||
(when (> self.git-added 0)
|
||||
(.. " " self.git-added spacer))))
|
||||
:hl {:fg colors.bright_green}}
|
||||
4 {:provider (fn [self]
|
||||
(let [spacer (if (> self.git-changed 0)
|
||||
" " "")]
|
||||
(let [spacer (if (> self.git-changed 0) " " "")]
|
||||
(when (> self.git-removed 0)
|
||||
(.. " " self.git-removed spacer))))
|
||||
:hl {:fg colors.bright_red}}
|
||||
|
@ -146,26 +161,32 @@
|
|||
(.. " " self.git-changed)))
|
||||
:hl {:fg colors.cyan}}})
|
||||
;; Diagnostics
|
||||
(set mod.heirline.diagnostics
|
||||
{:condition heirline-conditions.has_diagnostics
|
||||
(set mod.diagnostics {:condition heirline-conditions.has_diagnostics
|
||||
:init (fn [self]
|
||||
(let [d vim.diagnostic]
|
||||
(set self.errors
|
||||
(length (d.get 0 {:severity d.severity.ERROR})))
|
||||
(length (d.get 0
|
||||
{:severity d.severity.ERROR})))
|
||||
(set self.warnings
|
||||
(length (d.get 0 {:severity d.severity.WARN})))
|
||||
(set self.info (length (d.get 0 {:severity d.severity.INFO})))
|
||||
(length (d.get 0
|
||||
{:severity d.severity.WARN})))
|
||||
(set self.info
|
||||
(length (d.get 0
|
||||
{:severity d.severity.INFO})))
|
||||
(set self.hints
|
||||
(length (d.get 0 {:severity d.severity.HINT})))))
|
||||
(length (d.get 0
|
||||
{:severity d.severity.HINT})))))
|
||||
1 {:provider (fn [self]
|
||||
(let [spacer (if (or (> self.warnings 0) (> self.info 0)
|
||||
(let [spacer (if (or (> self.warnings 0)
|
||||
(> self.info 0)
|
||||
(> self.hints 0))
|
||||
" " "")]
|
||||
(when (> self.errors 0)
|
||||
(.. " " self.errors spacer))))
|
||||
:hl {:fg colors.red}}
|
||||
2 {:provider (fn [self]
|
||||
(let [spacer (if (or (> self.info 0) (> self.hints 0))
|
||||
(let [spacer (if (or (> self.info 0)
|
||||
(> self.hints 0))
|
||||
" " "")]
|
||||
(when (> self.warnings 0)
|
||||
(.. " " self.warnings spacer))))
|
||||
|
@ -180,7 +201,7 @@
|
|||
(.. " " self.hints)))
|
||||
:hl {:fg colors.cyan}}})
|
||||
;; Current Function
|
||||
(set mod.heirline.current-function
|
||||
(set mod.current-function
|
||||
{:condition heirline-conditions.lsp_attached
|
||||
:provider (fn []
|
||||
(let [ctx vim.b.nifoc_lsp_current_context]
|
||||
|
@ -188,8 +209,7 @@
|
|||
ctx)))
|
||||
:hl {:fg colors.white}})
|
||||
;; Buffer Options
|
||||
(set mod.heirline.buffer-options
|
||||
{:init (fn [self]
|
||||
(set mod.buffer-options {:init (fn [self]
|
||||
(set self.has-options?
|
||||
(or (buffer-variable-exists? :nifoc_lsp_enabled)
|
||||
(buffer-variable-exists? :nifoc_treesitter_enabled)
|
||||
|
@ -203,47 +223,55 @@
|
|||
" "))}
|
||||
3 {:provider (fn []
|
||||
(when (or (buffer-variable-exists? :nifoc_lsp_formatter_enabled)
|
||||
(not= (vim.opt_local.formatprg:get) ""))
|
||||
(not= (vim.opt_local.formatprg:get)
|
||||
""))
|
||||
" "))}
|
||||
4 {:provider (fn []
|
||||
(when (buffer-variable-exists? :nifoc_treesitter_enabled)
|
||||
" "))}
|
||||
5 {:provider (fn []
|
||||
(when vim.wo.spell
|
||||
"暈 "))}})
|
||||
"暈"))}})
|
||||
;; Position
|
||||
(set mod.heirline.position {:init (fn [self]
|
||||
(let [pos (api.nvim_win_get_cursor 0)]
|
||||
(set self.position-line
|
||||
(tostring (. pos 1)))
|
||||
(set self.position-column
|
||||
(tostring (. pos 2)))))
|
||||
:provider (fn [self]
|
||||
(string.format " %3s:%-3s "
|
||||
self.position-line
|
||||
self.position-column))
|
||||
:hl {:fg colors.black
|
||||
:bg colors.purple
|
||||
:bold true}})
|
||||
;; Scrollbar
|
||||
(set mod.heirline.scrollbar
|
||||
(set mod.position
|
||||
{:init (fn [self]
|
||||
(let [pos (api.nvim_win_get_cursor 0)]
|
||||
(set self.position-line (tostring (. pos 1)))
|
||||
(set self.position-column (tostring (. pos 2)))))
|
||||
:provider (fn [self]
|
||||
(string.format " %3s:%-3s " self.position-line
|
||||
self.position-column))
|
||||
:hl {:fg colors.black :bg colors.purple :bold true}})
|
||||
;; Scrollbar
|
||||
(set mod.scrollbar {:init (fn [self]
|
||||
(set self.current-line (get-current-line))
|
||||
(set self.total-lines (get-total-lines)))
|
||||
:static {:scrollbar-icons ["🭶" "🭷" "🭸" "🭹" "🭺" "🭻"]}
|
||||
:static {:scrollbar-icons ["🭶"
|
||||
"🭷"
|
||||
"🭸"
|
||||
"🭹"
|
||||
"🭺"
|
||||
"🭻"]}
|
||||
:provider (fn [self]
|
||||
(let [i (+ (math.floor (* (/ (- self.current-line 1)
|
||||
(let [i (+ (math.floor (* (/ (- self.current-line
|
||||
1)
|
||||
self.total-lines)
|
||||
(length self.scrollbar-icons)))
|
||||
1)
|
||||
new-scrollbar (. self :scrollbar-icons i)]
|
||||
new-scrollbar (. self :scrollbar-icons
|
||||
i)]
|
||||
(string.rep new-scrollbar 2)))
|
||||
:hl {:fg colors.purple}})
|
||||
;; Custom Mode
|
||||
|
||||
(fn mod.heirline.custom-mode [str]
|
||||
(fn mod.custom-mode [str fg bg]
|
||||
{:provider (.. " " str " ")
|
||||
:hl {:fg colors.black :bg colors.green :bold true}})
|
||||
:hl {:fg (. colors fg) :bg (. colors bg) :bold true}})
|
||||
|
||||
(fn mod.shell-mode [fg bg]
|
||||
{:provider (fn []
|
||||
(.. " " vim.b.nifoc_shell_mode " "))
|
||||
:hl {:fg (. colors fg) :bg (. colors bg) :bold true}})
|
||||
|
||||
mod)
|
||||
|
||||
|
|
|
@ -1,32 +1,38 @@
|
|||
(let [heirline (require :heirline)
|
||||
utils (require :heirline.utils)
|
||||
conditions (require :heirline.conditions)
|
||||
ns (. (require :nifoc.statusline) :heirline)]
|
||||
ns (require :nifoc.statusline)]
|
||||
(local default-statusline [;; Left
|
||||
ns.spacer
|
||||
ns.vi-mode
|
||||
(utils.surround [" " ""] nil ns.git)
|
||||
(utils.surround [" " ""] nil ns.diagnostics)
|
||||
(utils.surround [" " ""] nil ns.current-function)
|
||||
;; Right
|
||||
{:provider "%="}
|
||||
ns.push-right
|
||||
ns.filetype-block
|
||||
ns.space
|
||||
ns.buffer-options
|
||||
ns.space
|
||||
ns.scrollbar
|
||||
ns.space
|
||||
ns.position
|
||||
ns.spacer])
|
||||
ns.position])
|
||||
(local telescope-statusline
|
||||
{:condition (fn []
|
||||
(conditions.buffer_matches {:filetype [:TelescopePrompt]}))
|
||||
1 ns.spacer
|
||||
2 (ns.custom-mode :Telescope)})
|
||||
1 (ns.custom-mode :Telescope :black :green)})
|
||||
(local shell-statusline
|
||||
{:condition (fn []
|
||||
(not= vim.b.nifoc_shell_mode nil))
|
||||
1 ns.vi-mode
|
||||
2 ns.push-right
|
||||
3 ns.scrollbar
|
||||
4 ns.space
|
||||
5 (ns.shell-mode :black :purple)})
|
||||
(local statuslines {:hl ns.default-hl
|
||||
:init utils.pick_child_on_condition
|
||||
1 telescope-statusline
|
||||
2 default-statusline})
|
||||
2 shell-statusline
|
||||
3 default-statusline})
|
||||
;; Load Statusline
|
||||
(set vim.opt.laststatus 3)
|
||||
(heirline.setup statuslines))
|
||||
|
|
|
@ -73,11 +73,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1653340164,
|
||||
"narHash": "sha256-t6BPApyasx6FOv2cEVyFBXvkEDrknyUe7bngMbNSBkA=",
|
||||
"lastModified": 1653497002,
|
||||
"narHash": "sha256-L2kb16MAU59LIEWq7ODNsz5AHw5B5Dn9DNaKJF8pG/M=",
|
||||
"owner": "nix-community",
|
||||
"repo": "home-manager",
|
||||
"rev": "e66f0ff69a6c0698b35034b842c4b68814440778",
|
||||
"rev": "2c8489e57a04c913ba9e029cc2849a4bbac9673b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
@ -128,8 +128,8 @@
|
|||
src = pkgs.fetchFromGitHub {
|
||||
owner = "nvim-telescope";
|
||||
repo = "telescope.nvim";
|
||||
rev = "328232e090004274f2c830fdaad9a2bda8ba2e60";
|
||||
sha256 = "1lnl87b3bp31340ilp12dwr4gimxj8vajjf6nhqabd0w54r7g243";
|
||||
rev = "cd9e6aaee01624c1a5423a783e7fd5bc8fc955c5";
|
||||
sha256 = "1qvf0z2q0dz0nbvicz1vhd3684vx7nandxnz7246wncm2l5k26xr";
|
||||
fetchSubmodules = false;
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue