@@ -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
5661type tinyModel struct {
5762 skeleton *skeleton.Skeleton
5863 title string
5964}
6065
66+ // newTinyModel returns a new tinyModel
6167func 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+ }
6977func (m tinyModel ) Update (msg tea .Msg ) (tea .Model , tea .Cmd ) {
7078 return m, nil
7179}
@@ -76,74 +84,44 @@ func (m tinyModel) View() string {
7684}
7785````
7886
79- #### 2. Create the Main Model
80-
81- Next, define the main model that will handle the overall application state and interact with Skeleton:
82-
83- ```` go
84- type mainModel struct {
85- skeleton *skeleton.Skeleton
86- }
87-
88- func (m *mainModel ) Init () tea .Cmd {
89- return tea.Batch (
90- tea.EnterAltScreen ,
91- tea.SetWindowTitle (" Basic Tab Example" ),
92- m.skeleton .Init (), // Initialize the skeleton
93- )
94- }
95-
96- func (m *mainModel ) Update (msg tea .Msg ) (tea .Model , tea .Cmd ) {
97- var cmd tea.Cmd
98- m.skeleton , cmd = m.skeleton .Update (msg)
99- return m, cmd
100- }
101-
102- func (m *mainModel ) View () string {
103- return m.skeleton .View ()
104- }
105- ````
106-
107- #### 3. Set Up the Application
87+ #### 2. Set Up the Application
10888
10989Initialize Skeleton, add pages, and configure widgets:
11090
11191```` go
92+ // -----------------------------------------------------------------------------
93+ // Main Program
11294func main () {
113- skel := skeleton.NewSkeleton ()
95+ s := skeleton.NewSkeleton ()
11496
11597 // Add tabs (pages)
116- skel .AddPage (" first" , " First Tab" , newTinyModel (skel , " First" ))
117- skel .AddPage (" second" , " Second Tab" , newTinyModel (skel , " Second" ))
118- skel .AddPage (" third" , " Third Tab" , newTinyModel (skel , " Third" ))
98+ s .AddPage (" first" , " First Tab" , newTinyModel (s , " First" ))
99+ s .AddPage (" second" , " Second Tab" , newTinyModel (s , " Second" ))
100+ s .AddPage (" third" , " Third Tab" , newTinyModel (s , " Third" ))
119101
120102 // Set up key bindings ( Optional | Defaults: ctrl+left, ctrl+right )
121103 // To switch next page
122- skel .KeyMap .SwitchTabRight = key.NewBinding (
104+ s .KeyMap .SwitchTabRight = key.NewBinding (
123105 key.WithKeys (" shift+right" ))
124106
125107 // To switch previous page
126- skel .KeyMap .SwitchTabLeft = key.NewBinding (
108+ s .KeyMap .SwitchTabLeft = key.NewBinding (
127109 key.WithKeys (" shift+left" ))
128110
129111 // Add a widget to entire screen
130- skel .AddWidget (" battery" , " Battery % 92" )
131- skel .AddWidget (" time" , time.Now ().Format (" 15:04:05" ))
112+ s .AddWidget (" battery" , " Battery % 92" )
113+ s .AddWidget (" time" , time.Now ().Format (" 15:04:05" ))
132114
133115 // Update the time widget every second
134116 go func () {
135117 time.Sleep (time.Second )
136118 for {
137- skel .UpdateWidgetValue (" time" , time.Now ().Format (" 15:04:05" ))
119+ s .UpdateWidgetValue (" time" , time.Now ().Format (" 15:04:05" ))
138120 time.Sleep (time.Second )
139121 }
140122 }()
141123
142- model := &mainModel{
143- skeleton: skel,
144- }
145-
146- p := tea.NewProgram (model)
124+ p := tea.NewProgram (s)
147125 if err := p.Start (); err != nil {
148126 panic (err)
149127 }
@@ -154,9 +132,7 @@ func main() {
154132
1551331 . ** Model Definition** : ` tinyModel ` represents the content of each tab. It uses the Skeleton instance to query terminal dimensions and display information.
156134
157- 2 . ** Main Model** : ` mainModel ` integrates Skeleton and handles application state updates and rendering.
158-
159- 3 . ** Application Setup** : The ` main ` function initializes Skeleton, adds pages, and sets up widgets. The time widget updates every second to reflect the current time.
135+ 2 . ** Application Setup** : The ` main ` function initializes Skeleton, adds pages, and sets up widgets. The time widget updates every second to reflect the current time.
160136
161137## Skeleton in the Wild
162138Some programs that use Skeleton in production:
0 commit comments