-
Notifications
You must be signed in to change notification settings - Fork 0
/
static.go
241 lines (224 loc) · 6.64 KB
/
static.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
package main
import (
"log"
"os"
"runtime"
"strconv"
)
// Version is the version number of the application.
const version = "Apollo v1.1.0"
// Create a configuration directory for Unis systems.
func makeUnixConfigDir() {
path := os.Getenv("HOME") + "/.config/apollo"
_, err := os.Stat(path)
if err != nil {
err = os.Mkdir(path, 0755)
if err != nil {
log.Print(err)
}
}
}
// Returns the path of the database file.
func databasePath() string {
if runtime.GOOS == "windows" {
return "database.json"
} else {
makeUnixConfigDir()
return os.Getenv("HOME") + "/.config/apollo/database.json"
}
}
// Returns the path of the configuration file.
func configurationPath() string {
if runtime.GOOS == "windows" {
return "configuration.json"
} else {
makeUnixConfigDir()
return os.Getenv("HOME") + "/.config/apollo/configuration.json"
}
}
// PrintHelp prints out the help guide to the logs.
func (a *Apollo) printHelp() {
s := []string{
"{b}*───( Main Help Guide )───*",
"{b}│ {d}List of key-bindings:",
"{b}│ {d}Ctrl+C.........Close this software",
"{b}│ {d}Alt+Num........Go to the [num]th tab",
"{b}│ {d}Enter..........Send, or toggle between input bar and tab",
"{b}│",
"{b}│ {d}List of commands:",
"{b}│ {d}(For more details, use /help <command name>)",
"{b}│ {d}/help..........Show this help guide",
"{b}│ {d}/quit..........Close this software",
"{b}│ {d}/open..........Create a new tab",
"{b}│ {d}/close.........Close the current tab",
"{b}│ {d}/set...........Set a configuration option",
"{b}│ {d}/config........Show the current configuration",
"{b}│ {d}/stats.........Prints some stats about the entries",
"{b}*───*",
}
for i := 0; i < len(s); i++ {
a.log(s[i])
}
}
// PrintDetailedHelp prints out the detailed help of a function to the logs.
func (a *Apollo) printDetailedHelp(subject string) {
var s []string
switch subject {
case "help":
s = []string{
"{b}*───( Detailed Help Guide )───*",
"{b}│ {d}/help",
"{b}│ {d}/help <command name>",
"{b}│",
"{b}│ {d}Displays a help guide.",
"{b}*───*",
}
case "quit":
s = []string{
"{b}*───( Detailed Help Guide )───*",
"{b}│ {d}/quit",
"{b}│",
"{b}│ {d}Closes this software.",
"{b}*───*",
}
case "open":
s = []string{
"{b}*───( Detailed Help Guide )───*",
"{b}│ {d}/open <tab name>",
"{b}│",
"{b}│ {d}Opens a given tab or, if it already exists, selects it.",
"{b}│ {d}Tabs available: anime, books, games, movies, series.",
"{b}│ {d}For keybindings, use '/help tabs'",
"{b}*───*",
}
case "close":
s = []string{
"{b}*───( Detailed Help Guide )───*",
"{b}│ {d}/close",
"{b}│",
"{b}│ {d}Close the current tab.",
"{b}*───*",
}
case "set":
s = []string{
"{b}*───( Detailed Help Guide )───*",
"{b}│ {d}/set <option> <value>",
"{b}│",
"{b}│ {d}Sets a configuration option to a specific value.",
"{b}*───*",
}
case "config":
s = []string{
"{b}*───( Detailed Help Guide )───*",
"{b}│ {d}/config",
"{b}│",
"{b}│ {d}Shows the configuration options and their values.",
"{b}*───*",
}
case "stats":
s = []string{
"{b}*───( Detailed Help Guide )───*",
"{b}│ {d}/stats",
"{b}│",
"{b}│ {d}Prints statistics about the database entries.",
"{b}*───*",
}
case "tabs":
s = []string{
"{b}*───( Detailed Help Guide )───*",
"{b}│ {d}List of key-bindings:",
"{b}│ {d}1..............Switch to passive view",
"{b}│ {d}2..............Switch to active view",
"{b}│ {d}3..............Switch to inactive view",
"{b}│ {d}4..............Switch to all view",
"{b}│ {d}s..............Sort the entries",
"{b}│ {d}D..............Delete the current entry",
"{b}│ {d}e..............Edit the current entry",
"{b}│ {d}r..............Toggle ratings",
"{b}│ {d}a..............Toggle the current entry's state",
"{b}│ {d}[/]............Change the rating of the current entry",
"{b}│ {d}Up/Down........Scroll through the entries",
"{b}│ {d}Left/Right.....Change the current episode of an entry",
"{b}│ {d}p..............Print the current entries to a file",
"{b}*───*",
}
default:
s = []string{
"{b}│ {d}Detailed help does not exist for this command.",
}
}
for i := 0; i < len(s); i++ {
a.log(s[i])
}
}
// PrintWelcome prints out the welcome message to the logs.
func (a *Apollo) printWelcome() {
a.log("{b}*───( " + version + " )───*")
a.log("{b}│ {d}This software is licensed under the MIT License.")
a.log("{b}│ {d}To get started, use /help.")
a.log("{b}*───*")
}
// PrintConfig prints out the list of configuration options to the logs.
func (a *Apollo) printConfig() {
a.log("{b}*───( Current Configuration )───*")
for _, value := range a.c.config() {
a.log("{b}│ {d}" + value)
}
a.log("{b}*───*")
}
// PrintStats prints out relevant statistics about the database.
func (a *Apollo) printStats() {
totalMovies := 0
watchedMovies := 0
for i := range a.d.Movies {
totalMovies++
if a.d.Movies[i].State == "passive" {
watchedMovies++
}
}
totalAnime := 0
watchedAnime := 0
totalAnimeEp := 0
watchedAnimeEp := 0
for i := range a.d.Anime {
totalAnime++
if a.d.Anime[i].State == "passive" {
watchedAnime++
}
totalAnimeEp += a.d.Anime[i].EpisodeTotal
watchedAnimeEp += a.d.Anime[i].EpisodeDone
}
totalGames := 0
playedGames := 0
for i := range a.d.Games {
totalGames++
if a.d.Games[i].State == "passive" {
playedGames++
}
}
totalBooks := 0
readBooks := 0
for i := range a.d.Books {
totalBooks++
if a.d.Books[i].State == "passive" {
readBooks++
}
}
sTotalMovies := strconv.Itoa(totalMovies)
sWatchedMovies := strconv.Itoa(watchedMovies)
sTotalAnime := strconv.Itoa(totalAnime)
sWatchedAnime := strconv.Itoa(watchedAnime)
sTotalAnimeEp := strconv.Itoa(totalAnimeEp)
sWatchedAnimeEp := strconv.Itoa(watchedAnimeEp)
sTotalGames := strconv.Itoa(totalGames)
sPlayedGames := strconv.Itoa(playedGames)
sTotalBooks := strconv.Itoa(totalBooks)
sReadBooks := strconv.Itoa(readBooks)
a.log("{b}*───( Statistics )───*")
a.log("{b}│ {d}Movies watched: " + sWatchedMovies + "/" + sTotalMovies)
a.log("{b}│ {d}Anime seasons watched: " + sWatchedAnime + "/" + sTotalAnime)
a.log("{b}│ {d} Episodes watched: " + sWatchedAnimeEp + "/" + sTotalAnimeEp)
a.log("{b}│ {d}Games played: " + sPlayedGames + "/" + sTotalGames)
a.log("{b}│ {d}Books read: " + sReadBooks + "/" + sTotalBooks)
a.log("{b}*───*")
}