-
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathinit.lua
More file actions
69 lines (54 loc) · 1.32 KB
/
init.lua
File metadata and controls
69 lines (54 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
local Term = require('FTerm.terminal')
local M = {}
local t = Term:new()
---Creates a custom terminal
---@param cfg Config
---@return Term
function M:new(cfg)
return Term:new():setup(cfg)
end
---(Optional) Configure the default terminal
---@param cfg Config
function M.setup(cfg)
t:setup(cfg)
end
---Opens the default terminal
function M.open()
t:open()
end
---Closes the default terminal window but preserves the actual terminal session
function M.close()
t:close()
end
---Exits the terminal session
function M.exit()
t:close(true)
end
---Toggles the default terminal
function M.toggle()
t:toggle()
end
---Run a arbitrary command inside the default terminal
---@param cmd Command
function M.run(cmd)
if not cmd then
return vim.notify('FTerm: Please provide a command to run', vim.log.levels.ERROR)
end
t:run(cmd)
end
---Returns the job id of the terminal if it exists
function M.get_job_id()
return t.terminal
end
---To create a scratch (use and throw) terminal. Like those good ol' C++ build terminal.
---@param cfg Config
function M.scratch(cfg)
if not cfg then
return vim.notify('FTerm: Please provide configuration for scratch terminal', vim.log.levels.ERROR)
end
if cfg.auto_close == nil then
cfg.auto_close = false
end
M:new(cfg):open()
end
return M