forked from sudo-tee/opencode.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutput_window.lua
More file actions
718 lines (621 loc) · 22.5 KB
/
Copy pathoutput_window.lua
File metadata and controls
718 lines (621 loc) · 22.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
local state = require('opencode.state')
local config = require('opencode.config')
local window_options = require('opencode.ui.window_options')
local float_layout = require('opencode.ui.float_layout')
local M = {}
M.namespace = vim.api.nvim_create_namespace('opencode_output')
M.debug_namespace = vim.api.nvim_create_namespace('opencode_output_debug')
M.markdown_namespace = vim.api.nvim_create_namespace('opencode_output_markdown')
M._last_visible_bottom_by_win = {}
M._was_at_bottom_by_win = {}
M._prev_line_count_by_win = {}
local function build_fold_state(folds)
local fold_state = {
ranges = {},
}
for _, range in ipairs(folds or {}) do
if range.from and range.to then
fold_state.ranges[#fold_state.ranges + 1] = {
from = range.from,
to = range.to,
}
end
end
table.sort(fold_state.ranges, function(a, b)
return a.from < b.from
end)
return fold_state
end
---@param buf integer
---@return { ranges: table<{from: integer, to: integer}> }
local function get_fold_state(buf)
local ok, fold_state = pcall(vim.api.nvim_buf_get_var, buf, 'opencode_folds')
if not ok or type(fold_state) ~= 'table' then
return { ranges = {} }
end
if type(fold_state.ranges) == 'table' then
return fold_state
end
return build_fold_state(fold_state)
end
local _update_depth = 0
local _update_buf = nil
---Begin a batch of buffer writes — toggle modifiable once for the whole batch.
---Returns true if the batch was opened (buffer is valid). Must be paired with end_update().
---@return boolean
function M.begin_update()
local windows = state.windows
if not windows or not windows.output_buf then
return false
end
if _update_depth == 0 then
_update_buf = windows.output_buf
vim.api.nvim_set_option_value('modifiable', true, { buf = _update_buf })
end
_update_depth = _update_depth + 1
return true
end
---End a batch started by begin_update().
function M.end_update()
if _update_depth == 0 then
return
end
_update_depth = _update_depth - 1
if _update_depth == 0 and _update_buf then
pcall(vim.api.nvim_set_option_value, 'modifiable', false, { buf = _update_buf })
_update_buf = nil
end
end
---@return integer
function M.create_buf()
local output_buf = vim.api.nvim_create_buf(false, true)
local filetype = config.ui.output.filetype or 'opencode_output'
vim.api.nvim_set_option_value('filetype', filetype, { buf = output_buf })
vim.api.nvim_buf_set_var(output_buf, 'opencode_folds', build_fold_state({}))
local buffixwin = require('opencode.ui.buf_fix_win')
buffixwin.fix_to_win(output_buf, function()
return state.windows and state.windows.output_win
end)
return output_buf
end
---@return vim.api.keyset.win_config
function M._build_output_win_config()
return {
relative = 'editor',
width = config.ui.window_width or 80,
row = 2,
col = 2,
style = 'minimal',
border = 'rounded',
zindex = 40,
}
end
---@param windows OpencodeWindowState?
function M.mounted(windows)
windows = windows or state.windows
return windows
and windows.output_buf
and windows.output_win
and vim.api.nvim_win_is_valid(windows.output_win)
and vim.api.nvim_buf_is_valid(windows.output_buf)
and vim.api.nvim_win_get_buf(windows.output_win) == windows.output_buf
end
---Check if the cursor in the output window is at (or was at) the bottom of
---the buffer, using the same logic as the original implementation.
---Returns true if the window should continue auto-scrolling.
---@param win? integer Window ID, defaults to state.windows.output_win
---@return boolean
function M.is_at_bottom(win)
if config.ui.output.always_scroll_to_bottom then
return true
end
win = win or (state.windows and state.windows.output_win)
if not win or not vim.api.nvim_win_is_valid(win) then
return true
end
if not state.windows or not state.windows.output_buf then
return true
end
local ok, line_count = pcall(vim.api.nvim_buf_line_count, state.windows.output_buf)
if not ok or not line_count or line_count == 0 then
return true
end
local ok2, cursor = pcall(vim.api.nvim_win_get_cursor, win)
if not ok2 then
return true
end
local prev_line_count = M._prev_line_count_by_win[win] or line_count
return cursor[1] >= prev_line_count or cursor[1] >= line_count
end
---@param win? integer
---@return integer|nil
function M.get_visible_bottom_line(win)
win = win or (state.windows and state.windows.output_win)
if not win or not vim.api.nvim_win_is_valid(win) then
return nil
end
local ok, line = pcall(vim.fn.line, 'w$', win)
return (ok and line and line > 0) and line or nil
end
---@param win? integer
function M.reset_scroll_tracking(win)
if win then
M._last_visible_bottom_by_win[win] = nil
M._was_at_bottom_by_win[win] = nil
M._prev_line_count_by_win[win] = nil
return
end
M._last_visible_bottom_by_win = {}
M._was_at_bottom_by_win = {}
M._prev_line_count_by_win = {}
end
---@param win? integer
function M.sync_cursor_with_viewport(win)
win = win or (state.windows and state.windows.output_win)
if not win or not vim.api.nvim_win_is_valid(win) then
return
end
local windows = state.windows
local buf = windows and windows.output_buf
if not buf or not vim.api.nvim_buf_is_valid(buf) or vim.api.nvim_win_get_buf(win) ~= buf then
M.reset_scroll_tracking(win)
return
end
local ok, line_count = pcall(vim.api.nvim_buf_line_count, buf)
local visible_bottom = M.get_visible_bottom_line(win)
if not ok or not line_count or line_count == 0 or not visible_bottom then
return
end
M._last_visible_bottom_by_win[win] = visible_bottom
end
---@param windows OpencodeWindowState
function M.setup(windows)
window_options.set_window_option(
'winhighlight',
config.ui.window_highlight,
windows.output_win,
{ save_original = true }
)
window_options.set_window_option('wrap', true, windows.output_win, { save_original = true })
window_options.set_window_option('linebreak', true, windows.output_win, { save_original = true })
window_options.set_window_option('cursorline', false, windows.output_win, { save_original = true })
window_options.set_window_option('number', false, windows.output_win, { save_original = true })
window_options.set_window_option('relativenumber', false, windows.output_win, { save_original = true })
window_options.set_buffer_option('modifiable', false, windows.output_buf)
window_options.set_buffer_option('buftype', 'nofile', windows.output_buf)
window_options.set_buffer_option('bufhidden', 'hide', windows.output_buf)
window_options.set_buffer_option('buflisted', false, windows.output_buf)
window_options.set_buffer_option('swapfile', false, windows.output_buf)
window_options.set_buffer_option('undofile', false, windows.output_buf)
window_options.set_buffer_option('undolevels', -1, windows.output_buf)
window_options.set_window_option('foldmethod', 'manual', windows.output_win)
window_options.set_window_option('foldenable', true, windows.output_win)
window_options.set_window_option('foldlevel', 0, windows.output_win)
window_options.set_window_option('foldcolumn', '1', windows.output_win)
window_options.set_window_option('fillchars', 'fold:-,foldopen:-,foldclose:+,foldsep:│', windows.output_win)
window_options.set_window_option('foldtext', 'v:lua.opencode_fold_text()', windows.output_win)
if config.ui.position ~= 'current' then
window_options.set_window_option('winfixbuf', true, windows.output_win, { save_original = true })
end
window_options.set_window_option('winfixheight', true, windows.output_win, { save_original = true })
window_options.set_window_option('winfixwidth', true, windows.output_win, { save_original = true })
window_options.set_window_option('signcolumn', 'yes', windows.output_win, { save_original = true })
window_options.set_window_option('list', false, windows.output_win, { save_original = true })
window_options.set_window_option('statuscolumn', '', windows.output_win, { save_original = true })
window_options.set_window_option('colorcolumn', '', windows.output_win, { save_original = true })
M.update_dimensions(windows)
M.reset_scroll_tracking(windows.output_win)
M._last_visible_bottom_by_win[windows.output_win] = M.get_visible_bottom_line(windows.output_win)
M.setup_keymaps(windows)
end
---@param windows OpencodeWindowState?
function M.update_dimensions(windows)
if config.ui.position == 'current' then
return
end
if not windows or not windows.output_win or not vim.api.nvim_win_is_valid(windows.output_win) then
return
end
if config.ui.position == 'float' then
float_layout.update(windows, windows.input_win ~= nil and vim.api.nvim_win_is_valid(windows.input_win))
return
end
local total_width = vim.api.nvim_get_option_value('columns', {})
local width_ratio
if windows.saved_width_ratio then
width_ratio = windows.saved_width_ratio
windows.saved_width_ratio = nil
elseif state.pre_zoom_width then
width_ratio = config.ui.zoom_width
else
width_ratio = config.ui.window_width
end
local width = math.floor(total_width * width_ratio)
local ok, win_config = pcall(vim.api.nvim_win_get_config, windows.output_win)
if not ok then
return
end
if win_config.relative == '' then
pcall(vim.api.nvim_win_set_width, windows.output_win, width)
return
end
pcall(vim.api.nvim_win_set_config, windows.output_win, { width = width })
end
---Fold text for the output buffer
---@return string
function M.fold_text()
local windows = state.windows
local output_buf = windows and windows.output_buf
local line = vim.v.foldstart
if not output_buf or not vim.api.nvim_buf_is_valid(output_buf) then
return vim.fn.foldtext()
end
local folds = get_fold_state(output_buf).ranges
local line_count = 0
for _, range in ipairs(folds) do
if line >= range.from and line <= range.to then
line_count = range.to - range.from + 1
break
end
end
if line_count > 0 then
local text = string.format('▶ %d lines hidden (zo open, zc close) ◀', line_count)
local width = vim.api.nvim_win_get_width(0)
local padding = math.max(0, math.floor((width - #text) / 2))
return string.rep('-', padding) .. text .. string.rep('-', padding)
end
return vim.fn.foldtext()
end
_G.opencode_fold_text = M.fold_text
function M.get_open_fold_starts(win, buf)
if not win or not buf then
return {}
end
local prev_folds = get_fold_state(buf).ranges
local was_open = {}
vim.api.nvim_win_call(win, function()
for _, range in ipairs(prev_folds) do
if vim.fn.foldclosed(range.from) == -1 then
was_open[range.from] = true
end
end
end)
return was_open
end
---Set the folds for the output buffer
---@param fold_ranges table<{from: number, to: number}>
function M.set_folds(fold_ranges)
local windows = state.windows
if not M.mounted() then
return
end
---@cast windows OpencodeWindowState
local buf = windows.output_buf
local win = windows.output_win
local folds = build_fold_state(fold_ranges or {})
local prev_folds = get_fold_state(buf)
if vim.deep_equal(prev_folds.ranges, folds.ranges) then
return
end
local was_open = M.get_open_fold_starts(win, buf)
vim.api.nvim_buf_set_var(buf, 'opencode_folds', folds)
vim.api.nvim_win_call(win, function()
local view = vim.fn.winsaveview()
local line_count = vim.api.nvim_buf_line_count(buf)
for _, range in ipairs(folds.ranges) do
if range.from <= line_count and range.to <= line_count then
vim.cmd(range.from .. ',' .. range.to .. 'fold')
end
end
for _, range in ipairs(folds.ranges) do
if was_open[range.from] then
vim.cmd(range.from .. ',' .. range.to .. 'foldopen!')
end
end
vim.fn.winrestview(view)
end)
end
---Shift fold ranges
---@param start_line integer
---@param delta integer
function M.shift_folds(start_line, delta)
local windows = state.windows
if not windows or not windows.output_buf then
return
end
local buf = windows.output_buf
local fold_state = get_fold_state(buf)
local folds = fold_state.ranges
for _, range in ipairs(folds) do
if range.from > start_line then
range.from = range.from + delta
if delta < 0 then
range.from = math.max(start_line, range.from)
end
end
if range.to > start_line then
range.to = range.to + delta
if delta < 0 then
range.to = math.max(start_line, range.to)
end
end
if range.to < range.from then
range.to = range.from
end
end
table.sort(folds, function(a, b)
return a.from < b.from
end)
fold_state.starts = {}
for _, range in ipairs(folds) do
fold_state.starts[#fold_state.starts + 1] = range.from
end
end
---@return integer
function M.get_buf_line_count()
local windows = state.windows
if not windows or not windows.output_buf or not vim.api.nvim_buf_is_valid(windows.output_buf) then
return 0
end
return vim.api.nvim_buf_line_count(windows.output_buf)
end
---Set the output buffer contents
---@param lines string[] The lines to set
---@param start_line? integer The starting line to set, defaults to 0
---@param end_line? integer The last line to set, defaults to -1
function M.set_lines(lines, start_line, end_line)
local windows = state.windows
if not windows or not windows.output_buf or not vim.api.nvim_buf_is_valid(windows.output_buf) then
return
end
local buf = windows.output_buf
start_line = start_line or 0
end_line = end_line or -1
-- Skip identical content outside of batch mode to avoid unnecessary writes
-- that cause flicker (e.g. when a markdown plugin re-renders an unchanged part).
-- Inside begin_update/end_update the caller controls exactly what is written,
-- so the check would be redundant and expensive.
if _update_depth == 0 then
local ok, existing = pcall(vim.api.nvim_buf_get_lines, buf, start_line, end_line, false)
if ok and existing and #existing == #lines then
local same = true
for i = 1, #lines do
if existing[i] ~= lines[i] then
same = false
break
end
end
if same then
return
end
end
end
if _update_depth == 0 then
vim.api.nvim_set_option_value('modifiable', true, { buf = buf })
vim.api.nvim_buf_set_lines(buf, start_line, end_line, false, lines)
vim.api.nvim_set_option_value('modifiable', false, { buf = buf })
else
vim.api.nvim_buf_set_lines(buf, start_line, end_line, false, lines)
end
end
---Clear output buf extmarks
---@param start_line? integer Line to start clearing, defaults 0
---@param end_line? integer Line to clear until, defaults to -1
---@param clear_all? boolean If true, clears all extmarks in the buffer
function M.clear_extmarks(start_line, end_line, clear_all)
local windows = state.windows
if not windows or not windows.output_buf or not vim.api.nvim_buf_is_valid(windows.output_buf) then
return
end
start_line = start_line or 0
end_line = end_line or -1
pcall(vim.api.nvim_buf_clear_namespace, windows.output_buf, clear_all and -1 or M.namespace, start_line, end_line)
end
---Apply extmarks to the output buffer
---@param extmarks table<number, OutputExtmark[]> Extmarks indexed by line
---@param line_offset? integer Line offset to apply to extmarks, defaults to 0
function M.set_extmarks(extmarks, line_offset)
if not extmarks or type(extmarks) ~= 'table' then
return
end
local windows = state.windows
if not windows or not windows.output_buf or not vim.api.nvim_buf_is_valid(windows.output_buf) then
return
end
line_offset = line_offset or 0
local output_buf = windows.output_buf
local line_indices = vim.tbl_keys(extmarks)
table.sort(line_indices)
for _, line_idx in ipairs(line_indices) do
local marks = extmarks[line_idx]
table.sort(marks, function(a, b)
local ma = type(a) == 'function' and a() or a
local mb = type(b) == 'function' and b() or b
return (ma.priority or 0) > (mb.priority or 0)
end)
for _, mark in ipairs(marks) do
local m = type(mark) == 'function' and mark() or mark
local target_line = line_offset + line_idx --[[@as integer]]
local start_col = m.start_col
-- Only deepcopy when we need to mutate: start_col must be removed from the
-- opts table, and end_row must be offset when line_offset is non-zero.
-- The vast majority of extmarks (border virt_text) have neither field, so
-- we avoid 100k+ deepcopy calls during a full session render.
if start_col ~= nil or (m.end_row ~= nil and line_offset ~= 0) then
m = vim.deepcopy(m)
m.start_col = nil
if m.end_row then
m.end_row = m.end_row + line_offset
end
end
---@cast m vim.api.keyset.set_extmark
pcall(vim.api.nvim_buf_set_extmark, output_buf, M.namespace, target_line, start_col or 0, m)
end
end
end
---@param start_line integer
---@param end_line integer
function M.highlight_changed_lines(start_line, end_line)
local windows = state.windows
if not windows or not windows.output_buf or not vim.api.nvim_buf_is_valid(windows.output_buf) then
return
end
if not config.debug.highlight_changed_lines then
return
end
local buf = windows.output_buf
local first = math.max(0, start_line)
if end_line < start_line then
return
end
local last = math.max(first, end_line)
vim.api.nvim_buf_clear_namespace(buf, M.debug_namespace, first, last + 1)
for line = first, last do
vim.api.nvim_buf_set_extmark(buf, M.debug_namespace, line, 0, {
line_hl_group = 'OpencodeChangedLines',
hl_eol = true,
priority = 250,
})
end
vim.defer_fn(function()
if vim.api.nvim_buf_is_valid(buf) then
vim.api.nvim_buf_clear_namespace(buf, M.debug_namespace, first, last + 1)
end
end, config.debug.highlight_changed_lines_timeout_ms or 120)
end
---@param should_stop_insert? boolean
function M.focus_output(should_stop_insert)
if not M.mounted() then
return
end
---@cast state.windows { output_win: integer }
if should_stop_insert then
vim.cmd('stopinsert')
end
vim.api.nvim_set_current_win(state.windows.output_win)
end
---Close and delete the output window and buffer.
function M.close()
if not M.mounted() then
return
end
---@cast state.windows { output_win: integer, output_buf: integer }
M.reset_scroll_tracking(state.windows.output_win)
pcall(vim.api.nvim_win_close, state.windows.output_win, true)
pcall(vim.api.nvim_buf_delete, state.windows.output_buf, { force = true })
end
---@param windows OpencodeWindowState
function M.setup_keymaps(windows)
local keymap = require('opencode.keymap')
keymap.setup_window_keymaps(config.keymap.output_window, windows.output_buf)
-- When lazy-render is active, gg only reaches the top of rendered content.
-- Load all messages first so gg reaches the true start of history.
vim.keymap.set('n', 'gg', function()
local renderer = require('opencode.ui.renderer')
renderer.load_all_messages()
vim.api.nvim_win_set_cursor(0, { 1, 0 })
end, { buffer = windows.output_buf })
end
---@param windows OpencodeWindowState
---@param group integer
function M.setup_autocmds(windows, group)
vim.api.nvim_create_autocmd('WinEnter', {
group = group,
buffer = windows.output_buf,
callback = function()
local input_window = require('opencode.ui.input_window')
state.ui.set_last_focused_window('output')
input_window.refresh_placeholder(state.windows)
vim.cmd('stopinsert')
end,
})
vim.api.nvim_create_autocmd('BufEnter', {
group = group,
buffer = windows.output_buf,
callback = function()
local input_window = require('opencode.ui.input_window')
state.ui.set_last_focused_window('output')
input_window.refresh_placeholder(state.windows)
vim.cmd('stopinsert')
end,
})
vim.api.nvim_create_autocmd('CursorMoved', {
group = group,
buffer = windows.output_buf,
callback = function()
local pos = state.ui.get_window_cursor(windows.output_win)
if pos then
state.ui.set_cursor_position('output', pos)
end
end,
})
-- Lazy-render: load more messages on scroll-to-top (debounced)
local debounced_load_more = require('opencode.util').debounce(function()
local renderer = require('opencode.ui.renderer')
local render_state = require('opencode.ui.renderer.ctx').render_state
-- Save the message at the top of the viewport before loading more
local ok, cursor = pcall(vim.api.nvim_win_get_cursor, windows.output_win)
local anchor_msg_id = nil
local anchor_was_at_line = nil
if ok and cursor then
local top_line = cursor[1]
for _, msg in ipairs(state.messages or {}) do
local msg_id = msg.info and msg.info.id or ''
if not msg_id:match('^__opencode_') then
local rendered = render_state:get_message(msg_id)
if rendered and rendered.line_start and rendered.line_start >= top_line then
anchor_msg_id = msg_id
anchor_was_at_line = rendered.line_start
break
end
end
end
end
if renderer.load_more_messages() then
-- Restore cursor to the anchor message's new position
if anchor_msg_id then
local rendered = render_state:get_message(anchor_msg_id)
if rendered and rendered.line_start then
pcall(vim.api.nvim_win_set_cursor, windows.output_win, { rendered.line_start, 0 })
return
end
end
-- Fallback: move to top of buffer
pcall(vim.api.nvim_win_set_cursor, windows.output_win, { 1, 0 })
end
end, 150)
vim.api.nvim_create_autocmd('WinScrolled', {
group = group,
buffer = windows.output_buf,
callback = function()
M.sync_cursor_with_viewport(windows.output_win)
local ctx = require('opencode.ui.renderer.ctx')
local has_unrendered = ctx.lazy_render_count ~= nil
and ctx.lazy_render_count < #state.messages
if has_unrendered then
local ok, cursor = pcall(vim.api.nvim_win_get_cursor, windows.output_win)
if ok and cursor and cursor[1] <= 3 then
debounced_load_more()
end
end
end,
})
end
---Clear the output buffer and all namespaces.
function M.clear()
M.set_lines({})
-- clear extmarks in all namespaces as I've seen RenderMarkdown leave some
-- extmarks behind
M.clear_extmarks(0, -1, true)
end
---Get the output buffer
---@return integer|nil Buffer ID
function M.get_buf()
return state.windows and state.windows.output_buf
end
---Trigger a re-render by calling the renderer
function M.render()
local renderer = require('opencode.ui.renderer')
renderer._render_all_messages()
end
return M