From 722c2468160ef9b5f090f4a57a8a6eef11e95bde Mon Sep 17 00:00:00 2001 From: zbirenbaum Date: Mon, 25 Apr 2022 03:32:26 -0400 Subject: add new mappings and simplify more --- lua/nvterm/init.lua | 23 ++++++++++++++--------- lua/nvterm/terminal.lua | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lua/nvterm/init.lua b/lua/nvterm/init.lua index e89b04e..253eccb 100644 --- a/lua/nvterm/init.lua +++ b/lua/nvterm/init.lua @@ -1,7 +1,5 @@ local M = {} -local terminal = require("nvterm.terminal") - local defaults = { terminals = { list = {}, @@ -27,7 +25,12 @@ local defaults = { float = "", horizontal = "", vertical = "", - } + }, + new = { + float = "", + horizontal = "", + vertical = "", + }, } } @@ -53,11 +56,13 @@ end local create_mappings = function (mappings) local opts = { noremap = true, silent = true } - for type, mapping in ipairs(mappings.toggle) do - vim.keymap.set({'n', 't'}, mapping, function () - terminal.new_or_toggle(type) - end, opts) - end + vim.tbl_map(function(method) + for type, mapping in pairs(method) do + vim.keymap.set({'n', 't'}, mapping, function () + require("nvterm.terminal")[method](type) + end, opts) + end + end, mappings) end M.setup = function (config) @@ -71,7 +76,7 @@ M.setup = function (config) end set_behavior(config.behavior) create_mappings(config.mappings) - terminal.init(config.terminals) + require("nvterm.terminal").init(config.terminals) end return M diff --git a/lua/nvterm/terminal.lua b/lua/nvterm/terminal.lua index a5103db..3915158 100644 --- a/lua/nvterm/terminal.lua +++ b/lua/nvterm/terminal.lua @@ -96,7 +96,7 @@ nvterm.new = function (type) return term end -nvterm.new_or_toggle = function (type) +nvterm.toggle = function (type) terminals = util.verify_terminals(terminals) local term = get_type_last(type) if not term then term = nvterm.new(type) -- cgit v1.2.3-70-g09d2