June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
28
Task/Menu/Julia/menu.julia
Normal file
28
Task/Menu/Julia/menu.julia
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
function _menu(items)
|
||||
for (ind, item) in enumerate(items)
|
||||
@printf " %2i) %s\n" ind item
|
||||
end
|
||||
end
|
||||
|
||||
_ok(::Any,::Any) = false
|
||||
function _ok(reply::AbstractString, itemcount)
|
||||
n = tryparse(Int, reply)
|
||||
return isnull(n) || 0 ≤ get(n) ≤ itemcount
|
||||
end
|
||||
|
||||
"Prompt to select an item from the items"
|
||||
function _selector(items, prompt::AbstractString)
|
||||
isempty(items) && return ""
|
||||
reply = -1
|
||||
itemcount = length(items)
|
||||
while !_ok(reply, itemcount)
|
||||
_menu(items)
|
||||
print(prompt)
|
||||
reply = strip(readline(STDIN))
|
||||
end
|
||||
return items[parse(Int, reply)]
|
||||
end
|
||||
|
||||
items = ["fee fie", "huff and puff", "mirror mirror", "tick tock"]
|
||||
item = _selector(items, "Which is from the three pigs: ")
|
||||
println("You chose: ", item)
|
||||
Loading…
Add table
Add a link
Reference in a new issue