Skip to content

Commit f1f917b

Browse files
authored
feat: add option to not resize the terminal (#253)
Co-authored-by: Denzel <>
1 parent 4be3c22 commit f1f917b

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ require("cmake-tools").setup {
9999
single_terminal_per_instance = true, -- Single viewport, multiple windows
100100
single_terminal_per_tab = true, -- Single viewport per tab
101101
keep_terminal_static_location = true, -- Static location of the viewport if avialable
102+
auto_resize = true, -- Resize the terminal if it already exists
102103

103104
-- Running Tasks
104105
start_insert = false, -- If you want to enter terminal with :startinsert upon using :CMakeRun
@@ -146,6 +147,7 @@ require("cmake-tools").setup {
146147
single_terminal_per_instance = true, -- Single viewport, multiple windows
147148
single_terminal_per_tab = true, -- Single viewport per tab
148149
keep_terminal_static_location = true, -- Static location of the viewport if avialable
150+
auto_resize = true, -- Resize the terminal if it already exists
149151

150152
-- Running Tasks
151153
start_insert = false, -- If you want to enter terminal with :startinsert upon using :CMakeRun

lua/cmake-tools/const.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ local const = {
6262
single_terminal_per_instance = true, -- Single instance, multiple windows
6363
single_terminal_per_tab = true, -- Single instance per tab
6464
keep_terminal_static_location = true, -- Static location of the instance if avialable
65+
auto_resize = true, -- Resize the terminal if it already exists
6566

6667
-- Running Tasks
6768
start_insert = false, -- If you want to enter terminal with :startinsert upon using :CMakeRun
@@ -105,6 +106,7 @@ local const = {
105106
single_terminal_per_instance = true, -- Single instance, multiple windows
106107
single_terminal_per_tab = true, -- Single instance per tab
107108
keep_terminal_static_location = true, -- Static location of the instance if avialable
109+
auto_resize = true, -- Resize the terminal if it already exists
108110

109111
-- Running Tasks
110112
start_insert = false, -- If you want to enter terminal with :startinsert upon using :CMakeRun

lua/cmake-tools/terminal.lua

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ function _terminal.show(opts)
4040
if win_id ~= -1 then
4141
-- The window is alive, so we set buffer in window
4242
vim.api.nvim_win_set_buf(win_id, _terminal.id)
43-
if opts.split_direction == "horizontal" then
44-
vim.api.nvim_win_set_height(win_id, opts.split_size)
45-
else
46-
vim.api.nvim_win_set_width(win_id, opts.split_size)
43+
if opts.auto_resize then
44+
if opts.split_direction == "horizontal" then
45+
vim.api.nvim_win_set_height(win_id, opts.split_size)
46+
else
47+
vim.api.nvim_win_set_width(win_id, opts.split_size)
48+
end
4749
end
4850
elseif win_id >= -1 then
4951
-- The window is not active, we need to create a new buffer
@@ -63,6 +65,11 @@ function _terminal.new_instance(term_name, opts)
6365
vim.cmd(":" .. opts.split_direction .. " " .. opts.split_size .. "sp | :term") -- Creater terminal in a split
6466
-- local new_name = vim.fn.fnamemodify(term_name, ":t") -- Extract only the terminal name and reassign it
6567
vim.api.nvim_buf_set_name(vim.api.nvim_get_current_buf(), term_name) -- Set the buffer name
68+
if opts.split_direction == "horizontal" then
69+
vim.wo.winfixheight = true
70+
else
71+
vim.wo.winfixwidth = true
72+
end
6673
vim.cmd(":setlocal laststatus=3") -- Let there be a single status/lualine in the neovim instance
6774

6875
-- Renamming a terminal buffer creates a new hidden buffer, so duplicate terminals need to be deleted
@@ -165,10 +172,12 @@ function _terminal.send_data_to_terminal(buffer_idx, cmd, opts)
165172
if opts and opts.win_id ~= -1 then
166173
-- The window is alive, so we set buffer in window
167174
vim.api.nvim_win_set_buf(opts.win_id, buffer_idx)
168-
if opts.split_direction == "horizontal" then
169-
vim.api.nvim_win_set_height(opts.win_id, opts.split_size)
170-
else
171-
vim.api.nvim_win_set_width(opts.win_id, opts.split_size)
175+
if opts.auto_resize then
176+
if opts.split_direction == "horizontal" then
177+
vim.api.nvim_win_set_height(opts.win_id, opts.split_size)
178+
else
179+
vim.api.nvim_win_set_width(opts.win_id, opts.split_size)
180+
end
172181
end
173182
elseif opts and opts.win_id >= -1 then
174183
-- The window is not active, we need to create a new buffer
@@ -628,6 +637,7 @@ function _terminal.run(cmd, env_script, env, args, cwd, opts, on_exit, on_output
628637
split_size = opts.split_size,
629638
start_insert = opts.start_insert,
630639
focus = opts.focus,
640+
auto_resize = opts.auto_resize,
631641
do_not_add_newline = opts.do_not_add_newline,
632642
}
633643
)

0 commit comments

Comments
 (0)