on main help sign in
fix(ui): change pointer receivers to value receivers
f0942a7Ayman Bagabas
internal/ui/model/ui.go+24−32
@@ -162,7 +162,7 @@ func New(com *common.Common) *UI {
162}
162}
163
163
164// Init initializes the UI model.
164// Init initializes the UI model.
165−func (m *UI) Init() tea.Cmd {
165+func (m UI) Init() tea.Cmd {
166 if m.QueryVersion {
166 if m.QueryVersion {
167 return tea.RequestTerminalVersion
167 return tea.RequestTerminalVersion
168 }
168 }
@@ -170,7 +170,7 @@ func (m *UI) Init() tea.Cmd {
170}
170}
171
171
172// Update handles updates to the UI model.
172// Update handles updates to the UI model.
173−func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
173+func (m UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
174 var cmds []tea.Cmd
174 var cmds []tea.Cmd
175 switch msg := msg.(type) {
175 switch msg := msg.(type) {
176 case tea.EnvMsg:
176 case tea.EnvMsg:
@@ -297,73 +297,65 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) (cmds []tea.Cmd) {
297
297
298// Draw implements [tea.Layer] and draws the UI model.
298// Draw implements [tea.Layer] and draws the UI model.
299func (m *UI) Draw(scr uv.Screen, area uv.Rectangle) {
299func (m *UI) Draw(scr uv.Screen, area uv.Rectangle) {
300− layout := generateLayout(m, area.Dx(), area.Dy())
301−
302− // Update cached layout and component sizes if needed.
303− if m.layout != layout {
304− m.layout = layout
305− m.updateSize()
306− }
307−
308 // Clear the screen first
300 // Clear the screen first
309 screen.Clear(scr)
301 screen.Clear(scr)
310
302
311 switch m.state {
303 switch m.state {
312 case uiConfigure:
304 case uiConfigure:
313 header := uv.NewStyledString(m.header)
305 header := uv.NewStyledString(m.header)
314− header.Draw(scr, layout.header)
306+ header.Draw(scr, m.layout.header)
315
307
316− mainView := lipgloss.NewStyle().Width(layout.main.Dx()).
308+ mainView := lipgloss.NewStyle().Width(m.layout.main.Dx()).
317− Height(layout.main.Dy()).
309+ Height(m.layout.main.Dy()).
318 Background(lipgloss.ANSIColor(rand.Intn(256))).
310 Background(lipgloss.ANSIColor(rand.Intn(256))).
319 Render(" Configure ")
311 Render(" Configure ")
320 main := uv.NewStyledString(mainView)
312 main := uv.NewStyledString(mainView)
321− main.Draw(scr, layout.main)
313+ main.Draw(scr, m.layout.main)
322
314
323 case uiInitialize:
315 case uiInitialize:
324 header := uv.NewStyledString(m.header)
316 header := uv.NewStyledString(m.header)
325− header.Draw(scr, layout.header)
317+ header.Draw(scr, m.layout.header)
326
318
327 main := uv.NewStyledString(m.initializeView())
319 main := uv.NewStyledString(m.initializeView())
328− main.Draw(scr, layout.main)
320+ main.Draw(scr, m.layout.main)
329
321
330 case uiLanding:
322 case uiLanding:
331 header := uv.NewStyledString(m.header)
323 header := uv.NewStyledString(m.header)
332− header.Draw(scr, layout.header)
324+ header.Draw(scr, m.layout.header)
333 main := uv.NewStyledString(m.landingView())
325 main := uv.NewStyledString(m.landingView())
334− main.Draw(scr, layout.main)
326+ main.Draw(scr, m.layout.main)
335
327
336 editor := uv.NewStyledString(m.textarea.View())
328 editor := uv.NewStyledString(m.textarea.View())
337− editor.Draw(scr, layout.editor)
329+ editor.Draw(scr, m.layout.editor)
338
330
339 case uiChat:
331 case uiChat:
340 header := uv.NewStyledString(m.header)
332 header := uv.NewStyledString(m.header)
341− header.Draw(scr, layout.header)
333+ header.Draw(scr, m.layout.header)
342− m.drawSidebar(scr, layout.sidebar)
334+ m.drawSidebar(scr, m.layout.sidebar)
343
335
344− m.chat.Draw(scr, layout.main)
336+ m.chat.Draw(scr, m.layout.main)
345
337
346 editor := uv.NewStyledString(m.textarea.View())
338 editor := uv.NewStyledString(m.textarea.View())
347− editor.Draw(scr, layout.editor)
339+ editor.Draw(scr, m.layout.editor)
348
340
349 case uiChatCompact:
341 case uiChatCompact:
350 header := uv.NewStyledString(m.header)
342 header := uv.NewStyledString(m.header)
351− header.Draw(scr, layout.header)
343+ header.Draw(scr, m.layout.header)
352
344
353− mainView := lipgloss.NewStyle().Width(layout.main.Dx()).
345+ mainView := lipgloss.NewStyle().Width(m.layout.main.Dx()).
354− Height(layout.main.Dy()).
346+ Height(m.layout.main.Dy()).
355 Background(lipgloss.ANSIColor(rand.Intn(256))).
347 Background(lipgloss.ANSIColor(rand.Intn(256))).
356 Render(" Compact Chat Messages ")
348 Render(" Compact Chat Messages ")
357 main := uv.NewStyledString(mainView)
349 main := uv.NewStyledString(mainView)
358− main.Draw(scr, layout.main)
350+ main.Draw(scr, m.layout.main)
359
351
360 editor := uv.NewStyledString(m.textarea.View())
352 editor := uv.NewStyledString(m.textarea.View())
361− editor.Draw(scr, layout.editor)
353+ editor.Draw(scr, m.layout.editor)
362 }
354 }
363
355
364 // Add help layer
356 // Add help layer
365 help := uv.NewStyledString(m.help.View(m))
357 help := uv.NewStyledString(m.help.View(m))
366− help.Draw(scr, layout.help)
358+ help.Draw(scr, m.layout.help)
367
359
368 // Debugging rendering (visually see when the tui rerenders)
360 // Debugging rendering (visually see when the tui rerenders)
369 if os.Getenv("CRUSH_UI_DEBUG") == "true" {
361 if os.Getenv("CRUSH_UI_DEBUG") == "true" {
@@ -403,7 +395,7 @@ func (m *UI) Cursor() *tea.Cursor {
403}
395}
404
396
405// View renders the UI model's view.
397// View renders the UI model's view.
406−func (m *UI) View() tea.View {
398+func (m UI) View() tea.View {
407 var v tea.View
399 var v tea.View
408 v.AltScreen = true
400 v.AltScreen = true
409 v.BackgroundColor = m.com.Styles.Background
401 v.BackgroundColor = m.com.Styles.Background
@@ -434,7 +426,7 @@ func (m *UI) View() tea.View {
434}
426}
435
427
436// ShortHelp implements [help.KeyMap].
428// ShortHelp implements [help.KeyMap].
437−func (m *UI) ShortHelp() []key.Binding {
429+func (m UI) ShortHelp() []key.Binding {
438 var binds []key.Binding
430 var binds []key.Binding
439 k := &m.keyMap
431 k := &m.keyMap
440
432
@@ -481,7 +473,7 @@ func (m *UI) ShortHelp() []key.Binding {
481}
473}
482
474
483// FullHelp implements [help.KeyMap].
475// FullHelp implements [help.KeyMap].
484−func (m *UI) FullHelp() [][]key.Binding {
476+func (m UI) FullHelp() [][]key.Binding {
485 var binds [][]key.Binding
477 var binds [][]key.Binding
486 k := &m.keyMap
478 k := &m.keyMap
487 help := k.Help
479 help := k.Help