dotfiles/home/config/nvim/nifoc/tabline.fnl

103 lines
4.8 KiB
Text
Raw Normal View History

(let [mod {}
api vim.api
heirline-utils (require :heirline.utils)
2022-08-29 20:36:11 +00:00
colors (. (require :nifoc.theme) :colors)
2022-08-28 22:33:48 +00:00
statusline (require :nifoc.statusline)
fg-active (. (heirline-utils.get_highlight :TabLineSel) :fg)
fg-inactive (. (heirline-utils.get_highlight :TabLine) :fg)
bg-active (. (heirline-utils.get_highlight :TabLineSel) :bg)
bg-inactive (. (heirline-utils.get_highlight :TabLine) :bg)]
;; Utils
2022-08-28 22:33:48 +00:00
(set mod.space
{:provider " "
:hl (fn [self]
(if self.is_active {:bg bg-active} {:bg bg-inactive}))})
(set mod.truncate-left {:provider "" :hl {:fg fg-inactive}})
(set mod.truncate-right {:provider "" :hl {:fg fg-inactive}})
;; Filename
(set mod.filename-block
{:init (fn [self]
(set self.filename (api.nvim_buf_get_name self.bufnr)))
:hl (fn [self]
(if self.is_active :TabLineSel :TabLine))
:on_click {:name :heirline_tabline_buffer_callback
:callback (fn [_ minwid]
(api.nvim_win_set_buf 0 minwid))
:minwid (fn [self]
self.bufnr)}})
(set mod.filename
{:provider (fn [self]
(if (= self.filename "") "[No Name]"
(vim.fn.fnamemodify self.filename ":t")))
:hl (fn [self]
(let [visible (or self.is_active self.is_visible)]
{:bold visible :italic visible}))})
2022-12-10 23:10:09 +00:00
(set mod.file-flags [{:condition #(api.nvim_buf_get_option $1.bufnr :modified)
:provider " "
:hl {:fg colors.yellow}}
2022-12-10 23:10:09 +00:00
{:condition #(or (not (api.nvim_buf_get_option $1.bufnr
:modifiable))
(api.nvim_buf_get_option $1.bufnr
:readonly))
:provider (fn [self]
(if (= api.nvim_buf_get_option self.bufnr
:terminal)
2023-03-29 20:18:22 +00:00
" "
" "))
:hl {:fg colors.orange}}])
(set mod.filename-block
(heirline-utils.insert mod.filename-block statusline.file-icon
mod.filename mod.file-flags))
2022-08-29 20:36:11 +00:00
;; Tabpages
(set mod.tabpage
2023-04-05 08:10:31 +00:00
{:provider #(.. "%" $1.tabnr "T " $1.tabnr " %T")
2022-08-29 20:36:11 +00:00
:hl (fn [self]
(if self.is_active :TabLineSel :TabLine))})
;; Buttons
(set mod.close-button
{:condition (fn [self]
(not (. vim :bo self.bufnr :modified)))
2022-10-28 12:28:43 +00:00
:update [:WinNew :WinClosed :BufEnter]
2022-08-28 22:33:48 +00:00
1 mod.space
2 {:provider ""
2022-08-28 22:33:48 +00:00
:hl (fn [self]
(if self.is_active {:fg fg-active :bg bg-active}
{:fg fg-inactive :bg bg-inactive}))
:on_click {:name :heirline_tabline_close_buffer_callback
:callback (fn [_ minwid]
2023-03-29 20:18:22 +00:00
(vim.schedule #(api.nvim_buf_delete minwid
{:force false}))
(vim.cmd.redrawtabline))
:minwid (fn [self]
self.bufnr)}}})
2022-08-29 20:36:11 +00:00
(set mod.close-tabpage {:provider "%999X  %X" :hl :TabLine})
;; Indicator
(set mod.active-indicator
{:provider (fn [self]
(if self.is_active "┃ " " "))
2022-08-28 22:33:48 +00:00
:hl (fn [self]
(if self.is_active {:fg colors.purple :bg bg-active :bold true}
{:fg fg-inactive :bg bg-inactive :bold true}))})
2022-08-29 20:54:43 +00:00
(set mod.os-indicator {:static {:uname (. (vim.loop.os_uname) :sysname)
:os {:Darwin "" :Linux ""}
:os-color {:Darwin colors.white
:Linux "#7ebae4"}}
:hl (fn [self]
(let [fg-color (. self :os-color self.uname)]
{:fg fg-color :bg bg-active}))
2022-08-29 20:36:11 +00:00
1 {:provider " "}
2 {:provider (fn [self]
2022-08-29 20:54:43 +00:00
(. self :os self.uname))}
2022-08-29 20:36:11 +00:00
3 {:provider " "}})
;; Block
2022-08-28 22:33:48 +00:00
(set mod.buffer-block [mod.active-indicator
mod.filename-block
mod.close-button
mod.space])
2022-08-29 20:36:11 +00:00
(set mod.tabpages-block {:condition #(>= (length (api.nvim_list_tabpages)) 2)
1 statusline.push-right
2 (heirline-utils.make_tablist mod.tabpage)
3 mod.close-tabpage})
mod)