columnswriter

package
v0.0.0-...-48b9394 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2013 License: BSD-3-Clause Imports: 7 Imported by: 2

Documentation

Overview

Package columnswriter imlements a write filter that prints evenly distributed columns fitted to current terminal window size.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Writer

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

A Writer is a filter that prints evenly distributed columns

func New

func New(output io.Writer, inputSep rune, minWidth, padding int) *Writer

Create a writer object with specified values, see Init for explanation of paramaters.

func (*Writer) Flush

func (w *Writer) Flush()

Does the actual printing, always call this after everthing you want to print has been printed.

Example

Example of how to call flush after you have written everything

// Print to stdout, input separated by spaces, no min widht, 2 spaces padding
w := New(os.Stdout, ' ', 0, 2)
w.nrTerminalColumns = 80 //for testing purposes, not necessary in real world

fmt.Fprintln(w, `This is a test that has a lot of words and treats every `)
fmt.Fprintln(w, `word as a column.`)
fmt.Fprintln(w, `It should print nicely formatted columns similar to ls `)
fmt.Fprintln(w, `directory lisings on nix systems.`)

w.Flush()
Output:
This     is     a       test       that     has      a   lot      of
words    and    treats  every      word     as       a   column.  It
should   print  nicely  formatted  columns  similar  to  ls       directory
lisings  on     nix     systems.

func (*Writer) Init

func (w *Writer) Init(output io.Writer, inputSep rune, minWidth, padding int) *Writer

A Writer must be initialized with a call to Init. The first pararmater (output) specifies the filter output. The inputSep is the character by wich each field is seperated in the input later on.

minWidth: Is the minimum widht of a column
padding:  The number of spaces between columns

func (*Writer) Write

func (w *Writer) Write(buf []byte) (n int, err error)

Implements Writer interface, so you can call it with the whole Fprint family

Jump to

Keyboard shortcuts

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