blob: 8ad8820ee81159671943d26689e894a251db638f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
(local heirline (require :heirline))
(local conditions (require :heirline.conditions))
(local utils (require :heirline.utils))
(local colors (let [kanagawa-colors (require :kanagawa.colors)]
(kanagawa-colors.setup)))
(local Align {:provider "%="})
(local Space {:provider " "})
(fn with [tbl with-kv]
(local w {})
(each [k v (pairs tbl)]
(tset w k v))
(each [k v (pairs with-kv)]
(tset w k v))
w)
(heirline.load_colors colors)
(fn palette [name]
(. colors :palette name))
(fn theme [theme name]
(. colors :theme theme name))
(var FileNameBlock
{;; let's first set up some attributes needed by this component and it's children
:init (lambda [self]
(tset self :filename (vim.api.nvim_buf_get_name 0)))})
(local FileName
{:provider (lambda [self]
;; first, trim the pattern relative to the current directory. For other
;;- options, see :h filename-modifers
(var filename (vim.fn.fnamemodify (. self :filename) ":."))
(if (= filename "")
(set filename "[No Name]")
;;- now, if the filename would occupy more than 1/4th of the available
;;-- space, we trim the file path to its initials
;;-- See Flexible Components section below for dynamic truncation
(if (not (conditions.width_percent_below (length filename)
0.25))
(set filename (vim.fn.pathshorten filename))))
filename)
:hl {:fg (. (utils.get_highlight :Directory) :fg)}})
(local FileNameModifier {:hl (lambda []
(when vim.bo.modified
{:fg (theme :diag :warning)
:bold true
:force true}))})
(local FileFlags [{:condition (lambda [] vim.bo.modified)
:provider "[+]"
:hl {:fg (theme :diag :warning)}}])
(set FileNameBlock (utils.insert FileNameBlock
(utils.insert FileNameModifier FileName)
FileFlags {:provider "%<"}))
(local DAPMessages {:condition (lambda []
(local dap (require :dap))
(local session (dap.session))
(not (= session nil)))
:provider (lambda []
(local dap (require :dap))
(.. " " (dap.status)))
:hl :Debug})
(local Ruler {;; %l = current line number
;; %L = number of lines in the buffer
;; %c = column number
;; %P = percentage through file of displayed window
:provider "%7(%l/%3L%):%2c %P"})
(local ScrollBar
{:static {:sbar ["▁" "▂" "▃" "▄" "▅" "▆" "▇" "█"]}
;; Another variant, because the more choice the better.
;; sbar { '🭶', '🭷', '🭸', '🭹', '🭺', '🭻'}}
:provider (lambda [self]
(local curr_line (. (vim.api.nvim_win_get_cursor 0) 1))
(local lines (vim.api.nvim_buf_line_count 0))
(local i
(- (length self.sbar)
(math.floor (* (/ (- curr_line 1) lines)
(length (. self :sbar))))))
(string.rep (. self :sbar i) 2))
:hl {:fg (theme :syn :fun) :bg (theme :ui :bg)}})
(local Nix
{:condition (fn [] vim.env.IN_NIX_SHELL)
:provider (fn [self]
(local purity vim.env.IN_NIX_SHELL)
(local name vim.env.name)
(.. "" purity "(" name ")"))
:hl {:fg (theme :syn :fun) :bold true :bg (theme :ui :bg_m3)}})
(local RecordingMacro {:condition #(not= "" (vim.fn.reg_recording))
:provider (fn [self]
(.. "Recording... " (vim.fn.reg_recording)))
:hl {:fg (theme :syn :fun)
:bold true
:bg (theme :ui :bg_m3)}})
(local harpoon (require :harpoon))
(local harpoon-mark (require :harpoon.mark))
(local harpoon-colors [(theme :syn :identifier)
(theme :syn :identifier)
(theme :syn :identifier)])
(fn mark-component [i mark]
(utils.insert {} {:hl {:bg (if (= mark.filename
(vim.fn.fnamemodify (vim.api.nvim_buf_get_name 0)
":."))
(theme :ui :bg_p1)
(theme :ui :bg_m1))
:bold true
:fg (. harpoon-colors i)}
:provider (fn [self]
(.. " M" i " "))}))
;{:hl {:fg (theme :syn :fun)} :provider (vim.fn.pathshorten mark.filename)}))
; {:hl {:bold true :fg (. harpoon-colors i)} :provider ")"} Space))
(local HarpoonMarks
(utils.insert {:hl :TabLineSel
:condition #(< 0
(length (. (harpoon.get_mark_config)
:marks)))}
{:init (lambda [self]
(local mark-list
(. (harpoon.get_mark_config) :marks))
(each [i mark (ipairs mark-list)]
(tset self i
(self:new (mark-component i mark) i)))
(while (> (length self) (length mark-list))
(table.remove self (length self))))}))
(local Tabpage
{:provider (lambda [self]
(fn fnamemod [name mod]
(vim.fn.fnamemodify name mod))
(fn format-name [name]
(if (= name "") "[No Name]"
(fnamemod name ":t")))
(.. "%" self.tabnr "T " self.tabnr " "))
:hl (lambda [self]
(if (not self.is_active) :TabLine :TabLineSel))})
(fn active-tab-hrpn [self]
(local hl {})
(if (. self :is_active)
(do
(tset hl :fg (theme :syn :identifier))
(tset hl :bold true)))
hl)
(fn active-hl [hl]
(lambda [self]
(if self.is_active
hl
{})))
(fn tab-visible-buffers [tab]
(local visible (vim.fn.tabpagebuflist tab))
(if (= visible 0)
[]
visible))
(fn tab-harpoon-marks [tab]
(local visible (tab-visible-buffers tab))
(local tab-buffers (accumulate [buffers [] _ buf (ipairs visible)]
(do
(if (not (vim.tbl_contains buffers buf))
(table.insert buffers buf))
buffers)))
(icollect [_ buf (ipairs tab-buffers)]
(do
(local status (harpoon-mark.status buf))
(if (not= status "")
status))))
(local Tabpage
(utils.insert Tabpage {:hl active-tab-hrpn :provider "🌊 [ "}
{:hl (active-hl {:fg (theme :syn :fun)})
:provider (lambda [self]
(local harpoon_marks
(tab-harpoon-marks self.tabnr))
(table.concat harpoon_marks " "))}
{:hl active-tab-hrpn :provider " ] %T"}))
(local TabpageClose {:provider "%999X %X" :hl :TabLine})
(local TabPages
{;; only show this component if there's 2 or more tabpages
:condition (lambda []
(>= (length (vim.api.nvim_list_tabpages)) 1))})
(local TabPages (utils.insert TabPages (utils.make_tablist Tabpage)
TabpageClose))
(local StatusLine [FileNameBlock
Space
HarpoonMarks
Space
TabPages
DAPMessages
Space
RecordingMacro
Align
Space
Nix
Space
Ruler
Space
ScrollBar
Space])
(heirline.setup {:statusline StatusLine})
|