ffmt

package module
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2019 License: MIT Imports: 16 Imported by: 0

README

Golang beautify data display for Humans

Build Status Go Report Card GoDoc GitHub license cover.run

Install

# Stable version
go get -u -v gopkg.in/ffmt.v1

# Latest version
go get -u -v github.com/go-ffmt/ffmt

Usage

API Documentation

Examples

package main

import (
	ffmt "github.com/go-ffmt/ffmt"
)

func main() {
	example()
}

type mt struct {
	String string
	Int    int
	Slice  []int
	Map    map[string]interface{}
}

func example() {
	m := mt{
		"hello world",
		100,
		[]int{1, 2, 3, 4, 5, 6},
		map[string]interface{}{
			"A":  123,
			"BB": 456,
		},
	}

	fmt.Println(m) // fmt the default formatting.
	/*
		{hello world 100 [1 2 3 4 5 6] map[BB:456 A:123]}
	*/

	ffmt.Puts(m) // More friendly formatting.
	/*
		{
		 String: "hello world"
		 Int:    100
		 Slice:  [
		  1 2 3
		  4 5 6
		 ]
		 Map: {
		  "A":  123
		  "BB": 456
		 }
		}
	*/

	ffmt.Print(m) // Same "Puts" but String unadded '"'.
	/*
		{
		 String: hello world
		 Int:    100
		 Slice:  [
		  1 2 3
		  4 5 6
		 ]
		 Map: {
		  A:  123
		  BB: 456
		 }
		}
	*/

	ffmt.P(m) // Format data and types.
	/*
		main.mt{
		 String: string("hello world")
		 Int:    int(100)
		 Slice:  []int[
		  int(1) int(2) int(3)
		  int(4) int(5) int(6)
		 ]
		 Map: map[string]interface {}{
		  string("A"):  int(123)
		  string("BB"): int(456)
		 }
		}
	*/

	ffmt.Pjson(m) // Format it in json style.
	/*
		{
		 "Int": 100
		,"Map": {
		  "A":  123
		 ,"BB": 456
		 }
		,"Slice": [
		  1,2,3
		 ,4,5,6
		 ]
		,"String": "hello world"
		}
	*/

	m0 := ffmt.ToTable(m, m) // Break the fields into tables.
	ffmt.Puts(m0)
	/*
		[
		 [
		  "String" "Int"
		  "Slice"  "Map"
		 ]
		 [
		  "hello world"   "100"
		  "[1 2 3 4 5 6]" "map[A:123 BB:456]"
		 ]
		]
	*/

	m1 := ffmt.FmtTable(m0) // [][]string Table format.
	ffmt.Puts(m1)
	/*
		[
		 "String      Int Slice         Map               "
		 "hello world 100 [1 2 3 4 5 6] map[A:123 BB:456] "
		]
	*/

	ffmt.Mark("hello") // Mark position.
	/*
		main.go:124  hello
	*/

	ffmt.Print(ffmt.BytesViewer("Hello world! Hello All!"))
	/*
		| Address  | Hex                                             | Text             |
		| -------: | :---------------------------------------------- | :--------------- |
		| 00000000 | 48 65 6c 6c 6f 20 77 6f 72 6c 64 21 20 48 65 6c | Hello world! Hel |
		| 00000010 | 6c 6f 20 41 6c 6c 21                            | lo All!          |
	*/
}


License

Pouch is licensed under the MIT License. See LICENSE for the full license text.

Documentation

Index

Constants

View Source
const (
	CanDefaultString   option = 1 << (31 - iota) // can use .(fmt.Stringer)
	CanFilterDuplicate                           // Filter duplicates
	CanRowSpan                                   // Fold line
)

Formatted option

View Source
const (
	StyleP     style = iota + 1 // Display type and data
	StylePuts                   // Display data
	StylePrint                  // Display data; string without quotes
	StylePjson                  // The json style display; Do not show private
)

Formatted style

Variables

View Source
var Printf = fmt.Printf

Printf fmt.Printf

View Source
var Println = fmt.Println

Println fmt.Println

View Source
var Space byte = ' '

Space rune

Functions

func Align added in v1.4.1

func Align(a string) string

Align returns align structured strings

func D added in v1.3.1

func D(a ...interface{})

D for debug

func FmtTable

func FmtTable(b [][]string) (ss []string)

FmtTable Format table data

func Format

func Format(str string, data ...interface{}) string

Format Format("hello {name}", "ffmt") to "hello ffmt"

func Fp

func Fp(w io.Writer, a ...interface{}) (int, error)

Fp The go style friendly display types and data to writer

func Fpjson

func Fpjson(w io.Writer, a ...interface{}) (int, error)

Fpjson The json style friendly display to writer

func Fprint

func Fprint(w io.Writer, a ...interface{}) (int, error)

Fprint The go style friendly to writer

func Fputs

func Fputs(w io.Writer, a ...interface{}) (int, error)

Fputs The go style friendly to writer

func Mark

func Mark(a ...interface{})

Mark Output prefix current line position

func MarkStack

func MarkStack(skip int, a ...interface{})

MarkStack Output prefix stack line pos

func MarkStackFull

func MarkStackFull()

MarkStackFull Output stack full

func NewOptional

func NewOptional(depth int, b style, opt option) *optional

NewOptional ffmt optional

func P

func P(a ...interface{}) (int, error)

P The go style friendly display types and data

func Pjson

func Pjson(a ...interface{}) (int, error)

Pjson The json style friendly display

func Print

func Print(a ...interface{}) (int, error)

Print The go style friendly display

func Puts

func Puts(a ...interface{}) (int, error)

Puts The go style friendly display

func Sd added in v1.3.1

func Sd(a ...interface{}) string

Sd for debug

func Smark added in v1.3.1

func Smark(a ...interface{}) string

Smark returns Output prefix current line position

func SmarkStack added in v1.3.1

func SmarkStack(skip int, a ...interface{}) string

SmarkStack stack information

func SmarkStackFunc added in v1.4.1

func SmarkStackFunc(skip int, a ...interface{}) string

SmarkStackFunc stack information

func Sp

func Sp(a ...interface{}) string

Sp The go style friendly display types and data to string

func Spjson

func Spjson(a ...interface{}) string

Spjson The json style friendly display to string

func Sprint

func Sprint(a ...interface{}) string

Sprint The go style friendly to string

func Sputs

func Sputs(a ...interface{}) string

Sputs The go style friendly to string

func TableText added in v1.3.1

func TableText(b string, prefix, split string) string

TableText table text

func ToTable

func ToTable(t interface{}, is ...interface{}) [][]string

ToTable Data to table data

Types

type BytesViewer added in v1.4.5

type BytesViewer []byte

BytesViewer bytes viewer

func (BytesViewer) String added in v1.4.5

func (b BytesViewer) String() string

String returns view in hexadecimal

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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