Documentation ¶
Overview ¶
proptree handles nested node tree with properties `Name`, `Icon`, `Tag` and `Description`.
Index ¶
- type N
- func (n *N) Append(c *N) *N
- func (n *N) Description(description string, c ...color.Attribute) *N
- func (n *N) DescriptionColor(c ...color.Attribute) *N
- func (n *N) Descriptions(descriptions []string, c ...color.Attribute) *N
- func (n *N) Icon(icon string, c ...color.Attribute) *N
- func (n *N) IconColor(c ...color.Attribute) *N
- func (n *N) NameColor(c ...color.Attribute) *N
- func (n *N) RenderAsText(w io.Writer, opts ...*RenderTextOptions) error
- func (n *N) RenderName() string
- func (n *N) Tag(tag string, c ...color.Attribute) *N
- func (n *N) TagColor(c ...color.Attribute) *N
- type RenderTextOptions
- func (o *RenderTextOptions) Relax() *RenderTextOptions
- func (o *RenderTextOptions) SetGlobalDescriptionColor(c ...color.Attribute) *RenderTextOptions
- func (o *RenderTextOptions) SetGlobalIconColor(c ...color.Attribute) *RenderTextOptions
- func (o *RenderTextOptions) SetGlobalNameColor(c ...color.Attribute) *RenderTextOptions
- func (o *RenderTextOptions) SetGlobalTagColor(c ...color.Attribute) *RenderTextOptions
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type N ¶
type N struct { Prop *prop `json:"prop,omitempty" yaml:"prop,omitempty"` Children []*N `json:"children,omitempty" yaml:"children,omitempty"` // contains filtered or unexported fields }
N stores node data.
func (*N) Description ¶
Description is a setter to set a string for description attribute. 2nd- args are set for `DescriptionColor` attribute.
func (*N) DescriptionColor ¶ added in v0.3.0
DescriptionColor is a setter for a color attribute for a description property.
func (*N) Descriptions ¶ added in v0.2.0
Descriptions method is a setter to set multiple lines for description attribute. 2nd- args are set for `DescriptionColor` attribute.
func (*N) Icon ¶
Icon is a setter to set a string for icon attribute. 2nd- args are set for `IconColor` attribute.
func (*N) IconColor ¶ added in v0.3.0
IconColor is a setter for a color attribute for an icon property.
func (*N) NameColor ¶ added in v0.3.0
NameColor is a setter for a color attribute for a name property.
func (*N) RenderAsText ¶
func (n *N) RenderAsText(w io.Writer, opts ...*RenderTextOptions) error
RenderAsText renders a node tree as text, and output.
Example ¶
package main import ( "os" pt "github.com/bayashi/go-proptree" ) func main() { n := tree() n.RenderAsText(os.Stdout) } func tree() *pt.N { tree := pt.Node("Version History"). Description("This is version history of Fake Software."). Description("Life is full of ups and downs.") node1 := pt.Node("1.0") tree.Append(node1) node11 := pt.Node("1.1") node1.Append(node11) node11.Append(pt.Node("1.1.1").Icon("!")) node11.Append(pt.Node("1.1.2").Icon("*")) node12 := pt.Node("1.2") node1.Append(node12) node12.Append(pt.Node("1.2.1").Icon("*")) node13 := pt.Node("1.3").Description("Implemented GUI from this version.") node1.Append(node13) node13.Append(pt.Node("1.3.1")) node132 := pt.Node("1.3.2") node13.Append(node132) node132.Append(pt.Node("1.3.2.1")) node132.Append(pt.Node("1.3.2.2").Icon("*")) node13.Append(pt.Node("1.3.3").Tag("Stable")) node1.Append(pt.Node("1.4").Icon("!")) node1.Append(pt.Node("1.5").Icon("*").Tag("Newest")) return tree }
Output: ┌ Version History │ This is version history of Fake Software. │ Life is full of ups and downs. └─┬ 1.0 ├─┬ 1.1 │ ├──! 1.1.1 │ └──* 1.1.2 ├─┬ 1.2 │ └──* 1.2.1 ├─┬ 1.3 │ │ Implemented GUI from this version. │ ├── 1.3.1 │ ├─┬ 1.3.2 │ │ ├── 1.3.2.1 │ │ └──* 1.3.2.2 │ └── 1.3.3: Stable ├──! 1.4 └──* 1.5: Newest
func (*N) RenderName ¶ added in v0.3.0
type RenderTextOptions ¶
type RenderTextOptions struct { // symbols HorizontalLink string VerticalLink string RootLink string ChildLink string LastChildLink string ChildrenLink string // properties GlobalIcon string GlobalTag string GlobalDescriptions []string TagFormat string // color GlobalNameColor *color.Color GlobalIconColor *color.Color GlobalTagColor *color.Color GlobalDescriptionColor *color.Color // dimensions MarginTop int MarginLeft int ChildrenMarginTop int ChildrenMarginBottom int HorizontalLinkLen int NamePaddingLeftLen int // behavior TurnOffProp bool // contains filtered or unexported fields }
RenderTextOptions is a struct for rendering text.
func RenderTextDefaultOptions ¶
func RenderTextDefaultOptions() *RenderTextOptions
RenderTextDefaultOptions is a dataset of rendering options by default.
func (*RenderTextOptions) Relax ¶
func (o *RenderTextOptions) Relax() *RenderTextOptions
Relax is a optional data adjuster for relaxed view.
func (*RenderTextOptions) SetGlobalDescriptionColor ¶ added in v0.3.0
func (o *RenderTextOptions) SetGlobalDescriptionColor(c ...color.Attribute) *RenderTextOptions
SetGlobalDescriptionColor is a setter to set GlobalDescriptionColor
func (*RenderTextOptions) SetGlobalIconColor ¶ added in v0.3.0
func (o *RenderTextOptions) SetGlobalIconColor(c ...color.Attribute) *RenderTextOptions
SetGlobalIconColor is a setter to set GlobalIconColor
func (*RenderTextOptions) SetGlobalNameColor ¶ added in v0.3.0
func (o *RenderTextOptions) SetGlobalNameColor(c ...color.Attribute) *RenderTextOptions
SetGlobalNameColor is a setter to set GlobalNameColor
func (*RenderTextOptions) SetGlobalTagColor ¶ added in v0.3.0
func (o *RenderTextOptions) SetGlobalTagColor(c ...color.Attribute) *RenderTextOptions
SetGlobalTagColor is a setter to set GlobalTagColor