-
Notifications
You must be signed in to change notification settings - Fork 0
/
pio.go
76 lines (66 loc) · 2.11 KB
/
pio.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package pio
import (
"io"
)
// NewLine is a slice of bytes which controls the
// how a new line should be presented.
//
// Defaults to \n.
var NewLine = []byte("\n")
// Default returns the default, package-level registry instance.
var Default = NewRegistry()
// RegisterPrinter registers an already-created printer to the
// registry.
//
// If a printer with the same `Name` is already
// registered then it will be overridden by
// this new "printer".
//
// Returns the Registry, therefore it can be used as builder.
func RegisterPrinter(p *Printer) *Registry {
return Default.RegisterPrinter(p)
}
// Register creates and registers a new Printer
// based on a name(string) and an "output"(io.Writer).
//
// If a printer with the same `Name` is already
// registered then it will be overridden by
// this new "printer".
//
// Look `OutputFrom` too.
//
// Returns the just created Printer.
func Register(printerName string, output io.Writer) *Printer {
return Default.Register(printerName, output)
}
// Get returns a Printer based on the "printerName".
// If printer with this name can't be found then
// this function will return nil, so a check for
// nil is always a good practice.
func Get(printerName string) *Printer {
return Default.Get(printerName)
}
// Remove deletes a printer item from the printers collection
// by its name.
func Remove(printerName string) {
Default.Remove(printerName)
}
// Print accepts a value of "v",
// tries to marshal its contents and flushes the result
// to all available printers.
func Print(v interface{}) (int, error) {
return Default.Print(v)
}
// Println accepts a value of "v",
// tries to marshal its contents and flushes the result
// to all available printers, it adds a new line at the ending,
// the result doesn't contain this new line, therefore result's contnets kept as expected.
func Println(v interface{}) (int, error) {
return Default.Println(v)
}
// Scan scans everything from "r" and prints
// its new contents to the printers,
// forever or until the returning "cancel" is fired, once.
func Scan(r io.Reader, addNewLine bool) (cancel func()) {
return Default.Scan(r, addNewLine)
}