Skip to content

Commit c77f2b8

Browse files
committed
Update documentation & usage
1 parent 8fd4ed0 commit c77f2b8

File tree

3 files changed

+27
-67
lines changed

3 files changed

+27
-67
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,27 @@ import (
5353
tea "github.com/charmbracelet/bubbletea"
5454
)
5555

56+
// -----------------------------------------------------------------------------
57+
// Tiny Model
58+
// The Tiny Model is a sub-model for the tabs. It's a simple model that just shows the title of the tab.
59+
60+
// tinyModel is a sub-model for the tabs
5661
type tinyModel struct {
5762
skeleton *skeleton.Skeleton
5863
title string
5964
}
6065

66+
// newTinyModel returns a new tinyModel
6167
func newTinyModel(skeleton *skeleton.Skeleton, title string) *tinyModel {
6268
return &tinyModel{
6369
skeleton: skeleton,
6470
title: title,
6571
}
6672
}
6773

68-
func (m tinyModel) Init() tea.Cmd { return nil }
74+
func (m tinyModel) Init() tea.Cmd {
75+
return nil
76+
}
6977
func (m tinyModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
7078
return m, nil
7179
}
@@ -81,6 +89,8 @@ func (m tinyModel) View() string {
8189
Initialize Skeleton, add pages, and configure widgets:
8290

8391
````go
92+
// -----------------------------------------------------------------------------
93+
// Main Program
8494
func main() {
8595
s := skeleton.NewSkeleton()
8696

examples/file-reader/main.go

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,6 @@ import (
66
"github.com/termkit/skeleton"
77
)
88

9-
type mainModel struct {
10-
skeleton *skeleton.Skeleton
11-
}
12-
13-
func (m *mainModel) Init() tea.Cmd {
14-
return tea.Batch(
15-
tea.EnterAltScreen,
16-
tea.SetWindowTitle("File Reader"),
17-
m.skeleton.Init(),
18-
)
19-
}
20-
21-
func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
22-
var cmd tea.Cmd
23-
m.skeleton, cmd = m.skeleton.Update(msg)
24-
return m, cmd
25-
}
26-
27-
func (m *mainModel) View() string {
28-
return m.skeleton.View()
29-
}
30-
319
func main() {
3210
s := skeleton.NewSkeleton()
3311
s.SetPagePosition(lipgloss.Left)
@@ -37,9 +15,7 @@ func main() {
3715

3816
s.AddPage("explorer", "Explorer", newExplorer(s))
3917

40-
m := &mainModel{skeleton: s}
41-
42-
if err := tea.NewProgram(m).Start(); err != nil {
18+
if err := tea.NewProgram(s).Start(); err != nil {
4319
panic(err)
4420
}
4521
}

examples/fundamental-skeleton/main.go

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ func newTinyModel(skeleton *skeleton.Skeleton, title string) *tinyModel {
2828
}
2929
}
3030

31-
func (m tinyModel) Init() tea.Cmd { return nil }
31+
func (m tinyModel) Init() tea.Cmd {
32+
return nil
33+
}
3234
func (m tinyModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
3335
return m, nil
3436
}
@@ -40,60 +42,32 @@ func (m tinyModel) View() string {
4042
}
4143

4244
// -----------------------------------------------------------------------------
43-
// Main Model
44-
// The Main Model is the main model for the program. It contains the skeleton and the tab models.
45-
46-
type mainModel struct {
47-
skeleton *skeleton.Skeleton
48-
}
49-
50-
func (m *mainModel) Init() tea.Cmd {
51-
return tea.Batch(
52-
tea.EnterAltScreen,
53-
tea.SetWindowTitle("Basic Tab Example"),
54-
m.skeleton.Init(),
55-
)
56-
}
57-
58-
func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
59-
var cmd tea.Cmd
60-
m.skeleton, cmd = m.skeleton.Update(msg)
61-
return m, cmd
62-
}
63-
64-
func (m *mainModel) View() string {
65-
return m.skeleton.View()
66-
}
67-
45+
// Main Program
6846
func main() {
69-
skel := skeleton.NewSkeleton()
47+
s := skeleton.NewSkeleton()
7048

7149
// Add tabs (pages)
72-
skel.AddPage("first", "First Tab", newTinyModel(skel, "First"))
73-
skel.AddPage("second", "Second Tab", newTinyModel(skel, "Second"))
74-
skel.AddPage("third", "Third Tab", newTinyModel(skel, "Third"))
50+
s.AddPage("first", "First Tab", newTinyModel(s, "First"))
51+
s.AddPage("second", "Second Tab", newTinyModel(s, "Second"))
52+
s.AddPage("third", "Third Tab", newTinyModel(s, "Third"))
7553

76-
// Add a widget to entire screen
54+
// Add a widget to entire screen ( Optional )
7755
// Battery level is hardcoded. You can use a library to get the battery level of your system.
78-
skel.AddWidget("battery", "Battery %92") // Add a widget to entire screen
56+
s.AddWidget("battery", "Battery %92") // Add a widget to entire screen
7957

80-
// Add current time
81-
skel.AddWidget("time", time.Now().Format("15:04:05"))
58+
// Add current time ( Optional )
59+
s.AddWidget("time", time.Now().Format("15:04:05"))
8260

83-
// Update the time widget every second
61+
// Update the time widget every second ( Optional )
8462
go func() {
8563
time.Sleep(time.Second)
8664
for {
87-
skel.UpdateWidgetValue("time", time.Now().Format("15:04:05"))
65+
s.UpdateWidgetValue("time", time.Now().Format("15:04:05"))
8866
time.Sleep(time.Second)
8967
}
9068
}()
9169

92-
model := &mainModel{
93-
skeleton: skel,
94-
}
95-
96-
p := tea.NewProgram(model)
70+
p := tea.NewProgram(s)
9771
if err := p.Start(); err != nil {
9872
panic(err)
9973
}

0 commit comments

Comments
 (0)