Termui provides additional widgets for termui that only fulfill one purpose. These widgets are not meant to be generic or multifunction. Configuration of these widgets is also very easy.
The Hacker News widget pulls the most recent or top stories from the official Hacker News API. It does that asynchronously and updates its view.
Implementing it is pretty straightforward:
topStories := hackernews.NewWidget(hackernews.TopStories)
topStories.Height = 15
topStories.Width = 100
draw := func() {
ui.Render(topStories)
}
topStories.UpdateEntries(draw)
You will have to provide a callback which re-renders all Bufferers
. Make sure the callback function is side-effect free because it gets called very often.
You may choose to load the most recent stories by calling hackernews.NewWidget(hackernews.MostRecent)
.