From 3c006e8b441d6300f41291f334cfc5677269cd71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Tue, 10 May 2022 20:36:47 +0200 Subject: [PATCH] Add basic floating terminal --- symlinks/config/nvim/plugin/popupterm.lua | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 symlinks/config/nvim/plugin/popupterm.lua diff --git a/symlinks/config/nvim/plugin/popupterm.lua b/symlinks/config/nvim/plugin/popupterm.lua new file mode 100644 index 0000000..d119878 --- /dev/null +++ b/symlinks/config/nvim/plugin/popupterm.lua @@ -0,0 +1,50 @@ +-- Popupterm - get a popup with terminal buffer +local popup = require("nui.popup") +local event = require("nui.utils.autocmd").event + +local last_term_win + +local function popup_terminal() + if last_term_win then + last_term_win:show() + return + end + + local win = popup({ + enter = true, + focusable = true, + border = { + style = "rounded", + }, + position = "50%", + size = { + width = "80%", + height = "60%", + }, + }) + + -- mount/open the component + win:mount() + + vim.cmd("edit term://" .. vim.env.SHELL) + + -- map keys + win:map("n", "", function(_) + win:hide() + end, { noremap = true }) + + -- unmount component when cursor leaves buffer + win:on(event.BufLeave, function() + win:hide() + end) + + win:on(event.BufDelete, function() + last_term_win = nil + end) + + last_term_win = win +end + +vim.api.nvim_create_user_command("PopupTerm", function() + popup_terminal() +end, {})