Skip to content

Commit 476ce82

Browse files
cameronrsudo-tee
authored andcommitted
feat: make loading animation configurable
1 parent 8db2c11 commit 476ce82

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

lua/opencode/config.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ M.defaults = {
8181
preset = 'nerdfonts',
8282
overrides = {},
8383
},
84+
loading_animation = {
85+
frames = { '·', '', '', '', '', '', '', '', '', '' },
86+
},
8487
output = {
8588
tools = {
8689
show_output = true,

lua/opencode/types.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@
102102
---@class OpencodeCompletionConfig
103103
---@field file_sources OpencodeCompletionFileSourcesConfig
104104

105+
---@class OpencodeLoadingAnimationConfig
106+
---@field frames string[]
107+
105108
---@class OpencodeUIConfig
106109
---@field position 'right'|'left' # Position of the UI (default: 'right')
107110
---@field input_position 'bottom'|'top' # Position of the input window (default: 'bottom')
@@ -112,6 +115,7 @@
112115
---@field display_cost boolean
113116
---@field window_highlight string
114117
---@field icons { preset: 'emoji'|'text'|'nerdfonts', overrides: table<string,string> }
118+
---@field loading_animation OpencodeLoadingAnimationConfig
115119
---@field output { tools: { show_output: boolean } }
116120
---@field input { text: { wrap: boolean } }
117121
---@field completion OpencodeCompletionConfig

lua/opencode/ui/loading_animation.lua

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
local state = require('opencode.state')
2+
local config = require('opencode.config')
23

34
local Timer = require('opencode.ui.timer')
45
local M = {}
56

67
M._animation = {
7-
frames = { '·', '', '', '', '', '', '', '', '', '' },
8+
frames = nil,
89
text = 'Thinking... ',
910
current_frame = 1,
1011
timer = nil,
@@ -13,6 +14,17 @@ M._animation = {
1314
ns_id = vim.api.nvim_create_namespace('opencode_loading_animation'),
1415
}
1516

17+
function M._get_frames()
18+
if M._animation.frames then
19+
return M._animation.frames
20+
end
21+
local ui_config = config.get('ui')
22+
if ui_config and ui_config.loading_animation and ui_config.loading_animation.frames then
23+
return ui_config.loading_animation.frames
24+
end
25+
return { '·', '', '', '', '', '', '', '', '', '' }
26+
end
27+
1628
M.render = vim.schedule_wrap(function(windows)
1729
if not windows.footer_buf and not windows.output_buf or not vim.api.nvim_buf_is_valid(windows.output_buf) then
1830
return false
@@ -28,7 +40,7 @@ M.render = vim.schedule_wrap(function(windows)
2840
return false
2941
end
3042

31-
local loading_text = M._animation.text .. M._animation.frames[M._animation.current_frame]
43+
local loading_text = M._animation.text .. M._get_frames()[M._animation.current_frame]
3244

3345
M._animation.extmark_id = vim.api.nvim_buf_set_extmark(windows.footer_buf, M._animation.ns_id, 0, 0, {
3446
id = M._animation.extmark_id or nil,
@@ -41,7 +53,7 @@ M.render = vim.schedule_wrap(function(windows)
4153
end)
4254

4355
function M._next_frame()
44-
return (M._animation.current_frame % #M._animation.frames) + 1
56+
return (M._animation.current_frame % #M._get_frames()) + 1
4557
end
4658

4759
function M._start_animation_timer(windows)

0 commit comments

Comments
 (0)