-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathfloats.lua
More file actions
42 lines (32 loc) · 1.11 KB
/
floats.lua
File metadata and controls
42 lines (32 loc) · 1.11 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
local M = {}
local o = require("code_runner.options")
function M.floating(command)
local opt = o.get()
local buf = vim.api.nvim_create_buf(false, true)
vim.keymap.set("t", "<ESC>", "<C-\\><C-n>", { silent = true, buffer = buf })
vim.keymap.set("n", opt.float.close_key, "<CMD>q!<CR>", { silent = true, buffer = buf })
vim.bo[buf].filetype = "crunner"
local win_height = math.ceil(vim.o.lines * opt.float.height - 4)
local win_width = math.ceil(vim.o.columns * opt.float.width)
local row = math.ceil((vim.o.lines - win_height) * opt.float.y - 1)
local col = math.ceil((vim.o.columns - win_width) * opt.float.x)
local win = vim.api.nvim_open_win(buf, true, {
style = "minimal",
relative = "editor",
border = opt.float.border,
width = win_width,
height = win_height,
row = row,
col = col,
})
vim.fn.termopen(command)
if opt.startinsert then
vim.cmd("startinsert")
end
if opt.wincmd then
vim.cmd("wincmd p")
end
vim.wo[win].winhl = "Normal:" .. opt.float.float_hl .. ",FloatBorder:" .. opt.float.border_hl
vim.wo[win].winblend = opt.float.blend
end
return M