From 1317d6238f089e117e3ed98b3cecc37cc4364675 Mon Sep 17 00:00:00 2001 From: siduck Date: Fri, 22 Jul 2022 16:03:23 +0000 Subject: format files --- lua/nvterm/init.lua | 26 ++++++++++++++++---------- lua/nvterm/terminal.lua | 29 ++++++++++++++++++----------- lua/nvterm/termutil.lua | 2 +- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/lua/nvterm/init.lua b/lua/nvterm/init.lua index 0e53550..d6f3ee6 100644 --- a/lua/nvterm/init.lua +++ b/lua/nvterm/init.lua @@ -28,24 +28,30 @@ local defaults = { local set_behavior = function(behavior) if behavior.autoclose_on_quit.enabled then - local function force_exit () + local function force_exit() require("nvterm.terminal").close_all_terms() - vim.api.nvim_command("qa") + vim.api.nvim_command "qa" end vim.api.nvim_create_autocmd({ "WinClosed" }, { callback = vim.schedule_wrap(function() - local open_terms = require("nvterm.terminal").list_active_terms("win") + local open_terms = require("nvterm.terminal").list_active_terms "win" local non_terms = vim.tbl_filter(function(win) return not vim.tbl_contains(open_terms, win) end, vim.api.nvim_list_wins()) - if not vim.tbl_isempty(non_terms) then return end + if not vim.tbl_isempty(non_terms) then + return + end - if not behavior.autoclose_on_quit.confirm then return force_exit() end + if not behavior.autoclose_on_quit.confirm then + return force_exit() + end - vim.ui.input({ prompt = "Close all terms and quit? (Y/N): " }, function (input) - if not input or not string.lower(input) == "y" then return end + vim.ui.input({ prompt = "Close all terms and quit? (Y/N): " }, function(input) + if not input or not string.lower(input) == "y" then + return + end force_exit() end) end), @@ -54,7 +60,7 @@ local set_behavior = function(behavior) if behavior.close_on_exit then vim.api.nvim_create_autocmd({ "TermClose" }, { callback = function() - vim.schedule_wrap(vim.api.nvim_input("")) + vim.schedule_wrap(vim.api.nvim_input "") end, }) end @@ -62,14 +68,14 @@ local set_behavior = function(behavior) if behavior.auto_insert then vim.api.nvim_create_autocmd({ "BufEnter" }, { callback = function() - vim.cmd("startinsert") + vim.cmd "startinsert" end, pattern = "term://*", }) vim.api.nvim_create_autocmd({ "BufLeave" }, { callback = function() - vim.cmd("stopinsert") + vim.cmd "stopinsert" end, pattern = "term://*", }) diff --git a/lua/nvterm/terminal.lua b/lua/nvterm/terminal.lua index 970bd12..6cdf899 100644 --- a/lua/nvterm/terminal.lua +++ b/lua/nvterm/terminal.lua @@ -1,4 +1,4 @@ -local util = require("nvterm.termutil") +local util = require "nvterm.termutil" local a = vim.api local nvterm = {} local terminals = {} @@ -18,7 +18,9 @@ local function get_type(type, list) end local function get_still_open() - if not terminals.list then return {} end + if not terminals.list then + return {} + end return #terminals.list > 0 and vim.tbl_filter(function(t) return t.open == true end, terminals.list) or {} @@ -50,8 +52,11 @@ end local ensure_and_send = function(cmd, type) terminals = util.verify_terminals(terminals) local function select_term() - if not type then return get_last_still_open() or nvterm.new("horizontal") - else return get_type_last(type) or nvterm.new(type) end + if not type then + return get_last_still_open() or nvterm.new "horizontal" + else + return get_type_last(type) or nvterm.new(type) + end end local term = select_term() a.nvim_chan_send(term.job_id, cmd .. "\n") @@ -68,7 +73,9 @@ local call_and_restore = function(fn, opts) end nvterm.send = function(cmd, type) - if not cmd then return end + if not cmd then + return + end call_and_restore(ensure_and_send, { cmd, type }) end @@ -81,7 +88,7 @@ nvterm.show_term = function(term) term.win = create_term_window(term.type) a.nvim_win_set_buf(term.win, term.buf) terminals.list[term.id].open = true - vim.cmd("startinsert") + vim.cmd "startinsert" end nvterm.get_and_show = function(key, value) @@ -115,7 +122,7 @@ nvterm.new = function(type) 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") + vim.cmd "startinsert" return term end @@ -132,13 +139,13 @@ nvterm.toggle = function(type) end end -nvterm.close_all_terms = function () - for _, buf in ipairs(nvterm.list_active_terms("buf")) do +nvterm.close_all_terms = function() + for _, buf in ipairs(nvterm.list_active_terms "buf") do vim.cmd("bd! " .. tostring(buf)) end end -nvterm.list_active_terms = function (property) +nvterm.list_active_terms = function(property) local terms = get_still_open() if property then return vim.tbl_map(function(t) @@ -148,7 +155,7 @@ nvterm.list_active_terms = function (property) return terms end -nvterm.list_terms = function () +nvterm.list_terms = function() return terminals.list end diff --git a/lua/nvterm/termutil.lua b/lua/nvterm/termutil.lua index 94bad8e..1edf86a 100644 --- a/lua/nvterm/termutil.lua +++ b/lua/nvterm/termutil.lua @@ -20,7 +20,7 @@ end util.execute_type_cmd = function(type, terminals, override) 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) + local dims = type ~= "float" and util.get_split_dims(type, opts.split_ratio) or util.calc_float_opts(opts) dims = override and "" or dims local type_cmds = { horizontal = function() -- cgit v1.2.3-70-g09d2