Home

Awesome

tapioca

Add dynamic bubbletea elements to existing Go applications. tapioca makes bubbletea models stay at the bottom of the terminal, unaffected by log messages, the same way that tapioca pearls stay at the bottom of bubble tea.

Why should you use tapioca?

Add some tapioca to your application! With all the flexibility of bubbletea but without its complexity. As simple as two lines of code:

program := tapioca.NewProgram(spinner.New()).GoRun()
defer program.QuitAndWait()

Examples

Cobra & Spinner

Long running commands often require logging some intermediate information to let users know that the program is running as expected. However, printing a bunch of debug logs does not look nice in an application. Spinners can make your application more user friendly and tapioca integrates them painlessly with your cobra application.

./examples/cobra/cmd/connect.go

var connectCmd = &cobra.Command{
	[...]
	Run: func(cmd *cobra.Command, args []string) {
        	// Create and run a spinner in the background
		program := tapioca.NewProgram(spinner.New()).GoRun()
		defer program.QuitAndWait() // Quit when command ends

		// Set the command output to the program
		defer func(w io.Writer) { cmd.SetOut(w) }(cmd.OutOrStdout())
		cmd.SetOut(program)
        [...]
    }
}

cobra

Log & Progress

./examples/log/main.go

var logger *log.Logger = log.Default()

func main() {
	// Create and start the progress bar
	program := tapioca.NewProgram(progress.New()).GoRun()
	defer program.QuitAndWait()

	// Use a logger that works together with bubbletea
	defer func(l *log.Logger) { logger = l }(logger)
	logger = log.New(program, "", log.LstdFlags)

	// Do work, log and increase progress bar
	for i := 0; i <= 100; i++ {
		time.Sleep(10 * time.Millisecond)
		logger.Println("Started", i)
		time.Sleep(10 * time.Millisecond)
		logger.Println("Finished", i)
		program.Send(float64(i) / 100)
	}
	logger.Println("Finished everything!")
}

log-progress

<details> <summary>Without tapioca</summary>

log-progress_no-tapioca

</details>

Charm's Log

./examples/charmlog/main.go charmlog

<details> <summary>Without tapioca</summary>

charmlog_no-tapioca

</details>

Pre-defined models

tapioca extends bubbles with some pre-defined models for fast prototyping:

These models are usable out of the box and quit after pressing usual quit key combinations (ctrl+C/cmd+C). They are intended to cover basic dynamic elements that one would like to add to an existing application.

However they are just the tip of the iceberg of what can be done with Bubbletea and you might want a custom element. We also provide a WrapModel function that will wrap your custom model to make it behave better with an existing application (e.g. quitting with ctrl+C/cmd+C).