bubbleo

package module
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 0 Imported by: 0

README

BubbleO

BubbleO is a collection of components for the excellent terminal UI tool bubbletea.

Go Reference

Navstack

Add support to your bubble tea application to easily transition between component models. The example below uses the menu component to let a user pick a color from a list of artist paintings.

Recording of the deeper example demo
    s := shell.New()
    s.Navstack.Push(navstack.NavigationItem{Model: m, Title: "Colors"})
    p := tea.NewProgram(s, tea.WithAltScreen())

    _, err := p.Run()
    if err != nil {
        fmt.Println("Error running program:", err)
        os.Exit(1)
    }

Push, well, pushes a new navigation item on the nav stack. The title is used for breadcrumbs (more later). The model at the top of the navstack has it's Update and View funcs used effectively making it the presented component on the stack.

Popping the stack will remove the topmost navigation item from the stack.

Navigation

Navigation is accomplished by your components when they publish messages like navstack.PushNavigation{} or navstack.PopNavigation{}.

Pushing a new component onto the stack

This example is from the included menu component which presents a list of choices. When a menu item is selected by pressing enter the choice's model is pushed onto the stack by publishing navstack.PushNavigation.

    case tea.KeyEnter.String():
        choice, ok := m.list.SelectedItem().(choiceItem)
        if ok {
            m.selected = &choice.key
            item := navstack.NavigationItem{Title: choice.title, Model: choice.key.Model}
            cmd := utils.Cmdize(navstack.PushNavigation{Item: item})
            return m, cmd
        }

There is no limit to the depth of the navigation stack. And the stack components may be dynamic based on your application and user needs.

Note: Cmdize simply wraps the given arg in a tea.Cmd (func that returns a tea.Msg)

Popping the stack

To pop a component off the stack you might do the following in your bubbletea Update func.

	case color.ColorSelected:
		pop := utils.Cmdize(navstack.PopNavigation{})
		cmd := utils.Cmdize(ArtistSelected{Name: m.Artist.Name, Color: msg.RGB})
		return m, tea.Sequence(pop, cmd)

The first cmd pops the current component off the stack while the second command is received by the previous component on the stack. This allows you to communicate the actions taken by the user up the nav stack.

If there are no items on the stack tea.Quit command is sent and the applicaiton exits.

Important: In this example we are using tea.Sequence rather than the normal tea.Batch to ensure the messages are played in the correct order. This ensures the pop is played before the ArtistSelected which means the component below on the stack will get the message after the navstack is update.

Menu

The menu component wraps the excellent The bubble/list component to let the user select from a menu of choices. Each choice is a model, title, and optional description which upon selection will take the user to this component's view. Menu expects to be used within a navigation stack. See the simple and deeper examples for detailed usage.

Breadcrumb

It is handy to give the user a sense of place by presenting a breadcrumb view showing them where they come from.

Checkout the deeper example for usage of breadcrumbs.

Shell

Finally the shell component emcapsulates the Breadcrumb and Navstack components allowing them to work together. See the simple and deeper examples to see how it works.

Documentation

Overview

Bubbleo is a collection of [BubbleTea] components for building robust terminal user interfaces. Initially we are supporting hierarchical menus, via a navigation stack and supporting components such as breadcrumbs, menus, and a composit component called shell which puts them all together. [BubbleTea]: https://github.com/charmbracelet/bubbletea

Directories

Path Synopsis
Package Breadcrumb is a component that consumes a pointer ot a navstack.Model and renders a breadcrumb trail.
Package Breadcrumb is a component that consumes a pointer ot a navstack.Model and renders a breadcrumb trail.
examples module
Package Menu takes a list of choices allowing the user to select a component to push onto the navigation stack.
Package Menu takes a list of choices allowing the user to select a component to push onto the navigation stack.
Package Navstack manages a stack of NavigationItems which can be pushed or popped from the stack.
Package Navstack manages a stack of NavigationItems which can be pushed or popped from the stack.
Package Shell is a basic wrapper around the navstack and breadcrumb packages It provides a basic navigation mechanism while showing breadcrumb view of where the user is within the navigation stack.
Package Shell is a basic wrapper around the navstack and breadcrumb packages It provides a basic navigation mechanism while showing breadcrumb view of where the user is within the navigation stack.
Package styles provides default styles for the bubbleo components
Package styles provides default styles for the bubbleo components
Package Utils is for bubblo utility functions
Package Utils is for bubblo utility functions
Package Windows holds the dimensions of the container window.
Package Windows holds the dimensions of the container window.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL