-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
72 lines (57 loc) · 1.41 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"fmt"
"os"
tea "github.com/charmbracelet/bubbletea"
"github.com/shawalli/bubbles/tabs"
)
type PageModel struct {
content string
}
func (pm PageModel) Init() tea.Cmd { return nil }
func (pm PageModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return pm, nil }
func (pm PageModel) View() string { return pm.content }
type Model struct {
tabs tabs.Model
}
func (m Model) Init() tea.Cmd { return nil }
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "esc", "q", "ctrl+c":
return m, tea.Quit
}
}
t, cmd := m.tabs.Update(msg)
m.tabs = t.(tabs.Model)
return m, cmd
}
func (m Model) View() string {
return m.tabs.View()
}
func main() {
t := []tabs.Tab{
tabs.NewTab(
"Tab 1",
PageModel{content: "This is the content 1.\n\nYou can get to the next tab by typing the tab key."},
),
tabs.NewTab(
"Tab 2",
PageModel{content: "This is the content 2.\n\nYou can get back to me with shift+tab."},
),
tabs.NewTab(
"Tab 3",
PageModel{content: "This is the content 3.\n\nYou can get to me by typing the number 3 (or tabbing)."},
),
tabs.NewTab(
"Tab 4",
PageModel{content: "This is the content 4.\n\nHappy to be here!"},
),
}
m := Model{tabs: tabs.New(t...)}
if _, err := tea.NewProgram(m).Run(); err != nil {
fmt.Printf("could not run program: %v", err)
os.Exit(1)
}
}