/go-cli-tools

Command-line tools and utilities for Go

Primary LanguageGoMIT LicenseMIT

go-cli-tools

Command-line tools and utilities for Go projects.

Go Reference

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))

โฌ† Back to Top

๐Ÿ’„ 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"))

โฌ† Back to Top

โ˜ 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))

โฌ† Back to Top

๐Ÿงผ 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)

โฌ† Back to Top

๐Ÿ…ฐ 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)

โฌ† Back to Top


๐Ÿ“š 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!")

โฌ† Back to Top


๐Ÿ“ƒ 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" }))

โฌ† Back to Top

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.

โฌ† Back to Top

Pad

Apply padding around the text.

import "github.com/Shresht7/go-cli-tools/format"
var text string = "..."
fmt.Println(format.Pad(text, " ", 5))

โฌ† Back to Top


๐Ÿ“ฆ Layout

Create a table.

import "github.com/Shresht7/go-cli-tools/layout"

var data [][]string // ...
table := layout.NewTable(data)
fmt.Println(table.String())

โœ” 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: โ†‘ โ†“ โ† โ†’

โฌ† Back to Top

โœ” 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

โฌ† Back to Top


๐Ÿ“‘ License

This project is licensed under the MIT License - see the LICENSE file for details.