A powerful little TUI framework 🏗
Go to file
Christian Rocha 29799c3151
Go mod tidy
2020-01-25 22:22:28 -05:00
.github/workflows Add GitHub workflow 2020-01-25 07:17:37 +01:00
examples Update examples to use new subscription model 2020-01-25 21:28:16 -05: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 Update example in README as well as the README in general 2020-01-25 21:42:27 -05:00
ansi.go Move ANSI stuff into its own file 2020-01-18 10:33:43 -05:00
go.mod Go mod tidy 2020-01-25 22:22:28 -05:00
go.sum Go mod tidy 2020-01-25 22:22:28 -05:00
key.go Add missing comment 2020-01-25 16:34:00 -05:00
logging.go syslog is only available on unix systems 2020-01-25 07:15:56 +01:00
tea.go Rework subscriptions, allowing for them to be easily managed by the developer 2020-01-25 21:28:16 -05: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() {
	p := tea.NewProgram(init, update, view, subscriptions)
	if err := p.Start(); err != nil {
		log.Fatal(err)
	}
}

// Listen for messages and update the model accordingly
func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {
	m, _ := mdl.(model)

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

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

// Subscribe to events
func subscriptions(_ tea.Model) tea.Subs {
    return tea.Subs{
        "tick": tick,
    }
}

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

Hungry for more? See the other examples.

Authors

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

Other Resources

  • Termenv: advanced ANSI style and color support for your terminal applications. Very useful when rendering in your views!

License

MIT


Part of Charm. For more info see ssh charm.sh.

the Charm logo

Charm热爱开源!