Skip to content

Commit

Permalink
feat(terminal): better mappings (#3104)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianChiarulli committed Sep 30, 2022
1 parent 9930fc3 commit c389575
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
33 changes: 27 additions & 6 deletions lua/lvim/core/terminal.lua
Expand Up @@ -7,7 +7,6 @@ M.config = function()
-- size can be a number or function which is passed the current terminal
size = 20,
open_mapping = [[<c-\>]],
-- open_mapping = [[<c-t>]],
hide_numbers = true, -- hide the number column in toggleterm buffers
shade_filetypes = {},
shade_terminals = true,
Expand Down Expand Up @@ -41,7 +40,9 @@ M.config = function()
-- lvim.builtin.terminal.execs[#lvim.builtin.terminal.execs+1] = {"gdb", "tg", "GNU Debugger"}
-- TODO: pls add mappings in which key and refactor this
execs = {
{ "lazygit", "<leader>gg", "LazyGit", "float" },
{ vim.o.shell, "<M-1>", "Horizontal Terminal", "horizontal", 10 },
{ vim.o.shell, "<M-2>", "Vertical Terminal", "vertical", 60 },
{ vim.o.shell, "<M-3>", "Float Terminal", "float", nil },
},
}
end
Expand All @@ -58,7 +59,7 @@ M.setup = function()
-- NOTE: unable to consistently bind id/count <= 9, see #2146
count = i + 100,
direction = exec[4] or lvim.builtin.terminal.direction,
size = lvim.builtin.terminal.size,
size = exec[5] or lvim.builtin.terminal.size,
}

M.add_exec(opts)
Expand All @@ -76,15 +77,15 @@ M.add_exec = function(opts)
return
end

vim.keymap.set({ "n" }, opts.keymap, function()
M._exec_toggle { cmd = opts.cmd, count = opts.count, direction = opts.direction }
vim.keymap.set({ "n", "t" }, opts.keymap, function()
M._exec_toggle { cmd = opts.cmd, count = opts.count, direction = opts.direction, size = opts.size }
end, { desc = opts.label, noremap = true, silent = true })
end

M._exec_toggle = function(opts)
local Terminal = require("toggleterm.terminal").Terminal
local term = Terminal:new { cmd = opts.cmd, count = opts.count, direction = opts.direction }
term:toggle(lvim.builtin.terminal.size, opts.direction)
term:toggle(opts.size, opts.direction)
end

---Toggles a log viewer according to log.viewer.layout_config
Expand All @@ -110,4 +111,24 @@ M.toggle_log_view = function(logfile)
log_view:toggle()
end

M.lazygit_toggle = function()
local Terminal = require("toggleterm.terminal").Terminal
local lazygit = Terminal:new {
cmd = "lazygit",
hidden = true,
direction = "float",
float_opts = {
border = "none",
width = 100000,
height = 100000,
},
on_open = function(_)
vim.cmd "startinsert!"
end,
on_close = function(_) end,
count = 99,
}
lazygit:toggle()
end

return M
1 change: 1 addition & 0 deletions lua/lvim/core/which-key.lua
Expand Up @@ -130,6 +130,7 @@ M.config = function()
-- " Debugging
g = {
name = "Git",
g = { "<cmd>lua require 'lvim.core.terminal'.lazygit_toggle()<cr>", "Lazygit" },
j = { "<cmd>lua require 'gitsigns'.next_hunk()<cr>", "Next Hunk" },
k = { "<cmd>lua require 'gitsigns'.prev_hunk()<cr>", "Prev Hunk" },
l = { "<cmd>lua require 'gitsigns'.blame_line()<cr>", "Blame" },
Expand Down

0 comments on commit c389575

Please sign in to comment.