@@ -5,9 +5,11 @@ local icons = require('opencode.ui.icons')
55local output_window = require (' opencode.ui.output_window' )
66local snapshot = require (' opencode.snapshot' )
77local config_file = require (' opencode.config_file' )
8+
89local M = {}
910
10- function M .render (windows )
11+ function M .render ()
12+ local windows = state .windows
1113 if not output_window .mounted (windows ) or not M .mounted (windows ) then
1214 return
1315 end
@@ -43,6 +45,7 @@ function M.render(windows)
4345 append_to_footer (restore_point_text )
4446 end
4547
48+ --- @diagnostic disable-next-line : need-check-nil
4649 local win_width = vim .api .nvim_win_get_width (windows .output_win )
4750 local footer_text = table.concat (segments , ' | ' ) .. ' '
4851 footer_text = string.rep (' ' , win_width - # footer_text ) .. footer_text
@@ -67,24 +70,36 @@ function M._build_footer_win_config(windows)
6770 }
6871end
6972
73+ local function on_change (_ , _ , _ )
74+ M .render ()
75+ end
76+
77+ local function on_job_count_changed (_ , new , old )
78+ if new == 0 or old == 0 then
79+ M .render ()
80+ end
81+ end
82+
7083function M .setup (windows )
7184 windows .footer_win = vim .api .nvim_open_win (windows .footer_buf , false , M ._build_footer_win_config (windows ))
7285 vim .api .nvim_set_option_value (' winhl' , ' Normal:OpenCodeHint' , { win = windows .footer_win })
7386
7487 -- for stats changes
75- state .subscribe (' current_model' , function (_ , _ , _ )
76- M .render (windows )
77- end )
88+ state .subscribe (' current_model' , on_change )
89+ -- to show C-c message
90+ state .subscribe (' job_count' , on_job_count_changed )
91+ state .subscribe (' restore_points' , on_change )
92+ end
7893
79- state . subscribe ( ' job_count ' , function ( _ , new , old )
80- if new == 0 or old == 0 then
81- M . render ( windows )
82- end
83- end )
94+ function M . close ( )
95+ if state . windows then
96+ pcall ( vim . api . nvim_win_close , state . windows . footer_win , true )
97+ pcall ( vim . api . nvim_buf_delete , state . windows . footer_buf , { force = true })
98+ end
8499
85- state .subscribe ( ' restore_points ' , function ( _ , _ , _ )
86- M . render ( windows )
87- end )
100+ state .unsubscribe ( ' current_model ' , on_change )
101+ state . unsubscribe ( ' job_count ' , on_job_count_changed )
102+ state . unsubscribe ( ' restore_points ' , on_change )
88103end
89104
90105function M .mounted (windows )
@@ -101,7 +116,7 @@ function M.update_window(windows)
101116 end
102117
103118 vim .api .nvim_win_set_config (windows .footer_win , M ._build_footer_win_config (windows ))
104- M .render (windows )
119+ M .render ()
105120end
106121
107122--- @return integer
@@ -137,13 +152,4 @@ function M.set_content(lines)
137152 vim .api .nvim_set_option_value (' modifiable' , false , { buf = windows .footer_buf })
138153end
139154
140- function M .close ()
141- if not state .windows then
142- return
143- end
144-
145- pcall (vim .api .nvim_win_close , state .windows .footer_win , true )
146- pcall (vim .api .nvim_buf_delete , state .windows .footer_buf , { force = true })
147- end
148-
149155return M
0 commit comments