go-cli-tools
Command-line tools and utilities for Go projects.
Table of Contents
π¦ ANSI Modules
π¨ Colors
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))
π Styles
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"))
β Cursor
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))
π§Ό Clear
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)
π ° RegExp
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)
π Helpers
π Composition
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!")
π Format
Align
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
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.
Pad
Apply padding around the text.
import "github.com/Shresht7/go-cli-tools/format"
var text string = "..."
fmt.Println(format.Pad(text, " ", 5))
β Symbols
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: β β β β
β Status
The status
package includes some commonly used symbols with color.
import "github.com/Shresht7/go-cli-tools/status"
fmt.Println(status.Tick, "Done") // β Done
π License
This project is licensed under the MIT License - see the LICENSE file for details.