Skip to content

Commit dfb5fb8

Browse files
authored
Add new fixed_width & fixed_height settings (#24)
They control whether terminal size should be preserved on new splits
1 parent 0c7dc9b commit dfb5fb8

12 files changed

Lines changed: 112 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
66

77
- Fix: Correctly center floating terminal when no borders are used.
88
- Set terminal window as `nolist`.
9+
- Add `fixed_height` & `fixed_width` options to control whether terminal size should be preserved on new splits.
910

1011
## 1.0.0 - 2025-11-21
1112

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ require("ergoterm").setup({
7171
| `cleanup_on_failure` | `boolean` | `false` | Cleanup terminal when process exits with non-zero code |
7272
| `cleanup_on_success` | `boolean` | `true` | Cleanup terminal when process exits with code 0 |
7373
| `default_action` | `function` | `function(term) term:focus() end` | Action performed when selecting terminal with default picker action |
74+
| `fixed_height` | boolean | `true` | Keep the terminal height when new horizontal splits are opened (it depends on vim's `equalalways` being set) |
75+
| `fixed_width` | boolean | `true` | Keep the terminal width when new vertical splits are opened (it depends on vim's `equalalways` being set) |
7476
| `float_opts` | `table` | See below | Floating window configuration options |
7577
| `↳ border` | `string` | `"single"` | Border style (see `:help nvim_open_win()`) |
7678
| `↳ col` | `number` | Auto-centered | Column position |

doc/ergoterm.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,16 @@ default_action *ergoterm-default_action*
416416
Default: `function(term) term:focus() end`
417417
Action performed when selecting terminal with default picker action
418418

419+
fixed_height *ergoterm-fixed_height*
420+
Type: `boolean`
421+
Default: `true`
422+
Keep the terminal height when new horizontal splits are opened (it depends on vim's `equalalways` being set)
423+
424+
fixed_width *ergoterm-fixed_width*
425+
Type: `boolean`
426+
Default: `true`
427+
Keep the terminal width when new vertical splits are opened (it depends on vim's `equalalways` being set)
428+
419429
float_opts *ergoterm-float_opts*
420430
Type: `table`
421431
Floating window configuration options (see |nvim_open_win()|)

lua/ergoterm/commandline.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ end
5151
---@field watch_files boolean?
5252
---@field persist_mode boolean?
5353
---@field persist_size boolean?
54+
---@field fixed_width boolean?
55+
---@field fixed_height boolean?
5456
---@field auto_list boolean?
5557
---@field start_in_insert boolean?
5658
---@field sticky boolean?
@@ -102,6 +104,8 @@ function M.parse(args)
102104
watch_files = true,
103105
persist_mode = true,
104106
persist_size = true,
107+
fixed_width = true,
108+
fixed_height = true,
105109
auto_list = true,
106110
start_in_insert = true,
107111
sticky = true,
@@ -295,6 +299,10 @@ M._all_options = {
295299

296300
persist_size = M._boolean_options,
297301

302+
fixed_width = M._boolean_options,
303+
304+
fixed_height = M._boolean_options,
305+
298306
auto_list = M._boolean_options,
299307

300308
start_in_insert = M._boolean_options,
@@ -375,6 +383,8 @@ M._term_new_options = {
375383
watch_files = M._all_options.watch_files,
376384
persist_mode = M._all_options.persist_mode,
377385
persist_size = M._all_options.persist_size,
386+
fixed_width = M._all_options.fixed_width,
387+
fixed_height = M._all_options.fixed_height,
378388
auto_list = M._all_options.auto_list,
379389
["env."] = M._all_options["env."],
380390
start_in_insert = M._all_options.start_in_insert,
@@ -410,6 +420,8 @@ M._term_update_options = {
410420
watch_files = M._all_options.watch_files,
411421
persist_mode = M._all_options.persist_mode,
412422
persist_size = M._all_options.persist_size,
423+
fixed_width = M._all_options.fixed_width,
424+
fixed_height = M._all_options.fixed_height,
413425
auto_list = M._all_options.auto_list,
414426
start_in_insert = M._all_options.start_in_insert,
415427
sticky = M._all_options.sticky,

lua/ergoterm/commands.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ function M.new(args)
2828
vim.validate("watch_files", parsed.watch_files, "boolean", true)
2929
vim.validate("persist_mode", parsed.persist_mode, "boolean", true)
3030
vim.validate("persist_size", parsed.persist_size, "boolean", true)
31+
vim.validate("fixed_width", parsed.fixed_width, "boolean", true)
32+
vim.validate("fixed_height", parsed.fixed_height, "boolean", true)
3133
vim.validate("auto_list", parsed.auto_list, "boolean", true)
3234
vim.validate("start_in_insert", parsed.start_in_insert, "boolean", true)
3335
vim.validate("sticky", parsed.sticky, "boolean", true)
@@ -50,6 +52,8 @@ function M.new(args)
5052
watch_files = parsed.watch_files,
5153
persist_mode = parsed.persist_mode,
5254
persist_size = parsed.persist_size,
55+
fixed_width = parsed.fixed_width,
56+
fixed_height = parsed.fixed_height,
5357
auto_list = parsed.auto_list,
5458
start_in_insert = parsed.start_in_insert,
5559
sticky = parsed.sticky,
@@ -175,6 +179,8 @@ function M.update(args, bang, picker)
175179
vim.validate("watch_files", parsed.watch_files, "boolean", true)
176180
vim.validate("persist_mode", parsed.persist_mode, "boolean", true)
177181
vim.validate("persist_size", parsed.persist_size, "boolean", true)
182+
vim.validate("fixed_width", parsed.fixed_width, "boolean", true)
183+
vim.validate("fixed_height", parsed.fixed_height, "boolean", true)
178184
vim.validate("auto_list", parsed.auto_list, "boolean", true)
179185
vim.validate("start_in_insert", parsed.start_in_insert, "boolean", true)
180186
vim.validate("sticky", parsed.sticky, "boolean", true)

lua/ergoterm/config.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ M.NULL_CALLBACK = function(...) end
7171
---@field show_on_failure boolean?
7272
---@field persist_mode boolean?
7373
---@field persist_size boolean?
74+
---@field fixed_width boolean?
75+
---@field fixed_height boolean?
7476
---@field auto_list boolean?
7577
---@field size Size?
7678
---@field start_in_insert boolean?
@@ -114,6 +116,8 @@ local config = {
114116
float_winblend = 10,
115117
persist_mode = false,
116118
persist_size = true,
119+
fixed_width = true,
120+
fixed_height = true,
117121
auto_list = true,
118122
sticky = false,
119123
size = {

lua/ergoterm/instance.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ local utils = require("ergoterm.utils")
7979
---@field float_winblend number
8080
---@field persist_mode boolean
8181
---@field persist_size boolean
82+
---@field fixed_width boolean
83+
---@field fixed_height boolean
8284
---@field auto_list boolean
8385
---@field size Size
8486
---@field start_in_insert boolean
@@ -132,6 +134,8 @@ function Terminal:new(args)
132134
term.float_winblend = term.float_winblend or config.get("terminal_defaults.float_winblend")
133135
term.persist_mode = vim.F.if_nil(term.persist_mode, config.get("terminal_defaults.persist_mode"))
134136
term.persist_size = vim.F.if_nil(term.persist_size, config.get("terminal_defaults.persist_size"))
137+
term.fixed_width = vim.F.if_nil(term.fixed_width, config.get("terminal_defaults.fixed_width"))
138+
term.fixed_height = vim.F.if_nil(term.fixed_height, config.get("terminal_defaults.fixed_height"))
135139
if term.selectable ~= nil then
136140
utils.notify(
137141
"[ergoterm] `selectable` option is deprecated and will be removed soon. Use `auto_list` instead.",
@@ -533,9 +537,9 @@ function Terminal:_compute_float_win_config()
533537
float_opts.height = float_opts.height or math.ceil(math.min(vim.o.lines, math.max(20, vim.o.lines - 5)))
534538
float_opts.width = float_opts.width or math.ceil(math.min(vim.o.columns, math.max(80, vim.o.columns - 10)))
535539
float_opts.row = float_opts.row or
536-
math.ceil(vim.o.lines - float_opts.height) * 0.5 - (float_opts.border ~= 'none' and 1 or 0)
540+
math.ceil(vim.o.lines - float_opts.height) * 0.5 - (float_opts.border ~= 'none' and 1 or 0)
537541
float_opts.col = float_opts.col or
538-
math.ceil(vim.o.columns - float_opts.width) * 0.5 - (float_opts.border ~= 'none' and 1 or 0)
542+
math.ceil(vim.o.columns - float_opts.width) * 0.5 - (float_opts.border ~= 'none' and 1 or 0)
539543
float_opts.zindex = (vim.api.nvim_win_get_config(0).zindex or 0) + 1
540544
return float_opts
541545
end

lua/ergoterm/instance/open.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
local utils = require("ergoterm.utils")
55

66
local NEW_WINDOW_LAYOUTS = { "above", "below", "left", "right", "float" }
7+
local HORIZONTAL_LAYOUTS = { "above", "below" }
8+
local VERTICAL_LAYOUTS = { "left", "right" }
79
local TAB_LAYOUT = "tab"
810
local CURRENT_WINDOW_LAYOUT = "window"
911

@@ -95,6 +97,14 @@ function M._set_win_options(term)
9597
vim.api.nvim_set_option_value("list", false, { scope = "local", win = window })
9698
vim.api.nvim_set_option_value("foldmethod", "manual", { scope = "local", win = window })
9799
vim.api.nvim_set_option_value("foldtext", "foldtext()", { scope = "local", win = window })
100+
101+
if (term.fixed_height and vim.tbl_contains(HORIZONTAL_LAYOUTS, term._state.layout)) then
102+
vim.api.nvim_set_option_value("winfixheight", true, { scope = "local", win = window })
103+
end
104+
if (term.fixed_width and vim.tbl_contains(VERTICAL_LAYOUTS, term._state.layout)) then
105+
vim.api.nvim_set_option_value("winfixwidth", true, { scope = "local", win = window })
106+
end
107+
98108
if term._state.layout == "float" then
99109
M._set_float_options(term)
100110
end

lua/ergoterm/instance/update.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ local ALLOWED_SETTINGS = {
1717
"env",
1818
"name",
1919
"meta",
20+
"fixed_width",
21+
"fixed_height",
2022
"float_props",
2123
"float_winblend",
2224
"persist_mode",
@@ -76,9 +78,9 @@ end
7678
---@param deep_merge boolean
7779
function M._update_setting(term, setting, value, deep_merge)
7880
local should_merge = deep_merge
79-
and type(value) == "table"
80-
and type(term[setting]) == "table"
81-
and not vim.islist(value)
81+
and type(value) == "table"
82+
and type(term[setting]) == "table"
83+
and not vim.islist(value)
8284

8385
if should_merge then
8486
term[setting] = vim.tbl_deep_extend("force", term[setting], value)

spec/ergoterm/commandline_spec.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ describe("commandline.term_new_complete", function()
207207
assert.is_true(vim.tbl_contains(result, "float_opts.width="))
208208
assert.is_true(vim.tbl_contains(result, "float_opts.height="))
209209
assert.is_true(vim.tbl_contains(result, "float_opts.title="))
210+
assert.is_true(vim.tbl_contains(result, "fixed_width="))
211+
assert.is_true(vim.tbl_contains(result, "fixed_height="))
210212
assert.is_true(vim.tbl_contains(result, "tags="))
211213
assert.is_true(vim.tbl_contains(result, "meta.="))
212214
assert.is_true(vim.tbl_contains(result, "env.="))
@@ -332,6 +334,8 @@ describe("commandline.term_update_complete", function()
332334
assert.is_true(vim.tbl_contains(result, "float_opts.width="))
333335
assert.is_true(vim.tbl_contains(result, "float_opts.height="))
334336
assert.is_true(vim.tbl_contains(result, "float_opts.title="))
337+
assert.is_true(vim.tbl_contains(result, "fixed_width="))
338+
assert.is_true(vim.tbl_contains(result, "fixed_height="))
335339
assert.is_true(vim.tbl_contains(result, "tags="))
336340
assert.is_true(vim.tbl_contains(result, "meta.="))
337341
end)

0 commit comments

Comments
 (0)