-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathui.go
48 lines (36 loc) · 750 Bytes
/
ui.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
//nolint:errcheck
package tentez
import (
"fmt"
"io"
)
type Ui interface {
Ask(prompt string) string
Outputln(s string)
Outputf(format string, a ...interface{})
OutputErrln(s string)
OutputErrf(format string, a ...interface{})
}
type cui struct {
in io.Reader
out io.Writer
err io.Writer
}
func (c cui) Ask(prompt string) string {
fmt.Fprint(c.out, prompt)
var input string
fmt.Fscan(c.in, &input)
return input
}
func (c cui) Outputln(s string) {
fmt.Fprintln(c.out, s)
}
func (c cui) Outputf(format string, a ...interface{}) {
fmt.Fprintf(c.out, format, a...)
}
func (c cui) OutputErrln(s string) {
fmt.Fprintln(c.err, s)
}
func (c cui) OutputErrf(format string, a ...interface{}) {
fmt.Fprintf(c.err, format, a...)
}