Repository navigation
Expand file tree
/
Copy pathcli.jl
More file actions
63 lines (51 loc) · 1.33 KB
/
Copy pathcli.jl
File metadata and controls
63 lines (51 loc) · 1.33 KB
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
using REPL.TerminalMenus
import TOML
import Configurations: from_toml, to_toml
function study()
print("Enter the filename of a deck to study: ")
filename = readline()
if !endswith(filename, ".toml")
filename *= ".toml"
end
if !isfile(filename)
@warn "No deck by that name exists."
return study()
end
deck = try
deckversion = VersionNumber(TOML.parse(readline(filename))["version"])
if deckversion >= VersionNumber(version.major, version.minor+1, 0)
@warn "Deck was created with a newer version of Memex. There may be incompatibilities."
end
from_toml(Deck, filename)
catch
printstyled("Error: Could not read deck format.\n", color=:red)
return
end
review!(deck)
to_toml(filename, deck)
end
function createdeck()
print("Enter a name for the new deck: ")
name = readline()
filename = replace(name, r"\W" => "_") * ".toml"
if isfile(filename)
println("A deck with that name already exists. We'll study the existing deck.")
return filename
end
deck = Deck(name=name)
to_toml(filename, deck)
println("Created $filename")
return filename
end
printstyled("Memex v$version\n", bold=true, color=:blue)
options = ["Study deck", "New deck", "Quit"]
while true
opt = request("Select an option:", RadioMenu(options))
if opt == 1
study()
elseif opt == 2
createdeck()
elseif opt == 3 || opt == -1
exit()
end
end