-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathterm.lua
More file actions
75 lines (61 loc) · 2.01 KB
/
Copy pathterm.lua
File metadata and controls
75 lines (61 loc) · 2.01 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
local alpha = require("alpha")
local M = {}
function M.open_window(el)
local window_config = el.opts and el.opts.window_config or {}
if type(window_config) == 'function' then
window_config = window_config()
end
local width = window_config.width or el.width
local height = window_config.height or el.height
local row = math.floor(height / 5)
local col = math.floor((vim.o.columns - width) / 2)
local opts = vim.tbl_extend("keep", window_config, {
relative = "editor",
row = row,
col = col,
width = width,
height = height,
style = "minimal",
})
local bufnr = vim.api.nvim_create_buf(false, true)
local winid = vim.api.nvim_open_win(bufnr, true, opts)
vim.api.nvim_win_set_option(winid, "winhl", "Normal:Normal")
return { bufnr, winid }
end
function M.run_command(cmd, el)
if cmd == nil then
return
end
if type(cmd) == 'function' then
cmd = cmd()
end
vim.loop.new_async(vim.schedule_wrap(function()
local wininfo = M.open_window(el)
vim.api.nvim_command("terminal " .. cmd)
vim.api.nvim_command("wincmd j")
vim.api.nvim_buf_set_option(wininfo[1], "buflisted", false)
vim.api.nvim_win_set_var(0, "alpha_section_terminal", wininfo)
vim.api.nvim_command('let b:term_title ="alpha_terminal" ')
end)):send()
end
function M.close_window()
local ok, wininfo = pcall(vim.api.nvim_win_get_var, 0, "alpha_section_terminal")
if ok and vim.api.nvim_buf_is_loaded(wininfo[1]) then
vim.api.nvim_buf_delete(wininfo[1], { force = true })
end
end
vim.api.nvim_create_autocmd("User", {
pattern = "AlphaClosed",
callback = function()
M.close_window()
end,
})
function alpha.layout_element.terminal(el, _, _)
if el.opts and (el.opts.redraw == nil or el.opts.redraw) then
el.opts.redraw = false
M.run_command(el.command, el)
end
return {}, {}
end
function alpha.keymaps_element.terminal(_, _, _) end
return M