Skip to content

Commit 7ec41ba

Browse files
committed
feat: add setup function
1 parent 738177f commit 7ec41ba

File tree

3 files changed

+97
-60
lines changed

3 files changed

+97
-60
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
on:
2+
push:
3+
branches:
4+
- master
5+
6+
permissions:
7+
issues: write
8+
contents: write
9+
pull-requests: write
10+
11+
name: release-please
12+
13+
jobs:
14+
release-please:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: googleapis/release-please-action@v4
18+
with:
19+
# this assumes that you have created a personal access token
20+
# (PAT) and configured it as a GitHub action secret named
21+
# `MY_RELEASE_PLEASE_TOKEN` (this secret name is not important).
22+
token: ${{ secrets.GITHUB_TOKEN }}
23+
# this is a built-in strategy in release-please, see "Action Inputs"
24+
# for more options
25+
release-type: simple

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ with [nvim-plug](https://github.com/wsdjeg/nvim-plug)
1212
require('plug').add({
1313
{
1414
'wsdjeg/terminal.nvim',
15-
16-
config = function()
17-
vim.keymap.set('n', "<leader>'", '<cmd>lua require("terminal").open()<cr>', { silent = true })
18-
end,
15+
opts = {
16+
shell = vim.o.shell,
17+
border = { '', '', '', '', '', '', '', '' },
18+
},
19+
keys = {
20+
{ 'n', "<leader>'", '<cmd>lua require("terminal").open()<cr>', { silent = true } },
21+
},
1922
},
2023
})
2124
```

lua/terminal/init.lua

Lines changed: 65 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,65 @@
1-
local M = {}
2-
3-
local winid = -1
4-
local bufid = -1
5-
local fps = 60
6-
7-
local function increase_window()
8-
if vim.api.nvim_win_is_valid(winid) then
9-
local wininfo = vim.api.nvim_win_get_config(winid)
10-
wininfo.height = wininfo.height + 2
11-
vim.api.nvim_win_set_config(winid, { height = wininfo.height })
12-
if wininfo.height <= math.floor(vim.o.lines * 0.4) then
13-
vim.fn.timer_start(math.floor(1000 / fps + 0.5), increase_window, { ['repeat'] = 1 })
14-
end
15-
end
16-
end
17-
local function open_win(cwd)
18-
winid = vim.api.nvim_open_win(0, true, {
19-
relative = 'editor',
20-
width = math.floor(vim.o.columns * 0.8),
21-
height = 1,
22-
row = 1,
23-
col = math.floor(vim.o.columns * 0.1),
24-
border = { '', '', '', '', '', '', '', '' },
25-
})
26-
vim.cmd.enew()
27-
bufid = vim.api.nvim_get_current_buf()
28-
vim.api.nvim_create_autocmd({ 'TermClose' }, {
29-
buffer = bufid,
30-
callback = function()
31-
vim.api.nvim_win_close(winid, true)
32-
vim.cmd('doautocmd WinEnter')
33-
vim.api.nvim_buf_delete(bufid, { force = true, unload = false })
34-
end,
35-
})
36-
vim.cmd('setlocal nobuflisted nonumber norelativenumber')
37-
vim.fn.jobstart(vim.o.shell, { term = true, cwd = cwd or vim.fn.getcwd() })
38-
vim.cmd.startinsert()
39-
vim.api.nvim_set_option_value(
40-
'winhighlight',
41-
'NormalFloat:Normal,FloatBorder:WinSeparator',
42-
{ win = winid }
43-
)
44-
vim.fn.timer_start(math.floor(1000 / fps + 0.5), increase_window, { ['repeat'] = 1 })
45-
end
46-
47-
function M.open(cwd)
48-
if not vim.api.nvim_win_is_valid(winid) then
49-
open_win(cwd)
50-
else
51-
vim.api.nvim_set_current_win(winid)
52-
vim.cmd.startinsert()
53-
end
54-
end
55-
56-
return M
1+
local M = {}
2+
3+
local winid = -1
4+
local bufid = -1
5+
local fps = 60
6+
7+
local config = {
8+
shell = vim.o.shell,
9+
border = { '', '', '', '', '', '', '', '' },
10+
}
11+
12+
local function increase_window()
13+
if vim.api.nvim_win_is_valid(winid) then
14+
local wininfo = vim.api.nvim_win_get_config(winid)
15+
wininfo.height = wininfo.height + 2
16+
vim.api.nvim_win_set_config(winid, { height = wininfo.height })
17+
if wininfo.height <= math.floor(vim.o.lines * 0.4) then
18+
vim.fn.timer_start(math.floor(1000 / fps + 0.5), increase_window, { ['repeat'] = 1 })
19+
end
20+
end
21+
end
22+
local function open_win(cwd)
23+
winid = vim.api.nvim_open_win(0, true, {
24+
relative = 'editor',
25+
width = math.floor(vim.o.columns * 0.8),
26+
height = 1,
27+
row = 1,
28+
col = math.floor(vim.o.columns * 0.1),
29+
border = { '', '', '', '', '', '', '', '' },
30+
})
31+
vim.cmd.enew()
32+
bufid = vim.api.nvim_get_current_buf()
33+
vim.api.nvim_create_autocmd({ 'TermClose' }, {
34+
buffer = bufid,
35+
callback = function()
36+
vim.api.nvim_win_close(winid, true)
37+
vim.cmd('doautocmd WinEnter')
38+
vim.api.nvim_buf_delete(bufid, { force = true, unload = false })
39+
end,
40+
})
41+
vim.cmd('setlocal nobuflisted nonumber norelativenumber')
42+
vim.fn.jobstart(vim.o.shell, { term = true, cwd = cwd or vim.fn.getcwd() })
43+
vim.cmd.startinsert()
44+
vim.api.nvim_set_option_value(
45+
'winhighlight',
46+
'NormalFloat:Normal,FloatBorder:WinSeparator',
47+
{ win = winid }
48+
)
49+
vim.fn.timer_start(math.floor(1000 / fps + 0.5), increase_window, { ['repeat'] = 1 })
50+
end
51+
52+
function M.open(cwd)
53+
if not vim.api.nvim_win_is_valid(winid) then
54+
open_win(cwd)
55+
else
56+
vim.api.nvim_set_current_win(winid)
57+
vim.cmd.startinsert()
58+
end
59+
end
60+
61+
function M.setup(opt)
62+
config = vim.tbl_deep_extend('force', config, opt or {})
63+
end
64+
65+
return M

0 commit comments

Comments
 (0)