From 8c5d64437f41808a31496e5ae68cd696d0b702ff Mon Sep 17 00:00:00 2001 From: zbirenbaum Date: Tue, 31 May 2022 17:57:31 -0400 Subject: Fix #11 --- lua/nvterm/terminal.lua | 12 ++++++------ lua/nvterm/termutil.lua | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lua/nvterm/terminal.lua b/lua/nvterm/terminal.lua index b893bbb..a86f8bb 100644 --- a/lua/nvterm/terminal.lua +++ b/lua/nvterm/terminal.lua @@ -18,9 +18,9 @@ local function get_type(type, list) end local function get_still_open() - return vim.tbl_filter(function(t) + return #terminals.list > 0 and vim.tbl_filter(function(t) return t.open == true - end, terminals.list) + end, terminals.list) or {} end local function get_last_still_open() @@ -39,7 +39,7 @@ local function get_term(key, value) end local create_term_window = function(type) - local existing = #get_type(type, get_still_open()) > 0 + local existing = terminals.list and #get_type(type, get_still_open()) > 0 util.execute_type_cmd(type, terminals, existing) vim.wo.relativenumber = false vim.wo.number = false @@ -87,12 +87,12 @@ nvterm.show_term = function(term) end nvterm.get_and_show = function(key, value) - term = get_term(key, value) + local term = get_term(key, value) nvterm.show_term(term) end nvterm.get_and_hide = function(key, value) - term = get_term(key, value) + local term = get_term(key, value) nvterm.hide_term(term) end @@ -114,7 +114,7 @@ nvterm.new = function(type) a.nvim_win_set_buf(win, buf) local job_id = vim.fn.termopen(vim.o.shell) - local id = #terminals + 1 + local id = #terminals.list + 1 local term = { id = id, win = win, buf = buf, open = true, type = type, job_id = job_id } terminals.list[id] = term vim.cmd("startinsert") diff --git a/lua/nvterm/termutil.lua b/lua/nvterm/termutil.lua index 94bad8e..e84892c 100644 --- a/lua/nvterm/termutil.lua +++ b/lua/nvterm/termutil.lua @@ -19,6 +19,7 @@ util.get_split_dims = function(type, ratio) end util.execute_type_cmd = function(type, terminals, override) + print(terminals.type_opts) local opts = terminals.type_opts[type] local dims = type ~= 'float' and util.get_split_dims(type, opts.split_ratio) or util.calc_float_opts(opts) dims = override and "" or dims -- cgit v1.2.3-70-g09d2