-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathwlog.go
72 lines (67 loc) · 2.38 KB
/
wlog.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
//Package wlog creates simple to use UI structure.
//The UI is used to simply print to the screen.
//There a wrappers that will wrap each other to create a good looking UI.
//You can add color and prefixes as well as make it thread safe.
package wlog
//TODO:10 Add a simple way to split writer between terminal and file
//TODO:0 Add a TableUI
import "io"
//New creates a BasicUI.
//This should be the first function you call.
//This is not thread safe and should only be used in serial applications.
func New(reader io.Reader, writer, errorWriter io.Writer) *BasicUI {
return &BasicUI{
Reader: reader,
Writer: writer,
ErrorWriter: errorWriter,
}
}
// AddConcurrent will wrap a thread safe UI on top of ui.
// Safe to use inside of go routines.
func AddConcurrent(ui UI) *ConcurrentUI {
return &ConcurrentUI{UI: ui}
}
//AddColor will wrap a colorful UI on top of ui.
//Use wlog's color variables for the color.
//All background colors are not changed by this function but you are able to change them manually.
//Just create this structure manually and change any of the background colors you want.
//Arguments are in alphabetical order.
func AddColor(askColor, errorColor, infoColor, logColor, outputColor, responseColor, runningColor, successColor, warnColor Color, ui UI) *ColorUI {
return &ColorUI{
LogFGColor: logColor,
LogBGColor: None,
OutputFGColor: outputColor,
OutputBGColor: None,
SuccessFGColor: successColor,
SuccessBGColor: None,
InfoFGColor: infoColor,
InfoBGColor: None,
ErrorFGColor: errorColor,
ErrorBGColor: None,
WarnFGColor: warnColor,
WarnBGColor: None,
RunningFGColor: runningColor,
RunningBGColor: None,
AskFGColor: askColor,
AskBGColor: None,
ResponseFGColor: responseColor,
ResponseBGColor: None,
UI: ui,
}
}
//AddPrefix will wrap a UI that will prefix the message on top of ui.
//If a prefix is set to nothing ("") then there will be no prefix for that message type.
//Arguments are in alphabetical order.
func AddPrefix(askPre, errorPre, infoPre, logPre, outputPre, runningPre, successPre, warnPre string, ui UI) *PrefixUI {
return &PrefixUI{
LogPrefix: logPre,
OutputPrefix: outputPre,
SuccessPrefix: successPre,
InfoPrefix: infoPre,
ErrorPrefix: errorPre,
WarnPrefix: warnPre,
RunningPrefix: runningPre,
AskPrefix: askPre,
UI: ui,
}
}