+18
-5
lua/jj-log/init.lua
+18
-5
lua/jj-log/init.lua
···
1
1
local M = {}
2
2
3
+
local defaults = {
4
+
out_waiting = "",
5
+
out_no_jj_repo = "~no_jj_repo~",
6
+
out_no_desc = "~no_desc~",
7
+
max_desc_length = 47,
8
+
}
9
+
10
+
M.config = vim.deepcopy(defaults)
11
+
3
12
M.update_jj_status = function(bufnr)
4
-
vim.api.nvim_buf_set_var(bufnr, "jj_desc", "")
13
+
vim.api.nvim_buf_set_var(bufnr, "jj_desc", M.config.out_waiting)
5
14
6
15
local current_file = vim.api.nvim_buf_get_name(bufnr)
7
16
if current_file == "" or current_file == nil then
···
24
33
)[1]
25
34
26
35
if not jj_root then
27
-
vim.api.nvim_buf_set_var(bufnr, "jj_desc", "~no_jj_repo~")
36
+
vim.api.nvim_buf_set_var(bufnr, "jj_desc", M.config.out_no_jj_repo)
28
37
return
29
38
end
30
39
···
42
51
local output = vim.trim(obj.stdout or "")
43
52
output = output:gsub("\n", ""):gsub("^%s*", ""):gsub("%s*$", "")
44
53
45
-
if output == "" then output = "~no_desc~" end
46
-
if #output > 50 then output = string.sub(output, 1, 47) .. "..." end
54
+
if output == "" then output = M.config.out_no_desc end
55
+
if #output > (M.config.max_desc_length + 3) then
56
+
output = string.sub(output, 1, M.config.max_desc_length) .. "..."
57
+
end
47
58
48
59
vim.schedule(function()
49
60
if vim.api.nvim_buf_is_valid(bufnr) then
···
57
68
end)
58
69
end
59
70
60
-
M.setup = function()
71
+
M.setup = function(opts)
72
+
M.config = vim.tbl_deep_extend("force", M.config, opts or {})
73
+
61
74
local group = vim.api.nvim_create_augroup("JJLogPlugin", { clear = true })
62
75
63
76
vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter", "BufWritePost", "FocusGained" }, {