Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tests/
.workspace
44 changes: 44 additions & 0 deletions lua/consolation/defaults/floaterm.lua
Original file line number Diff line number Diff line change
@@ -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
47 changes: 46 additions & 1 deletion lua/consolation/init.lua
Original file line number Diff line number Diff line change
@@ -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