A powerful little TUI framework 🏗
Go to file
Christian Rocha 116ab34eb8
Sync pager viewport when starting up and resizing
2020-06-18 12:33:58 -04:00
.github/workflows Add GitHub workflow 2020-01-25 07:17:37 +01:00
examples Sync pager viewport when starting up and resizing 2020-06-18 12:33:58 -04:00
.gitignore Ignore .envrc 2020-04-22 09:53:18 -04:00
LICENSE Add MIT license 2020-01-24 15:07:54 -05:00
README.md Add go-runewidth to resources in README 2020-06-11 21:51:52 -04:00
commands.go Um, the package is called Bubble Tea, thank-you-very-much 2020-06-11 19:34:08 -04:00
commands_unix.go Rename to Bubble Tea (with the import name tea) 2020-05-25 19:48:36 -04:00
commands_windows.go Rename to Bubble Tea (with the import name tea) 2020-05-25 19:48:36 -04:00
go.mod Bump termenv and futher integrate it into terminal controls 2020-06-17 11:17:41 -04:00
go.sum Bump termenv and futher integrate it into terminal controls 2020-06-17 11:17:41 -04:00
key.go Rename to Bubble Tea (with the import name tea) 2020-05-25 19:48:36 -04:00
logging.go Rename to Bubble Tea (with the import name tea) 2020-05-25 19:48:36 -04:00
renderer.go Add command to sync scrollable area with renderer 2020-06-18 12:23:42 -04:00
screen.go Fix a bug where left area on the first line was not always cleared 2020-06-17 14:50:39 -04:00
signals_unix.go Disable resize listening on windows since it's not supported 2020-06-17 12:27:16 -04:00
signals_windows.go Disable resize listening on windows since it's not supported 2020-06-17 12:27:16 -04:00
tea.go Adjust comments 2020-06-17 19:43:19 -04:00
tty_unix.go Rename to Bubble Tea (with the import name tea) 2020-05-25 19:48:36 -04:00
tty_windows.go Rename to Bubble Tea (with the import name tea) 2020-05-25 19:48:36 -04:00

README.md

Bubble Tea

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

⚠️ This project is a pre-release so the API is subject to change a little. That said, we're using it in production.

Simple example

package main

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

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

type model int

type tickMsg struct{}

func main() {
	p := tea.NewProgram(initialize, update, view, subscriptions)
	if err := p.Start(); err != nil {
		log.Fatal(err)
	}
}

// Return the initial model and initial command
func initialize() (tea.Model, tea.Cmd) {
    return 5, tick
}

// 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)
}

// A simple command which Bubble Tea runs asynchronously.
func tick() tea.Msg {
    time.Sleep(time.Second)
    return tickMsg{}
}

Hungry for more? Totally confused? See the other examples.

Other Resources

  • termenv: advanced ANSI style and color support for your terminal applications. Very useful when rendering your views.
  • reflow: a collection of ANSI-aware text formatting tools. Also useful for view rendering.
  • go-runewidth: functions to get the physical width of runes in terms of cells. Indispensable when working with fullwidth and zero-width characters.

Acknowledgments

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

License

MIT


Part of Charm.

the Charm logo

Charm热爱开源!