From d2382b9042f01d4ee9a2be6f7f200d426480d84c Mon Sep 17 00:00:00 2001 From: Andreas Wachs Date: Tue, 22 Aug 2023 13:34:12 +0200 Subject: [PATCH] Enable toggling terminal windows --- lua/custom/plugins/toggleterm.lua | 104 +++++++++++++++++------------- 1 file changed, 59 insertions(+), 45 deletions(-) diff --git a/lua/custom/plugins/toggleterm.lua b/lua/custom/plugins/toggleterm.lua index c67fb41f..6bb9f9ff 100644 --- a/lua/custom/plugins/toggleterm.lua +++ b/lua/custom/plugins/toggleterm.lua @@ -1,52 +1,66 @@ - - return { - { - "akinsho/toggleterm.nvim", - event = "VeryLazy", - cmd = { "ToggleTerm", "TermExec" }, - config = function() - -- Lazygit - local Terminal = require('toggleterm.terminal').Terminal - local defaultTerm = Terminal:new({ cmd = "zsh", hidden = true, direction = "float" }) - local lazygit = Terminal:new({ cmd = "lazygit", hidden = true, direction = "float" }) - local pythonREPL = Terminal:new({ cmd = "python3", hidden = true, direction = "float" }) - local haskellREPL = Terminal:new({ cmd = "ghci", hidden = true, direction = "float" }) + { + "akinsho/toggleterm.nvim", + event = "VeryLazy", + cmd = { "ToggleTerm", "TermExec" }, + config = function() + local Terminal = require('toggleterm.terminal').Terminal + local defaultTerm = Terminal:new({ cmd = "zsh", hidden = true, direction = "float" }) + local lazygit = Terminal:new({ cmd = "lazygit", hidden = true, direction = "float" }) + local pythonREPL = Terminal:new({ cmd = "python3", hidden = true, direction = "float" }) + local haskellREPL = Terminal:new({ cmd = "ghci", hidden = true, direction = "float" }) - function _defaultterm_toggle() - defaultTerm:toggle() - end - function _lazygit_toggle() - lazygit:toggle() - end + function _defaultterm_toggle() + defaultTerm:toggle() + end + function _lazygit_toggle() + lazygit:toggle() + end - function _pythonREPL_toggle() - pythonREPL:toggle() - end + function _pythonREPL_toggle() + pythonREPL:toggle() + end - function _haskellREPL_toggle() - haskellREPL:toggle() - end + function _haskellREPL_toggle() + haskellREPL:toggle() + end - vim.keymap.set('n', 'tt', "lua _defaultterm_toggle()", { desc = 'Toggle Lazygit', noremap = true, silent = true }) - vim.keymap.set('n', '', "lua _defaultterm_toggle()", { desc = 'Toggle Lazygit', noremap = true, silent = true }) - vim.keymap.set('n', 'tl', "lua _lazygit_toggle()", { desc = 'Toggle Lazygit', noremap = true, silent = true }) - vim.keymap.set('n', 'tp', "lua _pythonREPL_toggle()", { desc = 'Toggle Python3 REPL', noremap = true, silent = true }) - vim.keymap.set('n', 'th', "lua _haskellREPL_toggle()", { desc = 'Toggle GHCI', noremap = true, silent = true }) - end, - opts = { - size = 10, - on_create = function() - vim.opt.foldcolumn = "0" - vim.opt.signcolumn = "no" - end, - open_mapping = [[]], - shading_factor = 2, - direction = "float", - float_opts = { - border = "curved", - highlights = { border = "Normal", background = "Dark" }, - }, + function toggle_all() + if defaultTerm:is_open() then + defaultTerm:toggle() + end + if lazygit:is_open() then + lazygit:toggle() + end + if pythonREPL:is_open() then + pythonREPL:toggle() + end + if haskellREPL:is_open() then + haskellREPL:toggle() + end + end + + vim.keymap.set('n', 'tt', "lua _defaultterm_toggle()", { desc = 'Toggle Lazygit', noremap = true, silent = true }) + vim.keymap.set('n', '', "lua _defaultterm_toggle()", { desc = 'Toggle Lazygit', noremap = true, silent = true }) + vim.keymap.set('n', 'tl', "lua _lazygit_toggle()", { desc = 'Toggle Lazygit', noremap = true, silent = true }) + vim.keymap.set('n', 'tp', "lua _pythonREPL_toggle()", { desc = 'Toggle Python3 REPL', noremap = true, silent = true }) + vim.keymap.set('n', 'th', "lua _haskellREPL_toggle()", { desc = 'Toggle GHCI', noremap = true, silent = true }) + + vim.keymap.set('t', '', 'lua toggle_all()', { desc = 'Toggle all visible terminals' }) + end, + opts = { + size = 10, + on_create = function() + vim.opt.foldcolumn = "0" + vim.opt.signcolumn = "no" + end, + open_mapping = [[]], + shading_factor = 2, + direction = "float", + float_opts = { + border = "curved", + highlights = { border = "Normal", background = "Dark" }, + }, + }, }, - }, }