From 9fef7b16ac04edd1132ac6861609c6260aae893a Mon Sep 17 00:00:00 2001 From: pianocomposer321 Date: Mon, 6 Sep 2021 12:35:07 -0500 Subject: [PATCH 1/3] Add gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ddf759d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +tests/ +.workspace From 3e48006bd5c13e5615ab02ae7be5c48da1c63493 Mon Sep 17 00:00:00 2001 From: pianocomposer321 Date: Mon, 6 Sep 2021 12:46:58 -0500 Subject: [PATCH 2/3] Add current_terminal --- lua/consolation/init.lua | 47 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/lua/consolation/init.lua b/lua/consolation/init.lua index c447b62..696c74d 100644 --- a/lua/consolation/init.lua +++ b/lua/consolation/init.lua @@ -1,5 +1,50 @@ -local M = {} +local M = { + current_terminal = nil +} M.Wrapper = require("consolation/wrapper") +function M.set_current_terminal(term) + M.current_terminal = term +end + +function M.setup(opts) + local term = M.Wrapper:new() + term:setup(opts) + + M.set_current_terminal(term) +end + +function M.create() + M.current_terminal:create() +end + +function M.open(args) + M.current_terminal:open(args) +end + +function M.close() + M.current_terminal:close() +end + +function M.kill() + M.current_terminal:kill() +end + +function M.is_open() + return M.current_terminal:is_open() +end + +function M.get_winnr() + return M.current_terminal:get_winnr() +end + +function M.toggle(args) + M.current_terminal:toggle(args) +end + +function M.send_command(args) + M.current_terminal:send_command(args) +end + return M From 6b8f018da283a61c62fbb3e2bcf3a5ccd864c035 Mon Sep 17 00:00:00 2001 From: pianocomposer321 Date: Mon, 6 Sep 2021 12:47:27 -0500 Subject: [PATCH 3/3] Add defaults Currently just for floaterm, probably more to come --- lua/consolation/defaults/floaterm.lua | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 lua/consolation/defaults/floaterm.lua diff --git a/lua/consolation/defaults/floaterm.lua b/lua/consolation/defaults/floaterm.lua new file mode 100644 index 0000000..e6953d9 --- /dev/null +++ b/lua/consolation/defaults/floaterm.lua @@ -0,0 +1,44 @@ +local M = { + width = 0.9, -- Width and height are percentages of the screen size + height = 0.4, + position = "bottom", + name = "runner" +} + +function M.create() + vim.cmd("FloatermNew --name=" .. M.name + .. " --width=" .. M.width + .. " --height=" .. M.height + .. " --position=" .. M.position) +end + +function M.open() + vim.cmd("FloatermShow " .. M.name) +end + +function M.close() + vim.cmd("FloatermHide " .. M.name) +end + +function M.kill() + vim.cmd("FloatermKill " .. M.name) +end + +local runner_bufnr = -1 +function M.toggle() + -- Get a list of the bufnrs of all the terminals managed by floaterm. + local bufnrs = vim.fn['floaterm#buflist#gather']() + + if vim.tbl_contains(bufnrs, runner_bufnr) then -- If the runner is in that list + vim.cmd("FloatermToggle " .. M.name) -- Simply toggle it + else + -- Otherwise, create a new runner and set runner_bufnr to the bufnr of + -- the new terminal buffer + M.create() + runner_bufnr = vim.fn['floaterm#buflist#curr']() + end +end + +vim.g.floaterm_autoclose = 1 + +return M