list

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2018 License: MIT Imports: 4 Imported by: 0

README

List

Pretty-print lists with multiple levels/indents into ASCII/Unicode strings.

  • Completely customizable styles
- Game Of Thrones
--- Winter
  - Is
  - Coming
  --- This
    - Is
    - Known

A demonstration of all the capabilities can be found here: ../cmd/demo-list

Find documentation here: GoDoc

TODO

  • Multi-line items
  • Line-width restrictions
  • Unindent
  • Render as HTML

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// StyleDefault renders a List like below:
	//  - Game Of Thrones
	//  --- Winter
	//    - Is
	//    - Coming
	//    --- This
	//      - Is
	//      - Known
	StyleDefault = Style{
		Format:           text.FormatDefault,
		CharConnect:      "-",
		CharItem:         "-",
		CharItemBottom:   "-",
		CharItemFirst:    "-",
		CharItemTop:      "-",
		CharPaddingLeft:  "-",
		CharPaddingRight: "",
		Name:             "StyleDefault",
	}

	// StyleBulletCircle renders a List like below:
	//  ● Game Of Thrones
	//    ● Winter
	//    ● Is
	//    ● Coming
	//      ● This
	//      ● Is
	//      ● Known
	StyleBulletCircle = Style{
		Format:           text.FormatDefault,
		CharConnect:      " ",
		CharItem:         text.BulletCircle,
		CharItemBottom:   text.BulletCircle,
		CharItemFirst:    text.BulletCircle,
		CharItemTop:      text.BulletCircle,
		CharPaddingLeft:  " ",
		CharPaddingRight: "",
		Name:             "StyleBulletCircle",
	}

	// StyleBulletFlower renders a List like below:
	//  ✽ Game Of Thrones
	//    ✽ Winter
	//    ✽ Is
	//    ✽ Coming
	//      ✽ This
	//      ✽ Is
	//      ✽ Known
	StyleBulletFlower = Style{
		Format:           text.FormatDefault,
		CharConnect:      " ",
		CharItem:         text.BulletFlower,
		CharItemBottom:   text.BulletFlower,
		CharItemFirst:    text.BulletFlower,
		CharItemTop:      text.BulletFlower,
		CharPaddingLeft:  " ",
		CharPaddingRight: "",
		Name:             "StyleBulletFlower",
	}

	// StyleBulletSquare renders a List like below:
	//  ■ Game Of Thrones
	//    ■ Winter
	//    ■ Is
	//    ■ Coming
	//      ■ This
	//      ■ Is
	//      ■ Known
	StyleBulletSquare = Style{
		Format:           text.FormatDefault,
		CharConnect:      " ",
		CharItem:         text.BulletSquare,
		CharItemBottom:   text.BulletSquare,
		CharItemFirst:    text.BulletSquare,
		CharItemTop:      text.BulletSquare,
		CharPaddingLeft:  " ",
		CharPaddingRight: "",
		Name:             "StyleBulletSquare",
	}

	// StyleBulletStar renders a List like below:
	//  ✭ Game Of Thrones
	//    ✭ Winter
	//    ✭ Is
	//    ✭ Coming
	//      ✭ This
	//      ✭ Is
	//      ✭ Known
	StyleBulletStar = Style{
		Format:           text.FormatDefault,
		CharConnect:      " ",
		CharItem:         text.BulletStar,
		CharItemBottom:   text.BulletStar,
		CharItemFirst:    text.BulletStar,
		CharItemTop:      text.BulletStar,
		CharPaddingLeft:  " ",
		CharPaddingRight: "",
		Name:             "StyleBulletStar",
	}

	// StyleBulletTriangle renders a List like below:
	//  ▶ Game Of Thrones
	//    ▶ Winter
	//    ▶ Is
	//    ▶ Coming
	//      ▶ This
	//      ▶ Is
	//      ▶ Known
	StyleBulletTriangle = Style{
		Format:           text.FormatDefault,
		CharConnect:      " ",
		CharItem:         text.BulletTrianglePointingRight,
		CharItemBottom:   text.BulletTrianglePointingRight,
		CharItemFirst:    text.BulletTrianglePointingRight,
		CharItemTop:      text.BulletTrianglePointingRight,
		CharPaddingLeft:  " ",
		CharPaddingRight: "",
		Name:             "StyleBulletTriangle",
	}

	// StyleConnectedBold renders a List like below:
	//  ┏━ Game Of Thrones
	//  ┗━┳━ Winter
	//    ┣━ Is
	//    ┣━ Coming
	//    ┗━┳━ This
	//      ┣━ Is
	//      ┗━ Known
	StyleConnectedBold = Style{
		Format:           text.FormatDefault,
		CharConnect:      text.BoxBottomLeftBold,
		CharItem:         text.BoxLeftSeparatorBold,
		CharItemBottom:   text.BoxBottomLeftBold,
		CharItemFirst:    text.BoxTopSeparatorBold,
		CharItemTop:      text.BoxTopLeftBold,
		CharPaddingLeft:  text.BoxHorizontalBold,
		CharPaddingRight: text.BoxHorizontalBold,
		Name:             "StyleConnectedBold",
	}

	// StyleConnectedDouble renders a List like below:
	//  ╔═ Game Of Thrones
	//  ╚═╦═ Winter
	//    ╠═ Is
	//    ╠═ Coming
	//    ╚═╦═ This
	//      ╠═ Is
	//      ╚═ Known
	StyleConnectedDouble = Style{
		Format:           text.FormatDefault,
		CharConnect:      text.BoxBottomLeftDouble,
		CharItem:         text.BoxLeftSeparatorDouble,
		CharItemBottom:   text.BoxBottomLeftDouble,
		CharItemFirst:    text.BoxTopSeparatorDouble,
		CharItemTop:      text.BoxTopLeftDouble,
		CharPaddingLeft:  text.BoxHorizontalDouble,
		CharPaddingRight: text.BoxHorizontalDouble,
		Name:             "StyleConnectedDouble",
	}

	// StyleConnectedLight renders a List like below:
	//  ┌─ Game Of Thrones
	//  └─┬─ Winter
	//    ├─ Is
	//    ├─ Coming
	//    └─┬─ This
	//      ├─ Is
	//      └─ Known
	StyleConnectedLight = Style{
		Format:           text.FormatDefault,
		CharConnect:      text.BoxBottomLeft,
		CharItem:         text.BoxLeftSeparator,
		CharItemBottom:   text.BoxBottomLeft,
		CharItemFirst:    text.BoxTopSeparator,
		CharItemTop:      text.BoxTopLeft,
		CharPaddingLeft:  text.BoxHorizontal,
		CharPaddingRight: text.BoxHorizontal,
		Name:             "StyleConnectedLight",
	}

	// StyleConnectedRounded renders a List like below:
	//  ╭─ Game Of Thrones
	//  ╰─┬─ Winter
	//    ├─ Is
	//    ├─ Coming
	//    ╰─┬─ This
	//      ├─ Is
	//      ╰─ Known
	StyleConnectedRounded = Style{
		Format:           text.FormatDefault,
		CharConnect:      text.BoxBottomLeftRounded,
		CharItem:         text.BoxLeftSeparator,
		CharItemBottom:   text.BoxBottomLeftRounded,
		CharItemFirst:    text.BoxTopSeparator,
		CharItemTop:      text.BoxTopLeftRounded,
		CharPaddingLeft:  text.BoxHorizontal,
		CharPaddingRight: text.BoxHorizontal,
		Name:             "StyleConnectedRounded",
	}
)

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

func (l *List) Length() int

Length returns the number of items to be rendered.

func (*List) Render

func (l *List) Render() string

Render renders the List in a human-readable "pretty" format. Example:

┌─ Game Of Thrones
└─┬─ Winter
  ├─ Is
  ├─ Coming
  └─┬─ This
    ├─ Is
    └─ Known

func (*List) SetStyle

func (l *List) SetStyle(style Style)

SetStyle overrides the DefaultStyle with the provided one.

func (*List) Style

func (l *List) Style() *Style

Style returns the current style.

type Style

type Style struct {
	Format           text.Format
	CharConnect      string
	CharItem         string
	CharItemBottom   string
	CharItemFirst    string
	CharItemTop      string
	CharPaddingLeft  string
	CharPaddingRight string
	Name             string
}

Style declares how to render the List.

type Writer

type Writer interface {
	AppendItem(item interface{})
	AppendItems(items []interface{})
	Indent()
	Length() int
	Render() string
	SetStyle(style Style)
	Style() *Style
}

Writer declares the interfaces that can be used to setup and render a list.

func NewWriter

func NewWriter() Writer

NewWriter initializes and returns a Writer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL