-
Notifications
You must be signed in to change notification settings - Fork 0
/
render.go
49 lines (39 loc) · 1.04 KB
/
render.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
package ezpwd
import (
"fmt"
"io"
"github.com/olekukonko/tablewriter"
)
type Renderer interface {
RenderPasswords([]Password)
}
type hidePasswords struct {
w io.Writer
}
type showPasswords struct {
w io.Writer
}
func NewHiddenPWDs(w io.Writer) *hidePasswords {
return &hidePasswords{w: w}
}
func NewShownPWDs(w io.Writer) *showPasswords {
return &showPasswords{w: w}
}
func (hp *hidePasswords) RenderPasswords(pwds []Password) {
table := tablewriter.NewWriter(hp.w)
for i, pwd := range pwds {
table.Append([]string{fmt.Sprintf("%d", i), pwd.Service, pwd.Login, pwd.Comment})
}
table.SetHeader([]string{"#", "Service", "Login", "Comment"})
table.Render()
}
func (sp *showPasswords) RenderPasswords(pwds []Password) {
table := tablewriter.NewWriter(sp.w)
for i, pwd := range pwds {
table.Append([]string{fmt.Sprintf("%d", i), pwd.Service, pwd.Login, pwd.Password, pwd.Comment})
}
table.SetHeader([]string{"#", "Service", "Login", "Password", "Comment"})
table.Render()
}
var _ Renderer = &showPasswords{}
var _ Renderer = &hidePasswords{}