Organizing the Interface’s Layout
Explore how to organize the interface layout effectively in Go CLI applications by creating start and pause buttons. Understand implementing lightweight, nonblocking button callbacks using goroutines to control Pomodoro intervals, update UI elements, and handle errors asynchronously.
We'll cover the following...
Now that we’ve added the main widgets, we can create the buttons to start and pause Pomodoro intervals. To make it easier to maintain and update the code, we’ll add the buttons in a different file. Save and close the widgets.go file and open a new file buttons.go for editing.
Creating the buttons
We start by adding the package definition and the import list. For this file, we’ll
use the following packages:
contextto carry cancellation signals.fmtto format strings.termdash/cell, which provides customization options for widgets.termdash/widgets/buttonto define abuttonwidget.pomodoro, which we created with the business logic.
Then we define a new custom type, buttonSet, that includes the btStart and btPause fields of type button.Button, which represents a Termdash button:
Creating the newButtonSet() function
Next, we add the function newButtonSet() to instantiate a buttonSet. This function
takes the following inputs: a Context to carry cancellation signals, an instance
of ...