Skip to content

Painter

Brandon Jordan edited this page Jan 24, 2023 · 2 revisions

Painter() is an exported function for printing updatable text.

For example, Menu() uses Painter() to display a menu of options and sends updates when a new option has been selected.

Usage

var lastText string
Painter(func() (template string) {
    var text = "Text"
    if text != lastText {
        template = text
        lastText = template
    } else {
        template = lastText
    }
})

Painter() intelligently updates the content printed, it checks to make sure each line it prints has actually changed, the line count of the content can change to have more or fewer lines and it will adapt, it will make room for longer lined content, and replace longer content with shorter lined content.

It continues printing and updating the content to the screen until StopPainting() is called.

It is currently used by Menu(), Viewport(), Prompt() and more.

Read painter.go to learn more.

Clone this wiki locally

⌂ 换网址