Skip to content

Commit b8db78a

Browse files
committed
feat(ui): clear output window when user selects No to prompt
- adjust confirmation dialog to clear the output window based on choice - update unit tests to ensure desired behavior on user selection - ensures consistent UI experience in input output handling
1 parent d1751b1 commit b8db78a

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

lua/opencode/ui/input_window.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ M._prompt_add_to_context = function(cmd, output, exit_code)
122122
if choice == 'Yes' then
123123
local message = string.format('Command: `%s`\nExit code: %d\nOutput:\n```\n%s```', cmd, exit_code, output)
124124
M._append_to_input(message)
125-
output_window.clear()
126125
end
126+
output_window.clear()
127127
require('opencode.ui.input_window').focus_input()
128128
end)
129129
end

tests/unit/input_window_spec.lua

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,15 @@ describe('input_window', function()
7878
local output_lines = nil
7979
local output_window = require('opencode.ui.output_window')
8080
local original_set_lines = output_window.set_lines
81+
local original_clear = output_window.clear
8182

8283
output_window.set_lines = function(lines)
8384
output_lines = lines
8485
end
8586

87+
output_window.clear = function()
88+
end
89+
8690
vim.system = function(cmd, opts, callback)
8791
vim.schedule(function()
8892
callback({ code = 0, stdout = 'hello world\n', stderr = '' })
@@ -126,6 +130,7 @@ describe('input_window', function()
126130
assert.are.same('hello world', output_lines[2])
127131

128132
output_window.set_lines = original_set_lines
133+
output_window.clear = original_clear
129134
vim.api.nvim_win_close(input_win, true)
130135
vim.api.nvim_win_close(output_win, true)
131136
vim.api.nvim_buf_delete(input_buf, { force = true })
@@ -246,6 +251,55 @@ describe('input_window', function()
246251
state.windows = nil
247252
end)
248253

254+
it('should clear output window when user selects No', function()
255+
vim.system = function(cmd, opts, callback)
256+
vim.schedule(function()
257+
callback({ code = 0, stdout = 'test output\n', stderr = '' })
258+
end)
259+
end
260+
261+
vim.ui.select = function(choices, opts, callback)
262+
callback('No')
263+
end
264+
265+
local input_buf = vim.api.nvim_create_buf(false, true)
266+
local output_buf = vim.api.nvim_create_buf(false, true)
267+
local input_win = vim.api.nvim_open_win(input_buf, true, {
268+
relative = 'editor',
269+
width = 80,
270+
height = 10,
271+
row = 0,
272+
col = 0,
273+
})
274+
local output_win = vim.api.nvim_open_win(output_buf, false, {
275+
relative = 'editor',
276+
width = 80,
277+
height = 10,
278+
row = 11,
279+
col = 0,
280+
})
281+
282+
state.windows = {
283+
input_buf = input_buf,
284+
input_win = input_win,
285+
output_buf = output_buf,
286+
output_win = output_win,
287+
}
288+
289+
vim.api.nvim_buf_set_lines(state.windows.input_buf, 0, -1, false, { '!echo test' })
290+
291+
input_window.handle_submit()
292+
293+
local output_lines = vim.api.nvim_buf_get_lines(output_buf, 0, -1, false)
294+
assert.are.same({ '' }, output_lines)
295+
296+
vim.api.nvim_win_close(input_win, true)
297+
vim.api.nvim_win_close(output_win, true)
298+
vim.api.nvim_buf_delete(input_buf, { force = true })
299+
vim.api.nvim_buf_delete(output_buf, { force = true })
300+
state.windows = nil
301+
end)
302+
249303
it('should handle command errors', function()
250304
local error_notified = false
251305

0 commit comments

Comments
 (0)