99 "github.com/charmbracelet/lipgloss/v2"
1010
1111 "github.com/docker/cagent/pkg/tui/core"
12+ "github.com/docker/cagent/pkg/tui/styles"
1213)
1314
1415// CommandExecuteMsg is sent when a command is selected
@@ -183,31 +184,17 @@ func (d *commandPaletteDialog) filterCommands() {
183184
184185// View renders the command palette dialog
185186func (d * commandPaletteDialog ) View () string {
186- dialogWidth := min (d .width * 80 / 100 , 70 )
187- if dialogWidth < 80 {
188- dialogWidth = 80
189- }
187+ dialogWidth := max (min (d .width * 80 / 100 , 70 ), 80 )
190188
191189 maxHeight := min (d .height * 70 / 100 , 30 )
192190 contentWidth := dialogWidth - 6
193191
194- dialogStyle := lipgloss .NewStyle ().
195- Border (lipgloss .RoundedBorder ()).
196- BorderForeground (lipgloss .Color ("#6b7280" )).
197- Padding (1 , 2 ).
198- Width (dialogWidth )
199-
200- titleStyle := lipgloss .NewStyle ().
201- Bold (true ).
202- Foreground (lipgloss .Color ("#9ca3af" )).
203- Width (contentWidth )
204- title := titleStyle .Render ("Commands" )
192+ title := styles .DialogTitleStyle .Width (contentWidth ).Render ("Commands" )
205193
206194 d .textInput .SetWidth (contentWidth )
207195 searchInput := d .textInput .View ()
208196
209- separator := lipgloss .NewStyle ().
210- Foreground (lipgloss .Color ("#4b5563" )).
197+ separator := styles .DialogSeparatorStyle .
211198 Width (contentWidth ).
212199 Render (strings .Repeat ("─" , contentWidth ))
213200
@@ -234,11 +221,7 @@ func (d *commandPaletteDialog) View() string {
234221
235222 commands := categoryMap [catName ]
236223
237- categoryStyle := lipgloss .NewStyle ().
238- Bold (true ).
239- Foreground (lipgloss .Color ("#6b7280" )).
240- MarginTop (1 )
241- commandList = append (commandList , categoryStyle .Render (catName ))
224+ commandList = append (commandList , styles .PaletteCategoryStyle .Render (catName ))
242225 itemCount ++
243226
244227 for _ , cmd := range commands {
@@ -247,28 +230,25 @@ func (d *commandPaletteDialog) View() string {
247230 }
248231
249232 isSelected := currentIndex == d .selected
250- commandLine := d .renderCommand (cmd , isSelected , contentWidth )
233+ commandLine := d .renderCommand (cmd , isSelected )
251234 commandList = append (commandList , commandLine )
252235 itemCount ++
253236 currentIndex ++
254237 }
255238 }
256239
257240 if len (d .filtered ) == 0 {
258- noResultsStyle := lipgloss .NewStyle ().
259- Foreground (lipgloss .Color ("#6b7280" )).
241+ commandList = append (commandList , "" , styles .DialogContentStyle .
260242 Italic (true ).
261243 Align (lipgloss .Center ).
262- Width (contentWidth )
263- commandList = append ( commandList , "" , noResultsStyle . Render ("No commands found" ))
244+ Width (contentWidth ).
245+ Render ("No commands found" ))
264246 }
265247
266- helpStyle := lipgloss .NewStyle ().
267- Foreground (lipgloss .Color ("#6b7280" )).
268- Italic (true ).
248+ help := styles .DialogHelpStyle .
269249 MarginTop (1 ).
270- Width (contentWidth )
271- help := helpStyle . Render ("↑/↓ navigate • enter execute • esc close" )
250+ Width (contentWidth ).
251+ Render ("↑/↓ navigate • enter execute • esc close" )
272252
273253 parts := []string {
274254 title ,
@@ -279,45 +259,28 @@ func (d *commandPaletteDialog) View() string {
279259 parts = append (parts , commandList ... )
280260 parts = append (parts , "" , help )
281261
282- content := lipgloss .JoinVertical (lipgloss .Left , parts ... )
283- return dialogStyle .Render (content )
262+ return styles .DialogStyle .
263+ Width (dialogWidth ).
264+ Render (lipgloss .JoinVertical (lipgloss .Left , parts ... ))
284265}
285266
286267// renderCommand renders a single command in the list
287- func (d * commandPaletteDialog ) renderCommand (cmd Command , selected bool , width int ) string {
288- var style lipgloss.Style
289-
290- if selected {
291- style = lipgloss .NewStyle ().
292- Background (lipgloss .Color ("#374151" )).
293- Foreground (lipgloss .Color ("#f9fafb" )).
294- Bold (true ).
295- Width (width ).
296- Padding (0 , 1 )
297- } else {
298- style = lipgloss .NewStyle ().
299- Foreground (lipgloss .Color ("#d1d5db" )).
300- Width (width ).
301- Padding (0 , 1 )
268+ func (d * commandPaletteDialog ) renderCommand (cmd Command , selected bool ) string {
269+ text := " " + cmd .Label
270+ if cmd .Description != "" {
271+ text += " - " + cmd .Description
302272 }
303273
304- labelStyle := lipgloss .NewStyle ()
305- descStyle := lipgloss .NewStyle ().Foreground (lipgloss .Color ("#9ca3af" ))
306-
307- text := " " + labelStyle .Render (cmd .Label )
308- if cmd .Description != "" {
309- text += " " + descStyle .Render ("- " + cmd .Description )
274+ if selected {
275+ return styles .PaletteSelectedStyle .Render (text )
310276 }
311277
312- return style .Render (text )
278+ return styles . PaletteUnselectedStyle .Render (text )
313279}
314280
315281// Position calculates the position to center the dialog
316282func (d * commandPaletteDialog ) Position () (row , col int ) {
317- dialogWidth := min (d .width * 80 / 100 , 70 )
318- if dialogWidth < 50 {
319- dialogWidth = 50
320- }
283+ dialogWidth := max (min (d .width * 80 / 100 , 70 ), 50 )
321284
322285 maxHeight := min (d .height * 70 / 100 , 30 )
323286
0 commit comments