From 6a7f12527b1d5f562c8e762126719706329aae8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 21 May 2016 23:45:34 +0200 Subject: vis: refactor status line handling Make window status bar content configurable via Lua. --- vis.lua | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'vis.lua') diff --git a/vis.lua b/vis.lua index 297c09e..c47d49f 100644 --- a/vis.lua +++ b/vis.lua @@ -282,3 +282,54 @@ vis.events.win_highlight = function(win, horizon_max) token_start = token_end end end + +local modes = { + [vis.MODE_NORMAL] = '', + [vis.MODE_OPERATOR_PENDING] = '', + [vis.MODE_VISUAL] = 'VISUAL', + [vis.MODE_VISUAL_LINE] = 'VISUAL-LINE', + [vis.MODE_INSERT] = 'INSERT', + [vis.MODE_REPLACE] = 'REPLACE', +} + +vis.events.win_status = function(win) + local left = {} + local right = {} + local file = win.file + local cursor = win.cursor + local delim_len = 1 + + local mode = modes[vis.mode] + if mode ~= '' then + table.insert(left, mode) + end + + table.insert(left, (file.name or '[No Name]') .. + (file.modified and ' [+]' or '') .. (vis.recording and ' @' or '')) + + if file.newlines ~= "nl" then + table.insert(right, "␊") + end + + if #win.cursors > 1 then + table.insert(right, cursor.number..'/'..#win.cursors) + end + + local size = file.size + table.insert(right, (size == 0 and "0" or math.ceil(cursor.pos/size*100)).."%") + + if not win.large then + local col = cursor.col + table.insert(right, cursor.line..', '..col) + if size > 33554432 or col > 65536 then + win.large = true + end + end + + local left_str = ' ' .. table.concat(left, " » ") .. ' ' + local right_str = ' ' .. table.concat(right, " « ") .. ' ' + local delim_count = math.max(#left-1, 0) + math.max(#right-1, 0) + local spaces = string.rep(' ', win.width - #left_str - #right_str + delim_count*delim_len) + local status = left_str .. spaces .. right_str + win:status(status) +end -- cgit v1.2.3