From 794256b2f108d6dfb48b0be7a2775a1b28b24ee6 Mon Sep 17 00:00:00 2001 From: zbirenbaum Date: Fri, 22 Apr 2022 01:21:26 -0400 Subject: add term_opts config shortcut --- README.md | 37 +++++++++++++++++++++++++++++++++++++ lua/nvterm/init.lua | 7 +++++++ 2 files changed, 44 insertions(+) diff --git a/README.md b/README.md index 1cc4152..9ec0a06 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,43 @@ require("nvterm").setup({ } }) ``` +A shortcut is available for setting options of the different terminal types: +``` +require("nvterm").setup({ + float = { + relative = 'editor', + row = 0.3, + col = 0.25, + width = 0.5, + height = 0.4, + border = "single", + }, + horizontal = { location = "rightbelow", split_ratio = .3, }, + vertical = { location = "rightbelow", split_ratio = .5 }, +}) +``` + +is equivalent to: + +``` +require("nvterm").setup({ + terminals = { + type_opts = { + float = { + relative = 'editor', + row = 0.3, + col = 0.25, + width = 0.5, + height = 0.4, + border = "single", + }, + horizontal = { location = "rightbelow", split_ratio = .3, }, + vertical = { location = "rightbelow", split_ratio = .5 }, + } + } +}) +``` + ### Additional Functionality: NvTerm provides an api for you to send commands to the terminal. You can create different ones for different filetypes like so: diff --git a/lua/nvterm/init.lua b/lua/nvterm/init.lua index 5feda9f..c49e09d 100644 --- a/lua/nvterm/init.lua +++ b/lua/nvterm/init.lua @@ -60,6 +60,13 @@ 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 ipairs(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 + end set_behavior(config.behavior) create_mappings(config.mappings) terminal.init(config.terminals) -- cgit v1.2.3-70-g09d2