init.lua 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. local buffers = {}
  2. local create_term = function(name, command)
  3. if buffers[name] == nil then
  4. buffers[name] = command
  5. end
  6. end
  7. local open_term = function(name)
  8. if buffers[name] == nil then
  9. return
  10. end
  11. local fresh = false
  12. if type(buffers[name]) == "string" then
  13. fresh = buffers[name]
  14. buffers[name] = vim.api.nvim_create_buf(false, true)
  15. vim.bo[buffers[name]].filetype = "butterfly"
  16. end
  17. local win = vim.api.nvim_open_win(buffers[name], true, {
  18. relative = 'editor',
  19. row = 2,
  20. col = 0,
  21. width = vim.o.columns,
  22. height = vim.o.lines - 2,
  23. style = 'minimal',
  24. border = 'none',
  25. })
  26. vim.fn.setwinvar(win, '&winhl', 'Normal:Normal')
  27. vim.cmd(":startinsert");
  28. if fresh ~= false then
  29. vim.fn.termopen({ 'zsh', '-c', 'while true; do; clear; ' ..
  30. fresh .. '; done;' })
  31. end
  32. end
  33. local close_all = function()
  34. for _, win in pairs(vim.api.nvim_list_wins()) do
  35. local winbuf = vim.api.nvim_win_get_buf(win)
  36. if vim.bo[winbuf].filetype == 'butterfly' then
  37. vim.api.nvim_win_hide(win)
  38. end
  39. end
  40. end
  41. return {
  42. create_term = create_term,
  43. open_term = open_term,
  44. close_all = close_all,
  45. buffers = function()
  46. return buffers
  47. end
  48. }