github.com/wtfutil/wtf@v0.43.0/generator/textwidget.tpl (about)

     1  package {{(Lower .Name)}}
     2  
     3  import (
     4  	"github.com/rivo/tview"
     5  	"github.com/wtfutil/wtf/view"
     6  )
     7  
     8  // Widget is the container for your module's data
     9  type Widget struct {
    10  	view.TextWidget
    11  
    12  	settings *Settings
    13  }
    14  
    15  // NewWidget creates and returns an instance of Widget
    16  func NewWidget(tviewApp *tview.Application, redrawChan chan bool, pages *tview.Pages, settings *Settings) *Widget {
    17  	widget := Widget{
    18  		TextWidget: view.NewTextWidget(tviewApp, redrawChan, pages, settings.common),
    19  
    20  		settings: settings,
    21  	}
    22  
    23  	return &widget
    24  }
    25  
    26  /* -------------------- Exported Functions -------------------- */
    27  
    28  // Refresh updates the onscreen contents of the widget
    29  func (widget *Widget) Refresh() {
    30  
    31      // The last call should always be to the display function
    32      widget.display()
    33  }
    34  
    35  /* -------------------- Unexported Functions -------------------- */
    36  
    37  func (widget *Widget) content() string {
    38  	return "This is my widget"
    39  }
    40  
    41  func (widget *Widget) display() {
    42  	widget.Redraw(func() (string, string, bool) {
    43  		return widget.CommonSettings().Title, widget.content(), false
    44  	})
    45  }