Command-line tools and utilities for Go projects.
Table of Contents
The colors package allows you to style text with colors.
import "github.com/Shresht7/go-cli-tools/ansi/colors"
fmt.Println(colors.Red("Giant"))
fmt.Println(colors.BgWhite("Dwarf"))
fmt.Println(colors.RGB("Supernova", 224, 65, 137))
The styles package allows you to format your text.
import "github.com/Shresht7/go-cli-tools/ansi/styles"
fmt.Println(styles.Bold("GO"))
fmt.Println(styles.Hidden("Secret"))
The cursor package provides helper function for cursor manipulation.
import "github.com/Shresht7/go-cli-tools/ansi/cursor"
fmt.Print(cursor.ToPos(15, 20))
fmt.Print(cursor.Up(3))
fmt.Print(cursor.ToNextLine(5))
The clear package provides helper functions to clear the terminal.
import "github.com/Shresht7/go-cli-tools/ansi/clear"
fmt.Println(clear.EntireLine)
fmt.Println(clear.Screen)
Regular expressions to capture ansi codes. The Strip
helper function can remove all ansi escape codes from a string.
import "github.com/Shresht7/go-cli-tools/ansi/codes"
var text string = "..."
text = codes.Strip(text)
fmt.Println(text)
Composition helpers provide two utility functions compose and pipe that allow you to combine many ansi functions together.
import "github.com/Shresht7/go-cli-tools/helpers"
import "github.com/Shresht7/go-cli-tools/ansi/colors"
import "github.com/Shresht7/go-cli-tools/ansi/styles"
styler = helpers.Compose(colors.Blue, styles.Bold, colors.BgWhite)
text = styler("Function Composition!")
Align text to the left, center or right.
import "github.com/Shresht7/go-cli-tools/format"
var text string = "..."
fmt.Println(format.Align(text, &format.AlignOptions{ Mode: "Center" }))
HereDoc is a helper function to create a multi-line string.
import "github.com/Shresht7/go-cli-tools/format"
var text string = format.HereDoc(`
This is a multi-line string
that can be used to create
a template.
`)
// Output:
// This is a multi-line string
// that can be used to create
// a template.
Apply padding around the text.
import "github.com/Shresht7/go-cli-tools/format"
var text string = "..."
fmt.Println(format.Pad(text, " ", 5))
Create a table.
import "github.com/Shresht7/go-cli-tools/layout"
var data [][]string // ...
table := layout.NewTable(data)
fmt.Println(table.String())
Unicode symbols for the terminal
โ โน โ โ โฐ โ โ โ โ โช โซ โ โ โค โฆ โบ โฒ โด โผ โพ โ โธ โ โฅ โ โ โ โ โค โฅ โก โ เทด โ
โถ โฌข
import "github.com/Shresht7/go-cli-tools/symbols"
fmt.Println(symbols.Warning, "Are you sure?")
// โ Are you sure?
fmt.Println(symbols.Tick, "Done")
// โ Done
fmt.Println("Controls: ", symbols.ArrowUp, symbols.ArrowDown, symbol.ArrowLeft, symbols.ArrowRight)
// Controls: โ โ โ โ
The status
package includes some commonly used symbols with color.
import "github.com/Shresht7/go-cli-tools/status"
fmt.Println(status.Tick, "Done") // โ Done
This project is licensed under the MIT License - see the LICENSE file for details.