-
Notifications
You must be signed in to change notification settings - Fork 15
/
screen.go
166 lines (123 loc) · 2.49 KB
/
screen.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package main
import (
"errors"
"fmt"
"log"
"os"
"sort"
"strconv"
)
func getMsg(code int) (msg string) {
switch code {
// Menu entries
case 0000:
msg = "Configuration"
case 0001:
msg = "Select Entry"
case 0010:
msg = "Exit"
case 0011:
msg = "Schedules Direct Account"
case 0012:
msg = "Add Lineup"
case 0013:
msg = "Remove Lineup"
case 0014:
msg = "Manage Channels"
case 0015:
msg = "Exit"
case 0016:
msg = "Create XMLTV File"
case 0100:
msg = "Username"
case 0101:
msg = "Password"
case 0200:
msg = "Cancel"
case 0201:
msg = "Select Country"
case 0202:
msg = "Postal Code"
case 0203:
msg = "Select Provider"
case 0204:
msg = "Select Lineup"
case 0300:
msg = "Update Config File"
case 0301:
msg = "Remove Cache File"
case 401:
msg = "Download images"
case 402:
msg = "Dowloaded Images Path"
case 403:
msg = "Local Images Cache"
}
return
}
// Show : Show menu on screen
func (m *Menu) Show() (selection int) {
log.SetOutput(os.Stdout)
if len(m.Entry) == 0 {
return
}
fmt.Println()
fmt.Println(m.Headline)
for i := 0; i < len(m.Headline); i++ {
fmt.Print("-")
}
fmt.Println()
for {
var input string
var keys []int
for _, entry := range m.Entry {
keys = append(keys, entry.Key)
}
sort.Ints(keys)
if keys[0] == 0 {
keys = keys[1:]
keys = append(keys, 0)
}
for _, key := range keys {
var entry = m.Entry[key]
switch len(fmt.Sprintf("%d", entry.Key)) {
case 1:
fmt.Print(fmt.Sprintf(" %d. ", entry.Key))
case 2:
fmt.Print(fmt.Sprintf("%d. ", entry.Key))
}
fmt.Println(entry.Value)
}
fmt.Print(fmt.Sprintf("%s: ", m.Select))
fmt.Scanln(&input)
selection, err := strconv.Atoi(input)
if err == nil {
for _, entry := range m.Entry {
if selection == entry.Key {
return selection
}
}
}
err = errors.New("Invalid Input")
ShowErr(err)
fmt.Println()
}
return
}
// ShowInfo : Show info on screen
func showInfo(key, msg string) {
log.SetOutput(os.Stdout)
switch len(key) {
case 1:
msg = fmt.Sprintf("[%s ] %s", key, msg)
case 2:
msg = fmt.Sprintf("[%s ] %s", key, msg)
case 3:
msg = fmt.Sprintf("[%s ] %s", key, msg)
case 4:
msg = fmt.Sprintf("[%s ] %s", key, msg)
case 5:
msg = fmt.Sprintf("[%s] %s", key, msg)
}
log.Println(msg)
}