| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- local buffers = {}
- local create_term = function(name, command)
- if buffers[name] == nil then
- buffers[name] = command
- end
- end
- local open_term = function(name)
- if buffers[name] == nil then
- return
- end
- local fresh = false
- if type(buffers[name]) == "string" then
- fresh = buffers[name]
- buffers[name] = vim.api.nvim_create_buf(false, true)
- vim.bo[buffers[name]].filetype = "butterfly"
- end
- local win = vim.api.nvim_open_win(buffers[name], true, {
- relative = 'editor',
- row = 2,
- col = 0,
- width = vim.o.columns,
- height = vim.o.lines - 2,
- style = 'minimal',
- border = 'none',
- })
- vim.fn.setwinvar(win, '&winhl', 'Normal:Normal')
- vim.cmd(":startinsert");
- if fresh ~= false then
- vim.fn.termopen({ 'zsh', '-c', 'while true; do; clear; ' ..
- fresh .. '; done;' })
- end
- end
- local close_all = function()
- for _, win in pairs(vim.api.nvim_list_wins()) do
- local winbuf = vim.api.nvim_win_get_buf(win)
- if vim.bo[winbuf].filetype == 'butterfly' then
- vim.api.nvim_win_hide(win)
- end
- end
- end
- return {
- create_term = create_term,
- open_term = open_term,
- close_all = close_all,
- buffers = function()
- return buffers
- end
- }
|