Skip to content
Kite

Quickstart

Use Go 1.26.1+ and an interactive terminal. In an empty directory, create a module:

Terminal window
go mod init example.com/counter
go get github.com/masterkeysrd/kite

Save one of the programs below as main.go. Run go mod tidy and go run .. Click the button to increment the count; press q to exit. Both examples use the same backend and the same exit-key helper as the repository demos.

package main
import (
"context"
"errors"
"log"
"github.com/masterkeysrd/kite"
"github.com/masterkeysrd/kite/backend/uv"
"github.com/masterkeysrd/kite/examples/demoutil"
"github.com/masterkeysrd/kite/extras/kitex"
)
var counter = kitex.FC("Counter", func(_ kitex.NoProps) kitex.Node {
count, setCount := kitex.UseState(0)
increment := func() {
setCount.Update(func(n int) int { return n + 1 })
}
return kitex.Button(kitex.ButtonProps{OnPress: increment},
kitex.Textf("Count: %d", count()),
)
})
func main() {
b, err := uv.New()
if err != nil {
log.Fatal(err)
}
app := kite.New(b)
root := kitex.CreateRoot(app)
root.Render(counter())
ctx, cancel := demoutil.ExitContext(context.Background(), app, "q", "ctrl+c")
defer cancel()
if err := app.Run(ctx); err != nil && !errors.Is(err, context.Canceled) {
log.Print(err)
}
}

The setter schedules a render. The next render reads the new count and Kitex updates the button label.

package main
import (
"context"
"errors"
"fmt"
"log"
"github.com/masterkeysrd/kite"
"github.com/masterkeysrd/kite/backend/uv"
"github.com/masterkeysrd/kite/element"
"github.com/masterkeysrd/kite/examples/demoutil"
)
func main() {
b, err := uv.New()
if err != nil {
log.Fatal(err)
}
app := kite.New(b)
count := 0
label := element.Text("Count: 0")
button := element.Button(label).OnPress(func() {
count++
label.SetData(fmt.Sprintf("Count: %d", count))
app.RequestFrame()
})
app.Mount(button)
ctx, cancel := demoutil.ExitContext(context.Background(), app, "q", "ctrl+c")
defer cancel()
if err := app.Run(ctx); err != nil && !errors.Is(err, context.Canceled) {
log.Print(err)
}
}

Here the button and text node are created once. The handler changes that exact text node; it never rebuilds the button. See Core concepts for how both programs reach the same renderer.