Repository navigation
Expand file tree
/
Copy pathgitgraph.lua
More file actions
60 lines (44 loc) · 1.55 KB
/
Copy pathgitgraph.lua
File metadata and controls
60 lines (44 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
local log = require('gitgraph.log')
local config = require('gitgraph.config')
local highlights = require('gitgraph.highlights')
local M = {
config = config.defaults,
buf = nil, ---@type integer?
graph = {}, ---@type I.Row[]
}
--- Setup
---@param user_config I.GGConfig
function M.setup(user_config)
M.config = vim.tbl_deep_extend('force', M.config, user_config)
highlights.set_highlights()
math.randomseed(os.time())
log.set_level(M.config.log_level)
end
--- Draws the gitgraph in buffer
---@param options I.DrawOptions
---@param args I.GitLogArgs
---@return nil
function M.draw(options, args)
return require('gitgraph.draw').draw(M.config, options, args)
end
--- Tests the gitgraph plugin
function M.test()
local lines, _failure = require('gitgraph.tests').run_tests(M.config.symbols, M.config.format.fields)
local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_win_set_buf(0, buf)
vim.api.nvim_buf_set_lines(buf, 0, #lines, false, lines)
local cursor_line = #lines
vim.api.nvim_win_set_cursor(0, { cursor_line, 0 })
vim.api.nvim_set_option_value('modifiable', false, { buf = buf })
end
--- Draws a random gitgraph
function M.random()
local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_win_set_buf(0, buf)
local lines = require('gitgraph.tests').run_random(M.config.symbols, M.config.format.fields)
vim.api.nvim_buf_set_lines(buf, 0, #lines, false, lines)
local cursor_line = 1
vim.api.nvim_win_set_cursor(0, { cursor_line, 0 })
vim.api.nvim_set_option_value('modifiable', false, { buf = buf })
end
return M