on main help sign in
Merge pull request #237 from charmbracelet/too-small

fix(tui): app: show error message when window is too small

commite854fe437678a01f5d1ac554568953c4654a56e6 authorKujtim Hoxha <kujtimii.h@gmail.com> dateThu 24 Jul 2025, 09:24 (1 year ago) parentcc4a43f9ce4fb6
1 file changed+22−4
internal/tui/tui.go+22−4
internal/tui/tui.go+22−4
@@ -113,6 +113,7 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
113113 }
114114 return a, tea.Batch(cmds...)
115115 case tea.WindowSizeMsg:
116+ a.wWidth, a.wHeight = msg.Width, msg.Height
116117 a.completions.Update(msg)
117118 return a, a.handleWindowResize(msg.Width, msg.Height)
118119
@@ -291,7 +292,6 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
291292// handleWindowResize processes window resize events and updates all components.
292293func (a *appModel) handleWindowResize(width, height int) tea.Cmd {
293294 var cmds []tea.Cmd
294− a.wWidth, a.wHeight = width, height
295295 if a.showingFullHelp {
296296 height -= 5
297297 } else {
@@ -424,6 +424,27 @@ func (a *appModel) moveToPage(pageID page.PageID) tea.Cmd {
424424
425425// View renders the complete application interface including pages, dialogs, and overlays.
426426func (a *appModel) View() tea.View {
427+ var view tea.View
428+ t := styles.CurrentTheme()
429+ view.BackgroundColor = t.BgBase
430+ if a.wWidth < 25 || a.wHeight < 15 {
431+ view.Layer = lipgloss.NewCanvas(
432+ lipgloss.NewLayer(
433+ t.S().Base.Width(a.wWidth).Height(a.wHeight).
434+ Align(lipgloss.Center, lipgloss.Center).
435+ Render(
436+ t.S().Base.
437+ Padding(1, 4).
438+ Foreground(t.White).
439+ BorderStyle(lipgloss.RoundedBorder()).
440+ BorderForeground(t.Primary).
441+ Render("Window too small!"),
442+ ),
443+ ),
444+ )
445+ return view
446+ }
447+
427448 page := a.pages[a.currentPage]
428449 if withHelp, ok := page.(core.KeyMapHelp); ok {
429450 a.status.SetKeyMap(withHelp.Help())
@@ -475,10 +496,7 @@ func (a *appModel) View() tea.View {
475496 layers...,
476497 )
477498
478− var view tea.View
479− t := styles.CurrentTheme()
480499 view.Layer = canvas
481− view.BackgroundColor = t.BgBase
482500 view.Cursor = cursor
483501 return view
484502}