An open API service indexing awesome lists of open source software.

https://github.com/shresht7/go-cli-tools

Command-line tools and utilities for Go
https://github.com/shresht7/go-cli-tools

cli go

Last synced: 2 months ago
JSON representation

Command-line tools and utilities for Go

Awesome Lists containing this project

README

        

# `go-cli-tools`

Command-line tools and utilities for Go projects.

[![Go Reference](https://pkg.go.dev/badge/github.com/Shresht7/go-cli-tools.svg)](https://pkg.go.dev/github.com/Shresht7/go-cli-tools)

Table of Contents

- [๐Ÿ“ฆ ANSI Modules](#-ansi-modules)
- [๐ŸŽจ Colors](#-colors)
- [๐Ÿ’„ Styles](#-styles)
- [โ˜ Cursor](#-cursor)
- [๐Ÿงผ Clear](#-clear)
- [๐Ÿ…ฐ RegExp](#-regexp)
- [๐Ÿ“š Helpers](#-helpers)
- [๐Ÿญ Composition](#-composition)
- [๐Ÿ“ƒ Format](#-format)
- [Align](#align)
- [HereDoc](#heredoc)
- [Pad](#pad)
- [๐Ÿ“ฆ Layout](#-layout)
- [โœ” Symbols](#-symbols)
- [โœ” Status](#-status)
- [๐Ÿ“‘ License](#-license)

---

## ๐Ÿ“ฆ ANSI Modules

### ๐ŸŽจ Colors

The colors package allows you to style text with colors.

```go
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][top]

### ๐Ÿ’„ Styles

The styles package allows you to format your text.

```go
import "github.com/Shresht7/go-cli-tools/ansi/styles"

fmt.Println(styles.Bold("GO"))
fmt.Println(styles.Hidden("Secret"))
```

[โฌ† Back to Top][top]

### โ˜ Cursor

The cursor package provides helper function for cursor manipulation.

```go
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][top]

### ๐Ÿงผ Clear

The clear package provides helper functions to clear the terminal.

```go
import "github.com/Shresht7/go-cli-tools/ansi/clear"

fmt.Println(clear.EntireLine)
fmt.Println(clear.Screen)
```

[โฌ† Back to Top][top]

### ๐Ÿ…ฐ RegExp

Regular expressions to capture ansi codes. The `Strip` helper function can remove all ansi escape codes from a string.

```go
import "github.com/Shresht7/go-cli-tools/ansi/codes"

var text string = "..."
text = codes.Strip(text)
fmt.Println(text)
```

[โฌ† Back to Top][top]

---

## ๐Ÿ“š Helpers

### ๐Ÿญ Composition

Composition helpers provide two utility functions compose and pipe that allow you to combine many ansi functions together.

```go
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][top]

---

## ๐Ÿ“ƒ Format

### Align

Align text to the left, center or right.

```go
import "github.com/Shresht7/go-cli-tools/format"
var text string = "..."
fmt.Println(format.Align(text, &format.AlignOptions{ Mode: "Center" }))
```

[โฌ† Back to Top][top]

### HereDoc

HereDoc is a helper function to create a multi-line string.

```go
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][top]

### Pad

Apply padding around the text.

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

[โฌ† Back to Top][top]

---

## ๐Ÿ“ฆ Layout

Create a table.

```go
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

```
โœ” โ„น โš  โœ– โ˜ฐ โ†‘ โ†“ โ† โ†’ โ™ช โ™ซ โ–  โ— โ€ค โ€ฆ โ€บ โ–ฒ โ–ด โ–ผ โ–พ โ—‚ โ–ธ โŒ‚ โ™ฅ โ†” โ†• โ‰ˆ โ‰  โ‰ค โ‰ฅ โ‰ก โˆž เทด โ˜… โ–ถ โฌข
```

```go
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][top]

## โœ” Status

The `status` package includes some commonly used symbols with color.

```go
import "github.com/Shresht7/go-cli-tools/status"

fmt.Println(status.Tick, "Done") // โœ” Done
```

[โฌ† Back to Top][top]

---

## ๐Ÿ“‘ License

This project is licensed under the [MIT License](LICENSE) - see the [LICENSE](LICENSE) file for details.

[top]: #go-cli-tools