Skip to content

Commit a91340d

Browse files
committed
add vim search_count component
1 parent 3e0fd38 commit a91340d

File tree

9 files changed

+68
-14
lines changed

9 files changed

+68
-14
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ This demo display an animation statusline to markdown and lua file.
1111

1212
![Mutlifiletype](./assets/demo/mutli_filetype.gif)
1313

14-
![spectre](./assets/demo/demo_spectre.png)
1514

1615
# Intro
1716

@@ -71,6 +70,8 @@ windline.setup({
7170
[wind animation](./lua/wlsample/wind.lua)
7271

7372

73+
Remember windline can change status line per filetype so you can have bubble
74+
line for markdown or latex file and airline for your working file.
7475

7576
# Status line
7677

@@ -178,6 +179,8 @@ basic.lsp_diagnos = {
178179
end,
179180
}
180181
```
182+
Windline doesn't have a component condition just return it to empty or nil to
183+
make it disappear
181184

182185
# Colors
183186
Windline use a terminal color. It generate from your colorscheme terminal.

lua/windline/component.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ local Comp = {}
22
local utils=require('windline.utils')
33

44
local render_text = function (text, highlight)
5-
if text == nil then text = "" end
5+
if text == nil or text == "" then return "" end
66
if highlight == '' or highlight == nil then return text end
77
return string.format('%%#%s#%s', highlight, text)
88
end

lua/windline/components/git.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ M.diff_added = function(opt)
3434
return function()
3535
local git_dict = vim.b.gitsigns_status_dict
3636
if git_dict and git_dict.head and #git_dict.head > 0 then
37-
local value = git_dict.added
37+
local value = git_dict.added or 0
3838
if value > 0 or value == 0 and opt.show_zero == true then
3939
return string.format(format, value)
4040
end
@@ -50,7 +50,7 @@ M.diff_removed = function(opt)
5050
return function()
5151
local git_dict = vim.b.gitsigns_status_dict
5252
if git_dict and git_dict.head and #git_dict.head > 0 then
53-
local value = git_dict.removed
53+
local value = git_dict.removed or 0
5454
if value > 0 or value == 0 and opt.show_zero == true then
5555
return string.format(format, value)
5656
end
@@ -65,7 +65,7 @@ M.diff_changed = function(opt)
6565
return function()
6666
local git_dict = vim.b.gitsigns_status_dict
6767
if git_dict and git_dict.head and #git_dict.head > 0 then
68-
local value = git_dict.changed
68+
local value = git_dict.changed or 0
6969
if value > 0 or value == 0 and opt.show_zero == true then
7070
return string.format(format, value)
7171
end

lua/windline/components/vim.lua

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
local M = {}
2+
3+
4+
M.cmdl_search_leave = function()
5+
6+
-- need to wait cmd finish search to get last search pattern
7+
vim.defer_fn(function()
8+
local pattern = vim.fn.getreg("/")
9+
local result = vim.fn.searchcount({pattern = pattern})
10+
vim.b.windline_search_cache = result
11+
vim.cmd "redrawstatus"
12+
end, 10)
13+
end
14+
15+
M.search_count = function(opt)
16+
opt= opt or{}
17+
local show_zero = opt.show_zero or false
18+
19+
vim.api.nvim_exec([[
20+
aug WLSearchLens
21+
au!
22+
au CmdlineLeave [/\?] lua require('windline.components.vim').cmdl_search_leave()
23+
aug END
24+
]], false)
25+
26+
return function()
27+
if vim.v.hlsearch == 0 then return '' end
28+
29+
local result = vim.b.windline_search_cache or {}
30+
if vim.tbl_isempty(result) then
31+
return ''
32+
end
33+
if show_zero == false and result.total == 0 and result.current == 0 then
34+
return ''
35+
end
36+
-- this make sure we have correct location
37+
result = vim.fn.searchcount({recompute = 0})
38+
39+
if result.incomplete == 1 then -- timed out
40+
return " ?/?? "
41+
elseif result.incomplete == 2 then -- max count exceeded
42+
if result.total > result.maxcount and result.current > result.maxcount then
43+
return string.format(" >%d/>%d ", result.current, result.total)
44+
elseif result.total > result.maxcount then
45+
return string.format(" >%d/>%d ", result.current, result.total)
46+
end
47+
end
48+
return string.format(" %d/%d ", result.current, result.total)
49+
end
50+
end
51+
return M

lua/wlsample/airline.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@ local helper = require('windline.helpers')
33
local sep = helper.separators
44
local b_components = require('windline.components.basic')
55
local state = _G.WindLine.state
6+
local vim_components = require('windline.components.vim')
67

78
local lsp_comps = require('windline.components.lsp')
89
local git_comps = require('windline.components.git')
910

1011
local hl_list = {
1112
Black = { 'white', 'black' },
1213
White = { 'black', 'white' },
14+
Normal = {'NormalFg', 'NormalBg'},
1315
Inactive = { 'InactiveFg', 'InactiveBg' },
1416
Active = { 'ActiveFg', 'ActiveBg' },
1517
}
1618
local basic = {}
1719

18-
basic.divider = { b_components.divider, '' }
19-
basic.bg = { ' ', 'StatusLine' }
20+
basic.divider = { b_components.divider, hl_list.Normal }
2021

2122
local colors_mode_light = {
2223
Normal = { 'magenta', 'black_light' },
@@ -94,7 +95,6 @@ basic.right_sep = {
9495
}
9596
end,
9697
}
97-
9898
local default = {
9999
filetypes = { 'default' },
100100
active = {
@@ -105,6 +105,7 @@ local default = {
105105
{ b_components.file_name(), '' },
106106
{ sep.right_filled, { 'black_light', 'NormalBg' } },
107107
basic.lsp_diagnos,
108+
{vim_components.search_count(),{"cyan", "NormalBg"}},
108109
basic.divider,
109110
{ sep.left_filled, { 'black_light', 'NormalBg' } },
110111
{ ' ', { 'white_light', 'black_light' } },

lua/wlsample/basic.lua

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,10 @@ basic.divider = {b_components.divider, ''}
2222
basic.space = {' ', ''}
2323
basic.line_col = {b_components.line_col, hl_list.Black }
2424
basic.progress = {b_components.progress, hl_list.Black}
25-
basic.bg = {" ", 'StatusLine'}
2625
basic.file_name_inactive = {b_components.full_file_name, hl_list.Inactive}
2726
basic.line_col_inactive = {b_components.line_col, hl_list.Inactive}
2827
basic.progress_inactive = {b_components.progress, hl_list.Inactive}
2928

30-
-- basic.file_format = {b_components.file_format({icon = true}), hl_list.Black}
31-
-- basic.file_size = {b_components.file_size(), hl_list.Black}
32-
3329
basic.vi_mode= {
3430
name = 'vi_mode',
3531
hl_colors = {

lua/wlsample/bubble.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local windline = require('windline')
22
local helper = require('windline.helpers')
33
local sep = helper.separators
4+
local vim_components = require('windline.components.vim')
45

56
local b_components = require('windline.components.basic')
67
local state = _G.WindLine.state
@@ -129,6 +130,7 @@ local default = {
129130
{ ' ', hl_list.Black },
130131
basic.vi_mode,
131132
basic.file,
133+
{vim_components.search_count(),{"red", "white"}},
132134
{ sep.right_rounded, hl_list.Black },
133135
basic.lsp_diagnos,
134136
basic.git,

lua/wlsample/evil_line.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ local default = {
116116
},
117117
in_active = {
118118
{ b_components.full_file_name, hl_list.Inactive },
119+
basic.file_name_inactive,
119120
basic.divider,
120121
basic.divider,
121122
{ b_components.line_col, hl_list.Inactive },

lua/wlsample/wind.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ animation.animation({
206206
{'waveleft4',efffects.list_color(blue_colors,3)},
207207
{'waveleft5',efffects.list_color(blue_colors,2)},
208208
},
209-
timeout = 10,
209+
timeout = 100,
210210
delay = 200,
211211
interval = 150,
212212
})
@@ -221,7 +221,7 @@ animation.animation({
221221
{'waveright4',efffects.list_color(blue_colors,5)},
222222
{'waveright5',efffects.list_color(blue_colors,6)},
223223
},
224-
timeout = 10,
224+
timeout = 100,
225225
delay = 200,
226226
interval = 150,
227227
})

0 commit comments

Comments
 (0)