on main help sign in
fix(tui): app: show error message when window is too small
commit34935a159e66ee57f52f6fe1ee06fbabc2240a20 authorAyman Bagabas <ayman.bagabas@gmail.com> dateThu 17 Jul 2025, 16:00 (1 year ago) parent8a16b8e
1 file changed+21−4
internal/tui/tui.go+21−4
internal/tui/tui.go+21−4
@@ -109,6 +109,7 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
109109 }
110110 return a, tea.Batch(cmds...)
111111 case tea.WindowSizeMsg:
112+ a.wWidth, a.wHeight = msg.Width, msg.Height
112113 a.completions.Update(msg)
113114 return a, a.handleWindowResize(msg.Width, msg.Height)
114115
@@ -269,7 +270,6 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
269270// handleWindowResize processes window resize events and updates all components.
270271func (a *appModel) handleWindowResize(width, height int) tea.Cmd {
271272 var cmds []tea.Cmd
272− a.wWidth, a.wHeight = width, height
273273 if a.showingFullHelp {
274274 height -= 5
275275 } else {
@@ -400,6 +400,26 @@ func (a *appModel) moveToPage(pageID page.PageID) tea.Cmd {
400400
401401// View renders the complete application interface including pages, dialogs, and overlays.
402402func (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+
403423 page := a.pages[a.currentPage]
404424 if withHelp, ok := page.(core.KeyMapHelp); ok {
405425 a.status.SetKeyMap(withHelp.Help())
@@ -446,10 +466,7 @@ func (a *appModel) View() tea.View {
446466 layers...,
447467 )
448468
449− var view tea.View
450− t := styles.CurrentTheme()
451469 view.Layer = canvas
452− view.BackgroundColor = t.BgBase
453470 view.Cursor = cursor
454471 return view
455472}