• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.travis.ymlH A D15-Sep-201525

COPYINGH A D15-Sep-20151 KiB

README.mdH A D15-Sep-20151.8 KiB

columnize.goH A D15-Sep-20153.3 KiB

columnize_test.goH A D15-Sep-20155.3 KiB

README.md

1Columnize
2=========
3
4Easy column-formatted output for golang
5
6[![Build Status](https://travis-ci.org/ryanuber/columnize.svg)](https://travis-ci.org/ryanuber/columnize)
7
8Columnize is a really small Go package that makes building CLI's a little bit
9easier. In some CLI designs, you want to output a number similar items in a
10human-readable way with nicely aligned columns. However, figuring out how wide
11to make each column is a boring problem to solve and eats your valuable time.
12
13Here is an example:
14
15```go
16package main
17
18import (
19    "fmt"
20    "github.com/ryanuber/columnize"
21)
22
23func main() {
24    output := []string{
25        "Name | Gender | Age",
26        "Bob | Male | 38",
27        "Sally | Female | 26",
28    }
29    result := columnize.SimpleFormat(output)
30    fmt.Println(result)
31}
32```
33
34As you can see, you just pass in a list of strings. And the result:
35
36```
37Name   Gender  Age
38Bob    Male    38
39Sally  Female  26
40```
41
42Columnize is tolerant of missing or empty fields, or even empty lines, so
43passing in extra lines for spacing should show up as you would expect.
44
45Configuration
46=============
47
48Columnize is configured using a `Config`, which can be obtained by calling the
49`DefaultConfig()` method. You can then tweak the settings in the resulting
50`Config`:
51
52```
53config := columnize.DefaultConfig()
54config.Delim = "|"
55config.Glue = "  "
56config.Prefix = ""
57config.Empty = ""
58```
59
60* `Delim` is the string by which columns of **input** are delimited
61* `Glue` is the string by which columns of **output** are delimited
62* `Prefix` is a string by which each line of **output** is prefixed
63* `Empty` is a string used to replace blank values found in output
64
65You can then pass the `Config` in using the `Format` method (signature below) to
66have text formatted to your liking.
67
68Usage
69=====
70
71```go
72SimpleFormat(intput []string) string
73
74Format(input []string, config *Config) string
75```
76