A powerful little TUI framework 🏗
Go to file
Christian Muehlhaeuser 1c98700015
syslog is only available on unix systems
2020-01-25 07:15:56 +01:00
examples Use local copy of Tea when building examples 2020-01-22 16:08:44 -08:00
.gitignore Ignore any example binaries 2020-01-22 13:32:39 -08:00
LICENSE Add MIT license 2020-01-24 15:07:54 -05:00
README.md Add MIT license 2020-01-24 15:07:54 -05:00
ansi.go Move ANSI stuff into its own file 2020-01-18 10:33:43 -05:00
go.mod Commands should probably receive the model as an arg, right? 2020-01-20 10:35:03 -08:00
go.sum Commands should probably receive the model as an arg, right? 2020-01-20 10:35:03 -08:00
key.go Simplify IsRune() 2020-01-25 06:56:53 +01:00
logging.go syslog is only available on unix systems 2020-01-25 07:15:56 +01:00
tea.go syslog is only available on unix systems 2020-01-25 07:15:56 +01:00
tty_unix.go Add platform-specific terminal init & restore 2020-01-25 07:15:29 +01:00
tty_windows.go Add platform-specific terminal init & restore 2020-01-25 07:15:29 +01:00

README.md

Tea

茶! The fun, functional way to build terminal apps. A Go framework based on The Elm Architecture.

Simple example

package main

// A simple program that counts down from 5 and then exits.

import (
	"fmt"
	"log"
	"time"
	"github.com/charmbracelet/tea"
)

type model int

type tickMsg struct{}

func main() {
	err := tea.NewProgram(model(5), update, view, []tea.Sub{tick}).Start()
	if err != nil {
		log.Fatal(err)
	}
}

func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {
	m, _ := mdl.(model)

	switch msg.(type) {
	case tickMsg:
		m -= 1
		if m <= 0 {
			return m, tea.Quit
		}
	}
	return m, nil
}

func view(mdl tea.Model) string {
	m, _ := mdl.(model)
	return fmt.Sprintf("Hi. This program will exit in %d seconds...\n", m)
}

func tick(_ tea.Model) tea.Msg {
	time.Sleep(time.Second)
	return tickMsg{}
}

Hungry for more? See the other examples.

Credit

Heavily inspired by both The Elm Architecture by Evan Czaplicki et al. and go-tea by TJ Holowaychuk.


Part of Charm. For more info see ssh charm.sh. Charm热爱开源!

License

MIT