helper

package
v3.4.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2020 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Examples

Constants

View Source
const (
	CENTRE = "+"
	ROW    = "-"
	COLUMN = "|"
	SPACE  = " "
	EMPTY  = ""
)
View Source
const (
	ALIGN_DEFAULT = iota
	ALIGN_CENTRE
	ALIGN_RIGHT
	ALIGN_LEFT
)
View Source
const (
	MAX_ROW_WIDTH = 30
)

Variables

This section is empty.

Functions

func ConditionString

func ConditionString(cond bool, valid, inValid string) string

Simple Condition for string Returns value based on condition

func DisplayWidth

func DisplayWidth(str string) int

func Pad

func Pad(s, pad string, width int) string

Pad String Attempts to play string in the center

func PadLeft

func PadLeft(s, pad string, width int) string

Pad String Left position This would pace string at the right side fo the screen

func PadRight

func PadRight(s, pad string, width int) string

Pad String Right position This would pace string at the left side fo the screen

func Title

func Title(name string) string

Format Table Header Replace spaces

func WrapString

func WrapString(s string, lim int) ([]string, int)

Wrap wraps s into a paragraph of lines of length lim, with minimal raggedness.

func WrapWords

func WrapWords(words []string, spc, lim, pen int) [][]string

WrapWords is the low-level line-breaking algorithm, useful if you need more control over the details of the text wrapping process. For most uses, WrapString will be sufficient and more convenient.

WrapWords splits a list of words into lines with minimal "raggedness", treating each rune as one unit, accounting for spc units between adjacent words on each line, and attempting to limit lines to lim units. Raggedness is the total error over all lines, where error is the square of the difference of the length of the line and lim. Too-long lines (which only happen when a single word is longer than lim units) have pen penalty units added to the error.

Types

type Table

type Table struct {
	// contains filtered or unexported fields
}
Example
tb := NewTable(os.Stdout)
tb.SetHeader([]string{"AAA", "BBB", "CCC"})
tb.Append([]string{"aaa", "bbb", "ccc"})
tb.Append([]string{"aaa", "bbbbbb", "ccc"})
tb.Append([]string{"aaa", "bbbbbbbbb", "ccc"})
tb.Render()
Output:

+-----+-----------+-----+
| AAA | BBB       | CCC |
+-----+-----------+-----+
| aaa | bbb       | ccc |
| aaa | bbbbbb    | ccc |
| aaa | bbbbbbbbb | ccc |
+-----+-----------+-----+

func NewPlainTable

func NewPlainTable(writer io.Writer) *Table

func NewTable

func NewTable(writer io.Writer) *Table

Start New Table Take io.Writer Directly

func (*Table) Append

func (t *Table) Append(row []string) error

Append row to table

func (*Table) AppendBulk

func (t *Table) AppendBulk(rows [][]string) (err error)

Allow Support for Bulk Append Eliminates repeated for loops

func (Table) Render

func (t Table) Render()

Render table output

func (*Table) SetAlignment

func (t *Table) SetAlignment(align int)

Set Table Alignment

func (*Table) SetAutoFormatHeaders

func (t *Table) SetAutoFormatHeaders(auto bool)

Turn header autoformatting on/off. Default is on (true).

func (*Table) SetAutoWrapText

func (t *Table) SetAutoWrapText(auto bool)

Turn automatic multiline text adjustment on/off. Default is on (true).

func (*Table) SetBorder

func (t *Table) SetBorder(border bool)

Set Table Border This would enable / disable line around the table

func (*Table) SetCenterSeparator

func (t *Table) SetCenterSeparator(sep string)

Set the center Separator

func (*Table) SetColWidth

func (t *Table) SetColWidth(width int)

Set the Default column width

func (*Table) SetColumnSeparator

func (t *Table) SetColumnSeparator(sep string)

Set the Column Separator

func (*Table) SetHeader

func (t *Table) SetHeader(keys []string)

Set table header

func (*Table) SetNoHeaderLine

func (t *Table) SetNoHeaderLine(b bool)

func (*Table) SetRowLine

func (t *Table) SetRowLine(line bool)

Set Row Line This would enable / disable a line on each row of the table

func (*Table) SetRowSeparator

func (t *Table) SetRowSeparator(sep string)

Set the Row Separator

Jump to

Keyboard shortcuts

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