Documentation ¶
Overview ¶
Example ¶
lw := NewWriter() // append a tree lw.AppendItem("George. R. R. Martin") lw.Indent() lw.AppendItem("A Song of Ice and Fire") lw.Indent() lw.AppendItems([]interface{}{ "Arya Stark", "Bran Stark", "Rickon Stark", "Robb Stark", "Sansa Stark", "Jon Snow", }) lw.UnIndent() lw.UnIndent() // append another tree lw.AppendItem("Stephen King") lw.Indent() lw.AppendItem("The Dark Tower") lw.Indent() lw.AppendItems([]interface{}{ "Jake Chambers", "Randal Flagg", "Roland Deschain", }) lw.UnIndent() lw.AppendItem("the shawshank redemption") lw.Indent() lw.AppendItems([]interface{}{ "andy dufresne", "byron hadley", "ellis boyd redding", "samuel norton", }) // customize rendering lw.SetStyle(StyleConnectedLight) lw.Style().CharItemTop = "├" lw.Style().Format = text.FormatTitle // render it fmt.Printf("Simple List:\n%s", lw.Render())
Output: Simple List: ├ George. R. R. Martin │ └─ A Song Of Ice And Fire │ ├─ Arya Stark │ ├─ Bran Stark │ ├─ Rickon Stark │ ├─ Robb Stark │ ├─ Sansa Stark │ └─ Jon Snow └─ Stephen King ├─ The Dark Tower │ ├─ Jake Chambers │ ├─ Randal Flagg │ └─ Roland Deschain └─ The Shawshank Redemption ├─ Andy Dufresne ├─ Byron Hadley ├─ Ellis Boyd Redding └─ Samuel Norton
Index ¶
- Constants
- Variables
- type List
- func (l *List) AppendItem(item interface{})
- func (l *List) AppendItems(items []interface{})
- func (l *List) Indent()
- func (l *List) Length() int
- func (l *List) Render() string
- func (l *List) RenderHTML() string
- func (l *List) RenderMarkdown() string
- func (l *List) Reset()
- func (l *List) SetHTMLCSSClass(cssClass string)
- func (l *List) SetOutputMirror(mirror io.Writer)
- func (l *List) SetStyle(style Style)
- func (l *List) Style() *Style
- func (l *List) UnIndent()
- type Style
- type Writer
Examples ¶
Constants ¶
const ( // DefaultHTMLCSSClass stores the css-class to use when none-provided via // SetHTMLCSSClass(cssClass string). DefaultHTMLCSSClass = "go-pretty-table" )
Variables ¶
var ( // StyleDefault renders a List like below: // * Game Of Thrones // * Winter // * Is // * Coming // * This // * Is // * Known // * The Dark Tower // * The Gunslinger StyleDefault = Style{ Format: text.FormatDefault, CharItemSingle: "*", CharItemTop: "*", CharItemFirst: "*", CharItemMiddle: "*", CharItemVertical: " ", CharItemBottom: "*", CharNewline: "\n", LinePrefix: "", Name: "StyleDefault", } // StyleBulletCircle renders a List like below: // ● Game Of Thrones // ● Winter // ● Is // ● Coming // ● This // ● Is // ● Known // ● The Dark Tower // ● The Gunslinger StyleBulletCircle = Style{ Format: text.FormatDefault, CharItemSingle: "●", CharItemTop: "●", CharItemFirst: "●", CharItemMiddle: "●", CharItemVertical: " ", CharItemBottom: "●", CharNewline: "\n", LinePrefix: "", Name: "StyleBulletCircle", } // StyleBulletFlower renders a List like below: // ✽ Game Of Thrones // ✽ Winter // ✽ Is // ✽ Coming // ✽ This // ✽ Is // ✽ Known // ✽ The Dark Tower // ✽ The Gunslinger StyleBulletFlower = Style{ Format: text.FormatDefault, CharItemSingle: "✽", CharItemTop: "✽", CharItemFirst: "✽", CharItemMiddle: "✽", CharItemVertical: " ", CharItemBottom: "✽", CharNewline: "\n", LinePrefix: "", Name: "StyleBulletFlower", } // StyleBulletSquare renders a List like below: // ■ Game Of Thrones // ■ Winter // ■ Is // ■ Coming // ■ This // ■ Is // ■ Known // ■ The Dark Tower // ■ The Gunslinger StyleBulletSquare = Style{ Format: text.FormatDefault, CharItemSingle: "■", CharItemTop: "■", CharItemFirst: "■", CharItemMiddle: "■", CharItemVertical: " ", CharItemBottom: "■", CharNewline: "\n", LinePrefix: "", Name: "StyleBulletSquare", } // StyleBulletStar renders a List like below: // ★ Game Of Thrones // ★ Winter // ★ Is // ★ Coming // ★ This // ★ Is // ★ Known // ★ The Dark Tower // ★ The Gunslinger StyleBulletStar = Style{ Format: text.FormatDefault, CharItemSingle: "★", CharItemTop: "★", CharItemFirst: "★", CharItemMiddle: "★", CharItemVertical: " ", CharItemBottom: "★", CharNewline: "\n", LinePrefix: "", Name: "StyleBulletStar", } // StyleBulletTriangle renders a List like below: // ▶ Game Of Thrones // ▶ Winter // ▶ Is // ▶ Coming // ▶ This // ▶ Is // ▶ Known // ▶ The Dark Tower // ▶ The Gunslinger StyleBulletTriangle = Style{ Format: text.FormatDefault, CharItemSingle: "▶", CharItemTop: "▶", CharItemFirst: "▶", CharItemMiddle: "▶", CharItemVertical: " ", CharItemBottom: "▶", CharNewline: "\n", LinePrefix: "", Name: "StyleBulletTriangle", } // StyleConnectedBold renders a List like below: // ┏━ Game Of Thrones // ┃ ┣━ Winter // ┃ ┣━ Is // ┃ ┗━ Coming // ┃ ┣━ This // ┃ ┣━ Is // ┃ ┗━ Known // ┗━ The Dark Tower // ┗━ The Gunslinger StyleConnectedBold = Style{ Format: text.FormatDefault, CharItemSingle: "━━", CharItemTop: "┏━", CharItemFirst: "┣━", CharItemMiddle: "┣━", CharItemVertical: "┃ ", CharItemBottom: "┗━", CharNewline: "\n", LinePrefix: "", Name: "StyleConnectedBold", } // StyleConnectedDouble renders a List like below: // ╔═ Game Of Thrones // ║ ╠═ Winter // ║ ╠═ Is // ║ ╚═ Coming // ║ ╠═ This // ║ ╠═ Is // ║ ╚═ Known // ╚═ The Dark Tower // ╚═ The Gunslinger StyleConnectedDouble = Style{ Format: text.FormatDefault, CharItemSingle: "══", CharItemTop: "╔═", CharItemFirst: "╠═", CharItemMiddle: "╠═", CharItemVertical: "║ ", CharItemBottom: "╚═", CharNewline: "\n", LinePrefix: "", Name: "StyleConnectedDouble", } // StyleConnectedLight renders a List like below: // ┌─ Game Of Thrones // │ ├─ Winter // │ ├─ Is // │ └─ Coming // │ ├─ This // │ ├─ Is // │ └─ Known // └─ The Dark Tower // └─ The Gunslinger StyleConnectedLight = Style{ Format: text.FormatDefault, CharItemSingle: "──", CharItemTop: "┌─", CharItemFirst: "├─", CharItemMiddle: "├─", CharItemVertical: "│ ", CharItemBottom: "└─", CharNewline: "\n", LinePrefix: "", Name: "StyleConnectedLight", } // StyleConnectedRounded renders a List like below: // ╭─ Game Of Thrones // │ ├─ Winter // │ ├─ Is // │ ╰─ Coming // │ ├─ This // │ ├─ Is // │ ╰─ Known // ╰─ The Dark Tower // ╰─ The Gunslinger StyleConnectedRounded = Style{ Format: text.FormatDefault, CharItemSingle: "──", CharItemTop: "╭─", CharItemFirst: "├─", CharItemMiddle: "├─", CharItemVertical: "│ ", CharItemBottom: "╰─", CharNewline: "\n", LinePrefix: "", Name: "StyleConnectedRounded", } // StyleMarkdown renders a List like below: // * Game Of Thrones // * Winter // * Is // * Coming // * This // * Is // * Known // * The Dark Tower // * The Gunslinger StyleMarkdown = Style{ Format: text.FormatDefault, CharItemSingle: "*", CharItemTop: "*", CharItemFirst: "*", CharItemMiddle: "*", CharItemVertical: " ", CharItemBottom: "*", CharNewline: "<br/>", LinePrefix: " ", Name: "StyleMarkdown", } )
Functions ¶
This section is empty.
Types ¶
type List ¶
type List struct {
// contains filtered or unexported fields
}
List helps print a 2-dimensional array in a human readable pretty-List.
func (*List) AppendItem ¶
func (l *List) AppendItem(item interface{})
AppendItem appends the item to the List of items to render.
func (*List) AppendItems ¶
func (l *List) AppendItems(items []interface{})
AppendItems appends the items to the List of items to render.
func (*List) Indent ¶
func (l *List) Indent()
Indent indents the following items to appear right-shifted.
func (*List) Render ¶
Render renders the List in a human-readable "pretty" format. Example:
- Game Of Thrones
- Winter
- Is
- Coming
- This
- Is
- Known
- The Dark Tower
- The Gunslinger
func (*List) RenderHTML ¶
RenderHTML renders the List in the HTML format. Example:
<ul class="go-pretty-table"> <li>Game Of Thrones</li> <ul class="go-pretty-table-1"> <li>Winter</li> <li>Is</li> <li>Coming</li> <ul class="go-pretty-table-2"> <li>This</li> <li>Is</li> <li>Known</li> </ul> </ul> <li>The Dark Tower</li> <ul class="go-pretty-table-1"> <li>The Gunslinger</li> </ul> </ul>
func (*List) RenderMarkdown ¶
RenderMarkdown renders the List in the Markdown format. Example:
- Game Of Thrones
- Winter
- Is
- Coming
- This
- Is
- Known
- The Dark Tower
- The Gunslinger
func (*List) SetHTMLCSSClass ¶
SetHTMLCSSClass sets the the HTML CSS Class to use on the <ul> node when rendering the List in HTML format. Recursive lists would use a numbered index suffix. For ex., if the cssClass is set as "foo"; the <ul> for level 0 would have the class set as "foo"; the <ul> for level 1 would have "foo-1".
func (*List) SetOutputMirror ¶
SetOutputMirror sets an io.Writer for all the Render functions to "Write" to in addition to returning a string.
type Style ¶
type Style struct { Format text.Format // formatting for the Text CharItemSingle string // the bullet for a single-item list CharItemTop string // the bullet for the top-most item CharItemFirst string // the bullet for the first item CharItemMiddle string // the bullet for non-first/non-last item CharItemVertical string // the vertical connector from one bullet to the next CharItemBottom string // the bullet for the bottom-most item CharNewline string // new-line character to use LinePrefix string // prefix for every single line Name string // name of the Style }
Style declares how to render the List (items).
type Writer ¶
type Writer interface { AppendItem(item interface{}) AppendItems(items []interface{}) Indent() Length() int Render() string RenderHTML() string RenderMarkdown() string Reset() SetHTMLCSSClass(cssClass string) SetOutputMirror(mirror io.Writer) SetStyle(style Style) Style() *Style UnIndent() }
Writer declares the interfaces that can be used to setup and render a list.