Creating New Modules
The widgets that you see on the screen are displayed using modules. To make it easier to create new modules there is a generator which creates a stub (an empty module). The Go package generators contains generator scripts for different types of widgets.
Prerequisites
Before you can generate new modules, you'll need to have:
- Go version 1.15 or higher
- The source code for WTF (
git clone https://github.com/wtfutil/wtf
)
Creating a New Text Widget
-
Generate a new module using generator
Usego run generator/textwidget.go
to create a new widget called NewTextWidget. You can change the name of the generated widget by setting an environment variable calledWTF_WIDGET_NAME
.For example, to generate a new widget called MyNewWidget on macOs or linux, the command would be:
# as a single line ❯ WTF_WIDGET_NAME=MyNewWidget go run generator/textwidget.go # setting the name separately ❯ export WTF_WIDGET_NAME=MyNewWidget ❯ go run generator/textwidget.go
The equivalent using Windows PowerShell would be
❯ $env:WTF_WIDGET_NAME = "MyNewWidget" ❯ go run generator\textwidget.go
The new widget is generated using the template in
textwidget.tpl
-
Register your newly generated module in app
The last step is to register your new module in app/widget_maker.go
, you will have to import your module and define a new case with your module name.
- Run you app, your module should be present !
Source Code
wtf/generator/