-
Notifications
You must be signed in to change notification settings - Fork 0
/
window_too_small_view.go
59 lines (47 loc) · 1.35 KB
/
window_too_small_view.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
func showWindowTooSmallView(m model) (tea.Model, tea.Cmd) {
return showModal(m, windowTooSmallView{})
}
type windowTooSmallViewKeyMap struct {
Quit key.Binding
}
var windowTooSmallViewKeys = windowTooSmallViewKeyMap{
Quit: key.NewBinding(
key.WithKeys("q"),
key.WithHelp("q", "quit"),
),
}
func (w windowTooSmallViewKeyMap) ShortHelp() []key.Binding {
return []key.Binding{w.Quit}
}
func (w windowTooSmallViewKeyMap) FullHelp() [][]key.Binding {
return [][]key.Binding{
{w.Quit},
}
}
type windowTooSmallView struct{}
func (w windowTooSmallView) update(msg tea.Msg, m model) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch {
case key.Matches(msg, windowTooSmallViewKeys.Quit):
return showQuitConfirmationView(m)
}
}
return m, nil
}
func (w windowTooSmallView) draw(m model) string {
text := fmt.Sprintf("Window is too small. Please resize the window to at least %dx%d (currently %dx%d).",
minWindowSize.x, minWindowSize.y, m.windowSize.x, m.windowSize.y)
m.help.Width = m.windowSize.x - 8
helpView := m.help.View(windowTooSmallViewKeys)
return lipgloss.NewStyle().
Width(m.windowSize.x - 8).
Render(lipgloss.JoinVertical(lipgloss.Left, text, "", helpView))
}