linewriter

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: MIT Imports: 6 Imported by: 12

README

linewriter

a programmatic fmt.Println

Documentation

Index

Examples

Constants

View Source
const DefaultFlags = AlignRight | Text | Second | TrueFalse | Decimal | Float | SizeIEC

Variables

This section is empty.

Functions

This section is empty.

Types

type Flag

type Flag uint64
const (
	AlignLeft Flag = 1 << iota
	AlignRight
	AlignCenter
	WithZero
	WithSign
	WithPrefix
	WithQuote
	NoSpace
	NoPadding
	NoSeparator
	YesNo
	OnOff
	TrueFalse
	OneZero
	Hex
	Octal
	Binary
	Decimal
	Percent
	Float
	Scientific
	Text
	Bytes
	Second
	Millisecond
	Microsecond
	SizeSI
	SizeIEC
)

type Option

type Option func(*Writer)

func AsCSV

func AsCSV(quoted bool) Option
Example
w1 := NewWriter(256, AsCSV(false))
w1.AppendUint(1, 4, AlignRight)
w1.AppendUint(1, 4, AlignRight|Hex|WithZero)
w1.AppendString("playback", 10, AlignLeft)
w1.AppendUint(44, 2, AlignLeft|Decimal)
w1.AppendBool(false, 3, AlignCenter|OnOff)

w2 := NewWriter(256, AsCSV(true))
w2.AppendUint(1, 4, AlignRight)
w2.AppendUint(1, 4, AlignRight|Hex|WithZero)
w2.AppendString("playback", 10, AlignLeft)
w2.AppendUint(44, 2, AlignLeft|Decimal)
w2.AppendBool(false, 3, AlignCenter|OnOff)

fmt.Println(w1.String())
fmt.Println(w2.String())
Output:

1,0001,playback,44,off
"1","0001","playback","44","off"

func WithCRLF

func WithCRLF() Option

func WithFlag

func WithFlag(flag Flag) Option

func WithLabel

func WithLabel(p string) Option

func WithPadding

func WithPadding(pad []byte) Option

func WithSeparator

func WithSeparator(seq []byte) Option

type Writer

type Writer struct {
	// contains filtered or unexported fields
}
Example
w1 := NewWriter(256, WithPadding([]byte("_")), WithSeparator([]byte("|")))
w1.AppendUint(1, 4, AlignRight)
w1.AppendUint(1, 4, AlignRight|Hex|WithZero)
w1.AppendString("playback", 10, AlignLeft)
w1.AppendUint(44, 2, AlignLeft|Decimal)
w1.AppendBool(false, 3, AlignCenter|OnOff)

w2 := NewWriter(256, WithPadding([]byte("_")), WithSeparator([]byte("|")), WithLabel("[label]"))
w2.AppendUint(1, 4, AlignRight)
w2.AppendUint(1, 4, AlignRight|Hex|WithZero)
w2.AppendString("playback", 10, AlignLeft)
w2.AppendUint(44, 2, AlignLeft|Decimal)
w2.AppendBool(false, 3, AlignCenter|OnOff)

fmt.Println(w1.String())
fmt.Println(w2.String())
Output:

_   1_|_0001_|_playback  _|_44_|_off_
[label]_   1_|_0001_|_playback  _|_44_|_off_

func NewWriter

func NewWriter(size int, options ...Option) *Writer

func (*Writer) AppendBool

func (w *Writer) AppendBool(b bool, width int, flag Flag)

func (*Writer) AppendBytes

func (w *Writer) AppendBytes(bs []byte, width int, flag Flag)

func (*Writer) AppendDuration

func (w *Writer) AppendDuration(d time.Duration, width int, flag Flag)

func (*Writer) AppendFloat

func (w *Writer) AppendFloat(v float64, width, prec int, flag Flag)

func (*Writer) AppendInt

func (w *Writer) AppendInt(v int64, width int, flag Flag)

func (*Writer) AppendPercent

func (w *Writer) AppendPercent(v float64, width, prec int, flag Flag)

func (*Writer) AppendSeparator

func (w *Writer) AppendSeparator(n int)
Example
w1 := NewWriter(256, WithPadding([]byte("_")), WithSeparator([]byte("|")))
w1.AppendUint(1, 4, AlignRight)
w1.AppendUint(1, 4, AlignRight|Hex|WithZero)
w1.AppendSeparator(1)
w1.AppendString("playback", 10, AlignLeft)
w1.AppendSeparator(3)
w1.AppendUint(44, 2, AlignLeft|Decimal)
w1.AppendBool(false, 3, AlignCenter|OnOff)

fmt.Println(w1.String())
Output:

_   1_|_0001_||_playback  _|||_44_|_off_

func (*Writer) AppendSize

func (w *Writer) AppendSize(v int64, width int, flag Flag)

func (*Writer) AppendString

func (w *Writer) AppendString(str string, width int, flag Flag)

func (*Writer) AppendTime

func (w *Writer) AppendTime(t time.Time, format string, flag Flag)

func (*Writer) AppendUint

func (w *Writer) AppendUint(v uint64, width int, flag Flag)

func (*Writer) Bytes

func (w *Writer) Bytes() []byte

func (*Writer) Read

func (w *Writer) Read(bs []byte) (int, error)

func (*Writer) Reset

func (w *Writer) Reset()

func (*Writer) String

func (w *Writer) String() string

func (*Writer) WriteTo

func (w *Writer) WriteTo(ws io.Writer) (int64, error)

Jump to

Keyboard shortcuts

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