GithubHelp home page GithubHelp logo

mitchellh / go-glint Goto Github PK

View Code? Open in Web Editor NEW
311.0 12.0 8.0 207 KB

Component-based UI-framework for command-line tools. Easily create highly dynamic CLI interfaces using shared, easily testable components.

License: MIT License

Go 100.00%
go golang

go-glint's Introduction

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!

go-glint's People

Contributors

dingoeatingfuzz avatar mitchellh avatar tgross avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-glint's Issues

Trailing newline breaks rendering

Using the following code:

d := glint.New()

d.Append(
	glint.Layout(
		gc.Spinner(),
		glint.Layout(glint.Text("Build site and validate links...")).MarginLeft(1),
		glint.Layout(gc.Stopwatch(time.Now())).MarginLeft(1),
	).Row(),
	glint.Layout(
		glint.Text("multi\nline\nmessage\n"),
	).Row(),
)

d.Render(context.Background())

Causes the following output:

⠙ Build site and validate links... 0s
⠙ Build site and validate links... 100ms
⠹ Build site and validate links... 100ms
⠹ Build site and validate links... 200ms
⠸ Build site and validate links... 300ms
⠸ Build site and validate links... 400ms
multi
line
message
^Csignal: interrupt

Removing the trailing \n from the glint.Text("multi\nline\nmessage\n"), line makes it work as expected.

I think it might be worth trimming the TextFunc output before rendering, but not sure if this is the right approach.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.