A powerful little TUI framework 🏗
Go to file
2020-05-25 14:22:32 -04:00
.github/workflows Add GitHub workflow 2020-01-25 07:17:37 +01:00
examples Update dependencies in examples 2020-05-25 14:22:32 -04:00
paginator Simplify code a bit 2020-05-25 14:12:30 +02:00
spinner Use consts for default values 2020-05-25 14:12:42 +02:00
textinput Add alt+left/right and alt+b/f to jump between words in text input 2020-05-25 14:21:03 -04:00
viewport Simplify code a bit 2020-05-25 14:12:30 +02:00
.gitignore Ignore .envrc 2020-04-22 09:53:18 -04:00
boba.go Make type documentation godoc-compliant 2020-05-25 14:02:46 +02:00
commands_unix.go Use a buffered channel for signal.Notify 2020-05-25 13:43:02 +02:00
commands_windows.go Disable OnResize command on Windows 2020-05-18 11:44:58 -04:00
commands.go Simplify code a bit 2020-05-25 14:12:30 +02:00
go.mod Bump dependencies, namely github.com/pkg/term 2020-05-21 22:31:39 -04:00
go.sum Bump dependencies, namely github.com/pkg/term 2020-05-21 22:31:39 -04:00
key.go Simplify key/sequence map 2020-05-25 14:03:59 +02:00
LICENSE Add MIT license 2020-01-24 15:07:54 -05:00
logging.go Add ability to log directly to a file 2020-05-21 16:59:26 -04:00
README.md Rename project to Boba 2020-05-12 16:39:08 -04:00
tty_unix.go Rename project to Boba 2020-05-12 16:39:08 -04:00
tty_windows.go Rename project to Boba 2020-05-12 16:39:08 -04:00

Boba

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"
	"github.com/charmbracelet/boba"
)

type model int

type tickMsg time.Time

func main() {
	p := boba.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 boba.Msg, mdl boba.Model) (boba.Model, boba.Cmd) {
	m, _ := mdl.(model)

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

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

// Subscribe to events
func subscriptions(_ boba.Model) boba.Subs {
    return boba.Subs{
        "tick": time.Every(time.Second, func(t time.Time) boba.Msg {
            return tickMsg(t)
        },
    }
}

Hungry for more? 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.

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热爱开源!