Add more functions to customize status bar

Adds `status.lines`, `status.vcol`, `status.bytes`, `status.size`,
and exposes some functions from go-humanize to plugins.

Ref #1727
This commit is contained in:
Zachary Yedidia
2020-06-24 17:19:42 -04:00
parent db1df05017
commit 5f62f550f3
5 changed files with 59 additions and 4 deletions

View File

@@ -6,10 +6,14 @@ Using the `statusformatl` and `statusformatr` options, the exact contents
of the status line can be modified. Please see the documentation for
those options (`> help options`) for more information.
This plugin provides the three functions that can be used in the status
line format:
This plugin provides functions that can be used in the status line format:
* `status.branch`: returns the name of the current git branch.
* `status.hash`: returns the hash of the current git commit.
* `status.paste`: returns "" if the paste option is disabled and "PASTE"
if it is enabled.
* `status.lines`: returns the number of lines in the buffer.
* `status.vcol`: returns the visual column number of the cursor.
* `status.bytes`: returns the number of bytes in the current buffer.
* `status.size`: returns the size of the current buffer in a human-readable
format.

View File

@@ -3,14 +3,35 @@ VERSION = "1.0.0"
local micro = import("micro")
local buffer = import("micro/buffer")
local config = import("micro/config")
local humanize = import("humanize")
function init()
micro.SetStatusInfoFn("status.branch")
micro.SetStatusInfoFn("status.hash")
micro.SetStatusInfoFn("status.paste")
micro.SetStatusInfoFn("status.vcol")
micro.SetStatusInfoFn("status.lines")
micro.SetStatusInfoFn("status.bytes")
micro.SetStatusInfoFn("status.size")
config.AddRuntimeFile("status", config.RTHelp, "help/status.md")
end
function lines(b)
return tostring(b:LinesNum())
end
function vcol(b)
return tostring(b:GetActiveCursor():GetVisualX())
end
function bytes(b)
return tostring(b:Size())
end
function size(b)
return humanize.Bytes(b:Size())
end
function branch(b)
if b.Type.Kind ~= buffer.BTInfo then
local shell = import("micro/shell")