Skip to content

Commit 0179ba4

Browse files
Add scrollback setting to configure terminal scrollback buffer size
1 parent 17911bb commit 0179ba4

11 files changed

Lines changed: 37 additions & 3 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
- BREAKING: `selectable` option has been deprecated in favor of `auto_list`.
88
- BREAKING: Rename `.get_last_focused()` to `.get_target_for_bang()`.
9+
- Added `scrollback` setting to configure terminal scrollback buffer size.
910

1011
## 0.9.0 - 2025-11-07
1112

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ All options default to values from your configuration:
267267
- `clear_env` - Use clean environment for the job
268268
- `cleanup_on_success` - Cleanup terminal when process exits successfully (exit code 0)
269269
- `cleanup_on_failure` - Cleanup terminal when process exits with failure (exit code non-zero)
270+
- `scrollback` - Number of lines to keep in scrollback buffer.
270271
- `show_on_success` - Open terminal window when process exits successfully (exit code 0). Requires `cleanup_on_success` to be `false`.
271272
- `show_on_failure` - Open terminal window when process exits with failure (exit code non-zero). Requires `cleanup_on_failure` to be `false`.
272273
- `default_action` - Function to invoke when selecting terminal in picker with `<Enter>`

doc/ergoterm.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,13 @@ terminal_defaults.cleanup_on_failure ~
371371

372372
Close terminal window when the job process exits with failure (exit code non-zero).
373373

374+
*ergoterm-scrollback*
375+
terminal_defaults.scrollback ~
376+
Default: `vim.o.scrollback`
377+
Type: `number`
378+
379+
Number of lines to keep in terminal scrollback buffer.
380+
374381
*ergoterm-show_on_success*
375382
terminal_defaults.show_on_success ~
376383
Default: `false`

