@@ -3,6 +3,7 @@ package ui
3
3
import (
4
4
"bytes"
5
5
"fmt"
6
+ "io"
6
7
"os"
7
8
8
9
"github.com/chzyer/readline"
@@ -104,6 +105,58 @@ func (u *UI) Hint(str string, noPadding bool, label *string) {
104
105
fmt .Fprintln (readline .Stdout , ansiwrap .WrapIndent (hintLabel + str , u .Cols , u .Indent , u .Indent + rc ))
105
106
}
106
107
108
+ // Info calls Info on the default UI
109
+ func Info (format string , args ... interface {}) { defUI .Info (format , args ... ) }
110
+
111
+ // Info handles outputting secondary information to the user such as messages
112
+ // about progress but are the actual result of an operation. For example,
113
+ // printing out that we're attempting to log a user in using the specific
114
+ // environment variables.
115
+ //
116
+ // Only printed if stdout is attached to a terminal.
117
+ func (u * UI ) Info (format string , args ... interface {}) {
118
+ if ! readline .IsTerminal (int (os .Stdout .Fd ())) {
119
+ return
120
+ }
121
+
122
+ u .Line (format , args ... )
123
+ }
124
+
125
+ // Warn calls Warn on the default UI
126
+ func Warn (format string , args ... interface {}) { defUI .Warn (format , args ... ) }
127
+
128
+ // Warn handles outputting warning information to the user such as
129
+ // messages about needing to be logged in.
130
+ //
131
+ // The warning is printed out to stderr if stdout is not attached to a
132
+ // terminal.
133
+ func (u * UI ) Warn (format string , args ... interface {}) {
134
+ var w io.Writer = readline .Stdout
135
+ if ! readline .IsTerminal (int (os .Stdout .Fd ())) {
136
+ w = readline .Stderr
137
+ }
138
+
139
+ o := fmt .Sprintf (format , args ... )
140
+ fmt .Fprintln (w , ansiwrap .WrapIndent (o , u .Cols , u .Indent , u .Indent ))
141
+ }
142
+
143
+ // Error calls Error on the default UI
144
+ func Error (format string , args ... interface {}) { defUI .Error (format , args ... ) }
145
+
146
+ // Error handles outputting error information to the user such as the fact they
147
+ // couldn't log in due to an error.
148
+ //
149
+ // The error is printed out to stderr if stdout is not attached to a termainl
150
+ func (u * UI ) Error (format string , args ... interface {}) {
151
+ var w io.Writer = readline .Stdout
152
+ if ! readline .IsTerminal (int (os .Stdout .Fd ())) {
153
+ w = readline .Stderr
154
+ }
155
+
156
+ o := fmt .Sprintf (format , args ... )
157
+ fmt .Fprintln (w , ansiwrap .WrapIndent (o , u .Cols , u .Indent , u .Indent ))
158
+ }
159
+
107
160
// Child calls Child on the default UI
108
161
func Child (indent int ) * UI { return defUI .Child (indent ) }
109
162
0 commit comments