commit eaa9aca1308b30dda651e530c6b5f164e3e30037
parent cdc3702f8d0391380316c1d5bd0919f29df1a76b
Author: phanium <91544758+phanen@users.noreply.github.com>
Date: Wed, 15 Oct 2025 12:42:02 +0800
fix(jobs): jobstart(term=true) accepts width/height #33904
Problem: when create a hidden terminal job with `nvim_buf_call`+
`jobstart(…,{term=true})`, program like `lazygit` cannot figure out the
correct width and height.
Solution: `jobstart(…,{term=true})` accepts `width`/`height`
Diffstat:
2 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
@@ -3595,8 +3595,8 @@ void f_jobstart(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
}
}
- uint16_t width = 0;
- uint16_t height = 0;
+ uint16_t width = (uint16_t)tv_dict_get_number(job_opts, "width");
+ uint16_t height = (uint16_t)tv_dict_get_number(job_opts, "height");
char *term_name = NULL;
if (term) {
@@ -3616,13 +3616,11 @@ void f_jobstart(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
overlapped = false;
detach = false;
stdin_mode = kChannelStdinPipe;
- width = (uint16_t)MAX(0, curwin->w_view_width - win_col_off(curwin));
- height = (uint16_t)curwin->w_view_height;
+ width = width ? width : (uint16_t)MAX(0, curwin->w_view_width - win_col_off(curwin));
+ height = height ? height : (uint16_t)curwin->w_view_height;
}
if (pty) {
- width = width ? width : (uint16_t)tv_dict_get_number(job_opts, "width");
- height = height ? height : (uint16_t)tv_dict_get_number(job_opts, "height");
// Deprecated TERM field is from before `env` option existed.
term_name = term_name ? term_name : tv_dict_get_string(job_opts, "TERM", false);
term_name = term_name ? term_name : "ansi";
diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua
@@ -97,6 +97,28 @@ describe('jobs', function()
command("call jobstart(['cat', '-'], { 'term': v:false })")
end)
+ it('jobstart(term=true) accepts width/height (#33904)', function()
+ local buf = api.nvim_create_buf(false, true)
+ exec_lua(function()
+ vim.api.nvim_buf_call(buf, function()
+ vim.fn.jobstart({
+ vim.v.progpath,
+ '--clean',
+ '--headless',
+ '+lua print(vim.uv.new_tty(1, false):get_winsize())',
+ }, {
+ term = true,
+ width = 11,
+ height = 12,
+ env = { VIMRUNTIME = os.getenv('VIMRUNTIME') },
+ })
+ end)
+ end)
+ retry(nil, nil, function()
+ eq({ '11 12' }, api.nvim_buf_get_lines(buf, 0, 1, false))
+ end)
+ end)
+
it('must specify env option as a dict', function()
command('let g:job_opts.env = v:true')
local _, err = pcall(function()