Giter Club home page Giter Club logo

clt's Introduction

CLT - Command Line Tools for Go

CLT is a toolset for building elegant command line interfaces in Go. CLT includes elements like styled text, tables, selections from a list, and more so that you can quickly build CLIs with interactive elements without the hassle of dealing with formatting all these yourself.

Go Doc documentation is available at [Godoc] and examples are located in the examples directory. This readme strives to show you the major features.

Styled Text

package main

import (
	"fmt"
	"github.com/BTBurke/clt"
)

func main() {
	fmt.Printf("This is %s text\n", clt.Style(clt.Red).ApplyTo("red"))
	fmt.Printf("This is %s text\n", clt.Style(clt.Blue, clt.Underline).ApplyTo("blue and underlined"))
	fmt.Printf("This is %s text\n", clt.Style(clt.Blue, clt.Background(clt.White)).ApplyTo("blue on a white background"))
	fmt.Printf("This is %s text\n", clt.Style(clt.Italic).ApplyTo("italic"))
	fmt.Printf("This is %s text\n", clt.Style(clt.Bold).ApplyTo("bold"))
}

console output

The general operation of the style function is to first call clt.Style(<Style1>, <Style2>, ...). This creates a style that can then be applied to a string via the .ApplyTo(<string>) method.

Tables

CLT provides an easy-to-use library for building text tables. It provides layout algorithms for multi-column tables and the ability to style each column or individual cells using clt.Style.

Tables detect the terminal width and intelligently decide how cell contents should be wrapped to fit on screen.

package main

import "github.com/BTBurke/clt"

func main() {

	// Create a table with 3 columns
	t := clt.NewTable(5)

	// Add a title
	t.SetTitle("Hockey Standings")

	// Set column headers
	t.SetColumnHeaders("Team", "Points", "W", "L", "OT")

	// Add some rows
	t.AddRow("Washington Capitals", "42", "18", "11", "6")
	t.AddRow("NJ Devils", "31", "12", "18", "7")

	// Render the table
	t.Show()
}

Produces:

console output

More examples

See examples/table_example.go for more examples. Also, see the GoDoc for the details of the table library.

Progress Bars

CLT provides two kinds of progress bars:

  • Spinner - Useful for when you want to show progress but don't know exactly when an action will complete

  • Bar - Useful when you have a defined number of iterations to completion and you can update progress during processing

Example:

See examples/progress_example.go for the example in the screencast below.

console output

Progress bars use go routines to update the progress status while your app does other processing. Remember to close out the progress element with either a call to Success() or Fail() to terminate this routine.

clt's People

Contributors

btburke avatar

Watchers

 avatar

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.