text

package
v4.0.18+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2021 License: Apache-2.0 Imports: 6 Imported by: 12

Documentation

Overview

Package text provides utilities for formatting text data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatBits

func FormatBits(size int64) string

FormatBits takes in a bit (not byte) count and returns a formatted string including units with three total digits (except if it is less than 1k) e.g. 12.0g, 0b, 124k

func FormatByteAmount

func FormatByteAmount(size int64) string

FormatByteAmount takes an int64 representing a size in bytes and returns a formatted string of a minimum amount of significant figures.

e.g. 12.4 GB, 0.0 B, 124.5 KB

func FormatMegabyteAmount

func FormatMegabyteAmount(size int64) string

FormatMegabyteAmount is equivalent to FormatByteAmount but expects an amount of MB instead of bytes.

Types

type Cell

type Cell struct {
	// contains filtered or unexported fields
}

type GridWriter

type GridWriter struct {
	ColumnPadding int
	MinWidth      int
	Grid          [][]Cell
	CurrentRow    int
	// contains filtered or unexported fields
}

func (*GridWriter) EndRow

func (gw *GridWriter) EndRow()

EndRow terminates the row of cells and begins a new row in the grid.

func (*GridWriter) Feed

func (gw *GridWriter) Feed(data string)

Feed writes the given string into the current cell but allowing the cell contents to extend past the width of the current column, and ends the row.

func (*GridWriter) Flush

func (gw *GridWriter) Flush(w io.Writer)

Flush writes the fully-formatted grid to the given io.Writer.

func (*GridWriter) FlushRows

func (gw *GridWriter) FlushRows(w io.Writer)

FlushRows writes the fully-formatted grid to the given io.Writer, but gives each row its own Write() call instead of using newlines.

func (*GridWriter) Reset

func (gw *GridWriter) Reset()

Reset discards any grid data and resets the current row.

func (*GridWriter) WriteCell

func (gw *GridWriter) WriteCell(data string)

WriteCell writes the given string into the next cell in the current row.

func (*GridWriter) WriteCells

func (gw *GridWriter) WriteCells(data ...string)

WriteCells writes multiple cells by calling WriteCell for each argument.

Jump to

Keyboard shortcuts

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