vis-config
lua scripts to configure vis editor
git clone https://9o.is/git/vis-config.git
status.lua
(1668B)
1 local wm = require('lib/x11')
2
3 local mode_names = {
4 [vis.modes.NORMAL] = '[NORMAL]',
5 [vis.modes.OPERATOR_PENDING] = '[OPERATOR]',
6 [vis.modes.INSERT] = '[INSERT]',
7 [vis.modes.REPLACE] = '[REPLACE]',
8 [vis.modes.VISUAL] = '[VISUAL]',
9 [vis.modes.VISUAL_LINE] = '[VISUAL LINE]',
10 }
11
12 vis.events.subscribe(vis.events.WIN_OPEN, function(win)
13 if wm.running() then
14 vis:command('set statusbar off')
15 end
16 end)
17
18 vis.events.subscribe(vis.events.WIN_CLOSE, function(win)
19 local wc = 0
20 for _ in vis:windows() do wc = wc + 1 end
21 if wm.running() and wc == 1 then
22 wm.set_status('', '')
23 end
24 end)
25
26 vis.events.subscribe(vis.events.WIN_STATUS, function(win)
27 if win ~= vis.win then return end
28
29 local filename = win.file.name or '[No Name]'
30 local modified = win.file.modified and '[+]' or ''
31 local recording = vis.recording and '@' or ''
32 local mode = mode_names[vis.mode]
33 local line = win.selection.line
34 local total_lines = #win.file.lines
35 local scroll_percent = 0
36 local selections = #win.selections > 1 and string.format('%d-', #win.selections) or ''
37 local keys = tostring(vis.count or '') .. vis.input_queue:gsub(' ', '_')
38
39 if total_lines > 0 then
40 scroll_percent = math.floor((line / total_lines) * 100)
41 end
42
43 local left = filename
44 local right = string.format("%-2s %s %s %s %3s%d,%-4d %3d%%",
45 keys,
46 modified,
47 recording,
48 mode,
49 selections,
50 win.selection.line,
51 win.selection.col,
52 scroll_percent
53 )
54
55 if wm.running() then
56 wm.set_status(left, right)
57 else
58 win:status(left, right)
59 end
60 end)
61