Family Day update
This commit is contained in:
parent
aac6731f2c
commit
9ad63ea473
2442 changed files with 39761 additions and 8255 deletions
|
|
@ -1,12 +1,13 @@
|
|||
USE: formatting
|
||||
USING: formatting io kernel math math.parser sequences ;
|
||||
|
||||
: print-menu ( seq -- )
|
||||
[ 1 + swap "%d - %s\n" printf ] each-index
|
||||
"Your choice? " write flush ;
|
||||
|
||||
: select ( seq -- result )
|
||||
dup print-menu
|
||||
readln string>number [
|
||||
1 - swap 2dup bounds-check?
|
||||
[ nth ] [ nip select ] if
|
||||
] [ select ] if* ;
|
||||
: (select) ( seq -- result )
|
||||
dup print-menu readln string>number dup integer? [
|
||||
drop 1 - swap 2dup bounds-check?
|
||||
[ nth ] [ nip (select) ] if
|
||||
] [ drop (select) ] if* ;
|
||||
|
||||
: select ( seq -- result ) [ "" ] [ (select) ] if-empty ;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,50 @@
|
|||
Public Sub Form_Open()
|
||||
Dim sMenu As String[] = ["fee fie", "huff and puff", "mirror mirror", "tick tock"]
|
||||
Dim sAnswer As String
|
||||
Public Sub Main()
|
||||
|
||||
Do
|
||||
sAnswer = InputBox("0: fee fie 1: huff and puff 2: mirror mirror 3: tick tock", "Please select an number")
|
||||
If InStr("0123", sAnswer) Then Message("You selected item " & sAnswer & " - " & sMenu[Val(sAnswer)], "OK")
|
||||
Loop
|
||||
Dim asMenu As String[] = ["fee fie", "huff And puff", "mirror mirror", "tick tock"]
|
||||
Dim sValuePrompt As String = "Please select one of the above numbers> "
|
||||
Dim sChoice As String
|
||||
Dim sFeedbackFormat As String = "You have chosen '&1'\r\n"
|
||||
|
||||
sChoice = Menu(asMenu, sValuePrompt)
|
||||
If sChoice = "" Then
|
||||
Print "menu returned an empty string"
|
||||
Else
|
||||
Print Subst(sFeedbackFormat, sChoice)
|
||||
Endif
|
||||
|
||||
End
|
||||
|
||||
Private Function Menu(asChoices As String[], sPrompt As String) As String
|
||||
|
||||
Dim sReturnValue As String = ""
|
||||
Dim sMenuLineFormat As String = "&1) &2"
|
||||
Dim sAnswer As String
|
||||
Dim iAnswer As Integer
|
||||
Dim iIndex As Integer = 0
|
||||
Dim sMenuItem As String
|
||||
|
||||
If Not IsNull(asChoices) Then
|
||||
If asChoices.Count > 0 Then
|
||||
Do
|
||||
For iIndex = 0 To asChoices.Max
|
||||
sMenuItem = asChoices[iIndex]
|
||||
Print Subst(sMenuLineFormat, iIndex, sMenuItem)
|
||||
Next
|
||||
|
||||
Print sPrompt
|
||||
Input sAnswer
|
||||
|
||||
If IsNumber(sAnswer) Then
|
||||
iAnswer = sAnswer
|
||||
If (0 <= iAnswer) And (iAnswer <= asChoices.Max) Then
|
||||
sReturnValue = asChoices[iAnswer]
|
||||
Break
|
||||
Endif
|
||||
Endif
|
||||
Loop
|
||||
Endif
|
||||
Endif
|
||||
|
||||
Return sReturnValue
|
||||
|
||||
End
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
using Printf
|
||||
|
||||
function _menu(items)
|
||||
for (ind, item) in enumerate(items)
|
||||
@printf " %2i) %s\n" ind item
|
||||
|
|
|
|||
|
|
@ -1,12 +1,18 @@
|
|||
function choice(choices)
|
||||
for i, v in ipairs(choices) do print(i, v) end
|
||||
|
||||
print"Enter your choice"
|
||||
local selection = io.read() + 0
|
||||
|
||||
if choices[selection] then print(choices[selection])
|
||||
else choice(choices)
|
||||
end
|
||||
function select (list)
|
||||
if not list or #list == 0 then
|
||||
return ""
|
||||
end
|
||||
local last, sel = #list
|
||||
repeat
|
||||
for i,option in ipairs(list) do
|
||||
io.write(i, ". ", option, "\n")
|
||||
end
|
||||
io.write("Choose an item (1-", tostring(last), "): ")
|
||||
sel = tonumber(string.match(io.read("*l"), "^%d+$"))
|
||||
until type(sel) == "number" and sel >= 1 and sel <= last
|
||||
return list[math.floor(sel)]
|
||||
end
|
||||
|
||||
choice{"fee fie", "huff and puff", "mirror mirror", "tick tock"}
|
||||
print("Nothing:", select {})
|
||||
print()
|
||||
print("You chose:", select {"fee fie", "huff and puff", "mirror mirror", "tick tock"})
|
||||
|
|
|
|||
|
|
@ -42,6 +42,9 @@ function Select-TextItem
|
|||
}
|
||||
End
|
||||
{
|
||||
if(!$inputObject){
|
||||
return ""
|
||||
}
|
||||
do
|
||||
{
|
||||
[int]$optionNumber = 1
|
||||
|
|
@ -55,7 +58,7 @@ function Select-TextItem
|
|||
|
||||
Write-Host ("{0,3}: {1}" -f 0,"To cancel")
|
||||
|
||||
[int]$choice = Read-Host $Prompt
|
||||
$choice = Read-Host $Prompt
|
||||
|
||||
$selectedValue = ""
|
||||
|
||||
|
|
@ -63,8 +66,9 @@ function Select-TextItem
|
|||
{
|
||||
$selectedValue = $menuOptions[$choice - 1]
|
||||
}
|
||||
|
||||
}
|
||||
until ($choice -eq 0 -or $choice -le $menuOptions.Count)
|
||||
until ($choice -match "^[0-9]+$" -and ($choice -eq 0 -or $choice -le $menuOptions.Count))
|
||||
|
||||
return $selectedValue
|
||||
}
|
||||
|
|
|
|||
36
Task/Menu/Swift/menu.swift
Normal file
36
Task/Menu/Swift/menu.swift
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
func getMenuInput(selections: [String]) -> String {
|
||||
guard !selections.isEmpty else {
|
||||
return ""
|
||||
}
|
||||
|
||||
func printMenu() {
|
||||
for (i, str) in selections.enumerated() {
|
||||
print("\(i + 1)) \(str)")
|
||||
}
|
||||
|
||||
print("Selection: ", terminator: "")
|
||||
}
|
||||
|
||||
while true {
|
||||
printMenu()
|
||||
|
||||
guard let input = readLine(strippingNewline: true), !input.isEmpty else {
|
||||
return ""
|
||||
}
|
||||
|
||||
guard let n = Int(input), n > 0, n <= selections.count else {
|
||||
continue
|
||||
}
|
||||
|
||||
return selections[n - 1]
|
||||
}
|
||||
}
|
||||
|
||||
let selected = getMenuInput(selections: [
|
||||
"fee fie",
|
||||
"huff and puff",
|
||||
"mirror mirror",
|
||||
"tick tock"
|
||||
])
|
||||
|
||||
print("You chose: \(selected)")
|
||||
Loading…
Add table
Add a link
Reference in a new issue