on main help sign in
fix(tui): app: show error message when window is too small
34935a1Ayman Bagabas
internal/tui/tui.go+21−4
@@ -109,6 +109,7 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
109 }
109 }
110 return a, tea.Batch(cmds...)
110 return a, tea.Batch(cmds...)
111 case tea.WindowSizeMsg:
111 case tea.WindowSizeMsg:
112+ a.wWidth, a.wHeight = msg.Width, msg.Height
112 a.completions.Update(msg)
113 a.completions.Update(msg)
113 return a, a.handleWindowResize(msg.Width, msg.Height)
114 return a, a.handleWindowResize(msg.Width, msg.Height)
114
115
@@ -269,7 +270,6 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
269// handleWindowResize processes window resize events and updates all components.
270// handleWindowResize processes window resize events and updates all components.
270func (a *appModel) handleWindowResize(width, height int) tea.Cmd {
271func (a *appModel) handleWindowResize(width, height int) tea.Cmd {
271 var cmds []tea.Cmd
272 var cmds []tea.Cmd
272− a.wWidth, a.wHeight = width, height
273 if a.showingFullHelp {
273 if a.showingFullHelp {
274 height -= 5
274 height -= 5
275 } else {
275 } else {
@@ -400,6 +400,26 @@ func (a *appModel) moveToPage(pageID page.PageID) tea.Cmd {
400
400
401// View renders the complete application interface including pages, dialogs, and overlays.
401// View renders the complete application interface including pages, dialogs, and overlays.
402func (a *appModel) View() tea.View {
402func (a *appModel) View() tea.View {
403+ var view tea.View
404+ t := styles.CurrentTheme()
405+ view.BackgroundColor = t.BgBase
406+ if a.wWidth < 25 || a.wHeight < 15 {
407+ view.Layer = lipgloss.NewCanvas(
408+ lipgloss.NewLayer(
409+ t.S().Base.Width(a.wWidth).Height(a.wHeight).
410+ Align(lipgloss.Center, lipgloss.Center).
411+ Render(
412+ t.S().Base.
413+ Padding(1, 2).
414+ Background(t.BgSubtle).
415+ Foreground(t.White).
416+ Render("Too small!"),
417+ ),
418+ ),
419+ )
420+ return view
421+ }
422+
403 page := a.pages[a.currentPage]
423 page := a.pages[a.currentPage]
404 if withHelp, ok := page.(core.KeyMapHelp); ok {
424 if withHelp, ok := page.(core.KeyMapHelp); ok {
405 a.status.SetKeyMap(withHelp.Help())
425 a.status.SetKeyMap(withHelp.Help())
@@ -446,10 +466,7 @@ func (a *appModel) View() tea.View {
446 layers...,
466 layers...,
447 )
467 )
448
468
449− var view tea.View
450− t := styles.CurrentTheme()
451 view.Layer = canvas
469 view.Layer = canvas
452− view.BackgroundColor = t.BgBase
453 view.Cursor = cursor
470 view.Cursor = cursor
454 return view
471 return view
455}
472}