From 53d3731ab3fac2381d96261a1870c96a8a0ceeaa Mon Sep 17 00:00:00 2001 From: zbirenbaum Date: Mon, 25 Apr 2022 04:00:31 -0400 Subject: add enable flag for new mappings --- lua/nvterm/init.lua | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/lua/nvterm/init.lua b/lua/nvterm/init.lua index 01bf487..9a1d930 100644 --- a/lua/nvterm/init.lua +++ b/lua/nvterm/init.lua @@ -27,11 +27,11 @@ local defaults = { vertical = "", }, new = { - float = "", horizontal = "", vertical = "", }, - } + }, + enable_new_mappings = false, } local set_behavior = function(behavior) @@ -54,7 +54,7 @@ local set_behavior = function(behavior) end end -M.create_mapping = function(method, map_table, opts) +M.create_mappings = function(method, map_table, opts) opts = opts or {} vim.tbl_deep_extend("force", { noremap = true, silent = true }, opts) for type, mapping in pairs(map_table) do @@ -66,20 +66,30 @@ end local setup_mappings = function (mappings) for method, map_table in pairs(mappings) do - M.create_mapping(method, map_table) + M.create_mappings(method, map_table) + end +end + +local map_config_shortcuts = function (config, location, shortcut) + for _, key in ipairs(shortcut) do + config[key] = config[key] or {} + vim.tbl_deep_extend("force", location[key], config[key]) + config[key] = nil end + return config end M.setup = function (config) config = config and vim.tbl_deep_extend("force", defaults, config) or defaults - local types = {'horizontal', 'vertical', 'float'} - for _, type in pairs(types) do - if config[type] then - config.terminals.type_opts[type] = vim.tbl_deep_extend("force", config.terminals.type_opts[type], config[type]) - config[type] = nil - end + local shortcuts = { + { config.terminals.type_opts, { 'horizontal', 'vertical', 'float' } }, + { config.mappings, { 'toggle', 'new' } }, + } + for _, shortcut_map in ipairs(shortcuts) do + map_config_shortcuts(config, shortcut_map[1], shortcut_map[2]) end set_behavior(config.behavior) + config.mappings.new = config.enable_new_mappings or nil setup_mappings(config.mappings) require("nvterm.terminal").init(config.terminals) end -- cgit v1.2.3-70-g09d2