Categorygithub.com/mitchellh/go-glint
modulepackage
0.0.0-20210722152315-6515ceb4a127
Repository: https://github.com/mitchellh/go-glint.git
Documentation: pkg.go.dev

# README

go-glint Godoc

Glint is a component-based UI framework specifically targeted towards command-line interfaces. This allows you to create highly dynamic CLI interfaces using shared, easily testable components. Glint uses a Flexbox implementation to make it easy to lay out components in the CLI, including paddings, margins, and more.

API Status: Unstable. We're still actively working on the API and may change it in backwards incompatible ways. See the roadmap section in particular for work that may impact the API. In particular, we have integrated this library into Waypoint, and the experience of using this library in the real world will likely drive major changes.

Example

The example below shows a simple dynamic counter:

func main() {
	var counter uint32
	go func() {
		for {
			time.Sleep(100 * time.Millisecond)
			atomic.AddUint32(&counter, 1)
		}
	}()

	d := glint.New()
	d.Append(
		glint.Style(
			glint.TextFunc(func(rows, cols uint) string {
				return fmt.Sprintf("%d tests passed", atomic.LoadUint32(&counter))
			}),
			glint.Color("green"),
		),
	)
	d.Render(context.Background())
}

Output:

Example

Roadmap

Glint is still an early stage project and there is a lot that we want to improve on. This may introduce some backwards incompatibilities but we are trying to stabilize the API as quickly as possible.

  • Non-interactive interfaces. We want to add support for rendering to non-interactive interfaces and allowing components to provide custom behavior in these cases. For now, users of Glint should detect non-interactivity and avoid using Glint.

  • Windows PowerShell and Cmd. Glint works fine in ANSI-compatible terminals on Windows, but doesn't work with PowerShell and Cmd. We want to make this work.

  • Dirty tracking. Glint currently rerenders the entire frame on each tick. I'd like components to be able to report if there are changes (if they are "dirty") and need to be rerendered. We could then more efficiently recalculate layouts and rerender outputs.

  • User Input. Glint should be able to query for user input and render this within its existing set of components.

  • Expose styling to custom renderers. Currently the Style component is a special-case for the terminal renderer to render colors. I'd like to expose the styles in a way that other renderers could use it in some meaningful way.

Thanks

This library is heavily inspired by the Ink project. I saw this project and thought that having a central render loop along with a full layout engine was a fantastic idea. Most of my projects are in Go so I wanted to be able to realize these benefits with Go. Thank you!

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

BGColor sets the background color by name.
BGColorHex sets the background color by hex code.
BGColorRGB sets the background color by RGB values.
Bold sets the text to bold.
Color sets the color by name.
ColorHex sets the foreground color by hex code.
ColorRGB sets the foreground color by RGB values.
Context is a component type that can be used to set data on the context given to Body calls for components that are children of this component.
Finalize reutrns a component that will finalize the input component.
Fragment appends multiple components together.
Italic sets the text to italic.
Layout is used to set layout properties for the child components.
MeasureTextNode implements flex.MeasureFunc and returns the measurements for the given node only if the node represents a TextComponent.
New returns a Document that will output to stdout.
RendererFromContext returns the Renderer in the context or nil if no Renderer is found.
Style applies visual styles to this component and any children.
TestRender renders the component using the string renderer and returns the string.
Text creates a TextComponent for static text.
TextFunc creates a TextComponent for text that is dependent on the size of the draw area.
Underline sets the text to be underlined.
WithRenderer inserts the renderer into the context.

# Structs

Document is the primary structure for managing and drawing components.
LayoutComponent is a component used for layout settings.
StringRenderer renders output to a string builder.
TerminalRenderer renders output to a terminal.
TextComponent is a Component that renders text.
TextNodeContext is the *flex.Node.Context set for all *TextComponent flex nodes.

# Interfaces

Components are the individual items that are rendered within a document.
ComponentFinalizer allows components to be notified they are going to be finalized.
ComponentMounter allows components to be notified when they are mounted and unmounted.
Renderers are responsible for helping configure layout properties and ultimately drawing components.

# Type aliases

StyleOption is an option that can be set when creating Text components.