/gridt

Display contents as a grid in the terminal!

Primary LanguageGoThe UnlicenseUnlicense

Gridt

License go.dev Travis CI Codecov.io Go Report Card

Display contents as a grid in the terminal!

Format unidimensional lists (slices) as grids, with well-defined columns, suitable for fixed-width fonts, for the sake of readability.

It's both a CLI and a Go library.

Inspired by ogham/rust-term-grid and by the fact that I needed it for paemuri/ipe.

Example

What we do not want:

What we do not want

What we want:

What we want

Install

Brew

brew tap paemuri/packages
brew install gridt

Go

go install github.com/paemuri/gridt/cmd/gridt

Run

Default

gridt

Runs the program with default configuration. It gets the values from stdin lines.

Flags

-h or --help

Shows the CLI help message.

-v or --version

Shows the CLI version.

-f <file> or --file <file>

Instead of getting the lines from stdin, gets it from a specific file.

-s <sep> or --separator <sep>

Defines what separates every value column. Defaults to " ".

-d <direction> or --direction <direction>

Defines writing direction. It can be top-to-bottom or left-to-right. Defaults to top-to-bottom.

Library usage

// Just create an empty grid...
grid := gridt.New(gridt.TopToBottom, "  ")

// Verify if it fits in a determined width...
dim, ok := grid.FitIntoWidth(100)

// And get its string!
if ok {
  fmt.Print(dim.String())
}
// But also, you can do a lot more!

// Create a grid with pre-defined cells...
grid := gridt.New(gridt.LeftToRight, "  ", "cell1", "cell2", "cell3")

// Manipulate the cells...
grid.Add("cell4", "cell5", "cell6")
grid.Insert(2, "cell2.1", "cell2.3")
grid.Delete(0)

// Base the size of the grid on the number of columns,
// instead of the number of caracters...
dim, ok := grid.FitIntoColumns(3)

License

This project code is in the public domain. See the LICENSE file.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be in the public domain, without any additional terms or conditions.