lua/ergoterm/commandline.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ end
5454
---@field sticky boolean?
5555
---@field cleanup_on_success boolean?
5656
---@field cleanup_on_failure boolean?
57+
---@field scrollback number?
5758
---@field show_on_success boolean?
5859
---@field show_on_failure boolean?
5960
---@field text string?
@@ -298,6 +299,8 @@ M._all_options = {
298299

299300
cleanup_on_failure = M._boolean_options,
300301

302+
scrollback = function() return {} end,
303+
301304
show_on_success = M._boolean_options,
302305

303306
show_on_failure = M._boolean_options,
@@ -369,6 +372,7 @@ M._term_new_options = {
369372
sticky = M._all_options.sticky,
370373
cleanup_on_success = M._all_options.cleanup_on_success,
371374
cleanup_on_failure = M._all_options.cleanup_on_failure,
375+
scrollback = M._all_options.scrollback,
372376
show_on_success = M._all_options.show_on_success,
373377
show_on_failure = M._all_options.show_on_failure,
374378
["size.below"] = M._all_options["size.below"],

lua/ergoterm/commands.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ end
145145
---Updates terminal configuration after creation
146146
---
147147
---Allows modification of terminal settings without recreating the terminal.
148-
---Updatable fields include layout, name, auto_scroll, persist_mode, persist_size,
149-
---auto_list, and start_in_insert. Changes take effect immediately.
148+
---Use autocompletion to see which settings can be updated.
150149
---
151150
---Bang mode (!) targets the last focused terminal directly.
152151
---Target option selects a terminal by name.

lua/ergoterm/config.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ M.NULL_CALLBACK = function(...) end
6666
---@field on_open on_open?
6767
---@field on_stop on_stop?
6868
---@field on_start on_start?
69+
---@field scrollback number?
6970
---@field show_on_success boolean?
7071
---@field show_on_failure boolean?
7172
---@field persist_mode boolean?
@@ -130,6 +131,7 @@ local config = {
130131
on_start = M.NULL_CALLBACK,
131132
on_job_stderr = M.NULL_CALLBACK,
132133
on_job_stdout = M.NULL_CALLBACK,
134+
scrollback = vim.o.scrollback,
133135
show_on_success = false,
134136
show_on_failure = false,
135137
shell = vim.o.shell,

lua/ergoterm/instance.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ local utils = require("ergoterm.utils")
9393
---@field on_open on_open
9494
---@field on_start on_start
9595
---@field on_stop on_stop
96+
---@field scrollback number
9697
---@field show_on_success boolean
9798
---@field show_on_failure boolean
9899
---@field tags string[]
@@ -152,6 +153,7 @@ function Terminal:new(args)
152153
term.on_open = vim.F.if_nil(term.on_open, config.get("terminal_defaults.on_open"))
153154
term.on_start = vim.F.if_nil(term.on_start, config.get("terminal_defaults.on_start"))
154155
term.on_stop = vim.F.if_nil(term.on_stop, config.get("terminal_defaults.on_stop"))
156+
term.scrollback = term.scrollback or config.get("terminal_defaults.scrollback")
155157
term.show_on_success = vim.F.if_nil(term.show_on_success, config.get("terminal_defaults.show_on_success"))
156158
term.show_on_failure = vim.F.if_nil(term.show_on_failure, config.get("terminal_defaults.show_on_failure"))
157159
term.tags = term.tags or vim.tbl_deep_extend("keep", {}, config.get("terminal_defaults.tags") or {})

lua/ergoterm/instance/start.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ function M.start(term)
1717
term._state.dir = term:_compute_dir()
1818
term._state.bufnr = vim.api.nvim_create_buf(false, false)
1919
term._state.has_been_started = true
20+
M._set_buffer_options(term)
2021
vim.api.nvim_buf_call(term._state.bufnr, function()
2122
term._state.job_id = M._start_job(term)
2223
end)
2324
M._setup_buffer_autocommands(term)
24-
M._set_buffer_options(term)
2525
term:on_start()
2626
end
2727
return term
@@ -74,6 +74,7 @@ function M._set_buffer_options(term)
7474
vim.api.nvim_set_option_value("filetype", FILETYPE, { scope = "local", buf = bufnr })
7575
vim.api.nvim_set_option_value("buflisted", false, { scope = "local", buf = bufnr })
7676
vim.api.nvim_set_option_value("bufhidden", "hide", { scope = "local", buf = bufnr })
77+
vim.api.nvim_set_option_value("scrollback", term.scrollback, { scope = "local", buf = bufnr })
7778
end
7879

7980
return setmetatable(M, {

spec/ergoterm/commandline_spec.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ describe("commandline.term_new_complete", function()
181181
assert.is_true(vim.tbl_contains(result, "sticky="))
182182
assert.is_true(vim.tbl_contains(result, "cleanup_on_success="))
183183
assert.is_true(vim.tbl_contains(result, "cleanup_on_failure="))
184+
assert.is_true(vim.tbl_contains(result, "scrollback="))
185+
assert.is_true(vim.tbl_contains(result, "show_on_success="))
186+
assert.is_true(vim.tbl_contains(result, "show_on_failure="))
184187
assert.is_true(vim.tbl_contains(result, "size.below="))
185188
assert.is_true(vim.tbl_contains(result, "size.above="))
186189
assert.is_true(vim.tbl_contains(result, "size.left="))

spec/ergoterm/instance/start_spec.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ describe(".start", function()
154154
assert.equal("hide", vim.bo[term:get_state("bufnr")].bufhidden)
155155
end)
156156

157+
it("sets the buffer scrollback from term's setting", function()
158+
local term = Terminal:new({ scrollback = 5000 })
159+
160+
start(term)
161+
162+
assert.equal(5000, vim.bo[term:get_state("bufnr")].scrollback)
163+
end)
164+
157165
it("does nothing if already started", function()
158166
local term = Terminal:new()
159167
start(term)

0 commit comments

Comments
 (0)