https://github.com/3rd/go-futui
Futuristic TUI library for Go.
https://github.com/3rd/go-futui
Last synced: about 1 year ago
JSON representation
Futuristic TUI library for Go.
- Host: GitHub
- URL: https://github.com/3rd/go-futui
- Owner: 3rd
- Created: 2024-01-02T22:46:05.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-07-20T13:17:24.000Z (almost 2 years ago)
- Last Synced: 2025-02-05T12:12:14.697Z (about 1 year ago)
- Language: Go
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# go-futui: Futuristic TUI library for Go.
> [!IMPORTANT]
> Very much WIP, you probably don't want to build stuff with this yet.
## Installation
```sh
go get github.com/3rd/go-futui
```
## Usage
```go
package main
import (
"strconv"
"time"
ui "github.com/3rd/go-futui"
"github.com/gdamore/tcell/v2"
)
// basic component
type Counter struct {
ui.Component
value int
}
func (c *Counter) Render() ui.Buffer {
b := ui.Buffer{}
b.Text(0, 0, "Count: "+strconv.Itoa(c.value), ui.Style{
Background: "#ff0000",
Foreground: "#000000",
Bold: true,
Italic: true,
Underline: true,
})
return b
}
// app with state
type State struct {
counter int
}
type MyApp struct {
ui.App
state State
}
func (app *MyApp) Setup() {
ticker := time.NewTicker(time.Millisecond * 16)
go func() {
for range ticker.C {
app.state.counter++
app.Update()
}
}()
}
func (app *MyApp) Render() ui.Buffer {
b := ui.Buffer{}
b.Resize(app.Width(), app.Height())
b.FillStyle(ui.Style{
Background: "#00ff00",
Foreground: "#000000",
})
b.Text(0, 0, "Hello World!", ui.Style{Foreground: "#220ee0"})
b.DrawComponent(0, 1, &Counter{value: app.state.counter})
return b
}
func (app *MyApp) OnKeypress(ev tcell.EventKey) {
switch ev.Key() {
case tcell.KeyCtrlC:
app.Quit()
}
app.state.counter++
app.Update()
}
func (app *MyApp) OnResize() {
app.Update()
}
func main() {
app := MyApp{}
app.Run(&app)
}
```