@@ -308,25 +308,41 @@ func (s *Skeleton) deletePage(key string) {
308
308
309
309
// AddWidget adds a new widget to the Skeleton.
310
310
func (s * Skeleton ) AddWidget (key string , value string ) * Skeleton {
311
- s .widget .AddWidget (key , value )
311
+ go func () {
312
+ s .updateChan <- AddNewWidget {
313
+ Key : key ,
314
+ Value : value ,
315
+ }
316
+ }()
312
317
return s
313
318
}
314
319
315
320
// UpdateWidgetValue updates the Value content by the given key.
316
321
// Adds the widget if it doesn't exist.
317
322
func (s * Skeleton ) UpdateWidgetValue (key string , value string ) * Skeleton {
318
- // if widget not exists, add it
319
- if s .widget .GetWidget (key ) == nil {
320
- s .widget .AddWidget (key , value )
321
- }
323
+ go func () {
324
+ // if widget not exists, add it
325
+ if s .widget .GetWidget (key ) == nil {
326
+ s .AddWidget (key , value )
327
+ }
328
+
329
+ s .updateChan <- UpdateWidgetContent {
330
+ Key : key ,
331
+ Value : value ,
332
+ }
333
+ }()
322
334
323
- s .widget .UpdateWidgetValue (key , value )
324
335
return s
325
336
}
326
337
327
338
// DeleteWidget deletes the Value by the given key.
328
339
func (s * Skeleton ) DeleteWidget (key string ) * Skeleton {
329
- s .widget .DeleteWidget (key )
340
+ go func () {
341
+ s .updateChan <- DeleteWidget {
342
+ Key : key ,
343
+ }
344
+ }()
345
+
330
346
return s
331
347
}
332
348
@@ -364,6 +380,23 @@ func (s *Skeleton) IAMActivePageCmd() tea.Cmd {
364
380
}
365
381
}
366
382
383
+ func (s * Skeleton ) switchPage (cmds []tea.Cmd , position string ) []tea.Cmd {
384
+ switch position {
385
+ case "left" :
386
+ if ! s .IsTabsLocked () {
387
+ s .currentTab = max (s .currentTab - 1 , 0 )
388
+ cmds = append (cmds , s .IAMActivePageCmd ())
389
+ }
390
+ case "right" :
391
+ if ! s .IsTabsLocked () {
392
+ s .currentTab = min (s .currentTab + 1 , len (s .pages )- 1 )
393
+ cmds = append (cmds , s .IAMActivePageCmd ())
394
+ }
395
+ }
396
+
397
+ return cmds
398
+ }
399
+
367
400
func (s * Skeleton ) updateSkeleton (msg tea.Msg , cmd tea.Cmd , cmds []tea.Cmd ) []tea.Cmd {
368
401
s .header , cmd = s .header .Update (msg )
369
402
cmds = append (cmds , cmd )
0 commit comments