Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
27
Task/Menu/Ada/menu.adb
Normal file
27
Task/Menu/Ada/menu.adb
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
with ada.text_io,Ada.Strings.Unbounded; use ada.text_io, Ada.Strings.Unbounded;
|
||||
|
||||
procedure menu is
|
||||
type menu_strings is array (positive range <>) of Unbounded_String ;
|
||||
function "+" (s : string) return Unbounded_String is (To_Unbounded_String (s));
|
||||
|
||||
function choice (m : menu_strings; prompt : string) return string is
|
||||
begin
|
||||
if m'length > 0 then
|
||||
loop
|
||||
put_line (prompt);
|
||||
for i in m'range loop
|
||||
put_line (i'img &") " & To_String (m(i)));
|
||||
end loop;
|
||||
begin
|
||||
return To_String (m(positive'value (get_line)));
|
||||
exception when others => put_line ("Try again !");
|
||||
end;
|
||||
end loop;
|
||||
end if;
|
||||
return "";
|
||||
end choice;
|
||||
|
||||
begin
|
||||
put_line ("You chose " &
|
||||
choice ((+"fee fie",+"huff and puff",+"mirror mirror",+"tick tock"),"Enter your choice "));
|
||||
end menu;
|
||||
92
Task/Menu/COBOL/menu.cob
Normal file
92
Task/Menu/COBOL/menu.cob
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. Test-Prompt-Menu.
|
||||
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
|
||||
01 Num-Options USAGE UNSIGNED-INT VALUE 4.
|
||||
01 Example-Menu.
|
||||
03 Example-Options-Data.
|
||||
05 FILLER PIC X(30) VALUE "fee fie".
|
||||
05 FILLER PIC X(30) VALUE "huff and puff".
|
||||
05 FILLER PIC X(30) VALUE "mirror mirror".
|
||||
05 FILLER PIC X(30) VALUE "tick tock".
|
||||
|
||||
03 Example-Options-Values REDEFINES Example-Options-Data.
|
||||
05 Example-Options PIC X(30) OCCURS 4 TIMES.
|
||||
|
||||
01 Chosen-Option PIC X(30).
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
CALL "Prompt-Menu" USING BY CONTENT Num-Options
|
||||
BY CONTENT Example-Menu
|
||||
BY REFERENCE Chosen-Option
|
||||
|
||||
DISPLAY "You chose: " Chosen-Option
|
||||
|
||||
GOBACK
|
||||
.
|
||||
|
||||
END PROGRAM Test-Prompt-Menu.
|
||||
|
||||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. Prompt-Menu.
|
||||
|
||||
DATA DIVISION.
|
||||
LOCAL-STORAGE SECTION.
|
||||
01 User-Input USAGE UNSIGNED-INT.
|
||||
01 Input-Flag PIC X.
|
||||
88 Valid-Input VALUE "Y".
|
||||
|
||||
01 Options-Index USAGE UNSIGNED-INT.
|
||||
01 Index-Display PIC Z(10).
|
||||
|
||||
LINKAGE SECTION.
|
||||
|
||||
01 Num-Options USAGE UNSIGNED-INT.
|
||||
01 Menu-Options.
|
||||
03 Options-Table PIC X(30) OCCURS 0 TO 10000000 TIMES
|
||||
DEPENDING ON Num-Options.
|
||||
|
||||
01 Chosen-Option PIC X(30).
|
||||
|
||||
PROCEDURE DIVISION USING Num-Options Menu-Options Chosen-Option.
|
||||
Main.
|
||||
IF Num-Options = 0
|
||||
MOVE SPACES TO Chosen-Option
|
||||
GOBACK
|
||||
END-IF
|
||||
|
||||
PERFORM UNTIL Valid-Input
|
||||
PERFORM Display-Menu-Options
|
||||
|
||||
DISPLAY "Choose an option: " WITH NO ADVANCING
|
||||
ACCEPT User-Input
|
||||
|
||||
PERFORM Validate-Input
|
||||
END-PERFORM
|
||||
|
||||
MOVE Options-Table (User-Input) TO Chosen-Option
|
||||
|
||||
GOBACK
|
||||
.
|
||||
|
||||
Display-Menu-Options.
|
||||
PERFORM VARYING Options-Index FROM 1 BY 1
|
||||
UNTIL Num-Options < Options-Index
|
||||
MOVE Options-Index TO Index-Display
|
||||
DISPLAY
|
||||
Index-Display ". " Options-Table (Options-Index)
|
||||
END-DISPLAY
|
||||
END-PERFORM
|
||||
.
|
||||
|
||||
Validate-Input.
|
||||
IF User-Input = 0 OR > Num-Options
|
||||
DISPLAY "Invalid input."
|
||||
ELSE
|
||||
SET Valid-Input TO TRUE
|
||||
END-IF
|
||||
.
|
||||
|
||||
END PROGRAM Prompt-Menu.
|
||||
37
Task/Menu/Emacs-Lisp/menu.el
Normal file
37
Task/Menu/Emacs-Lisp/menu.el
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
(let ((prompt-buffer-name "***** prompt *****")
|
||||
(option-list '("fee fie"
|
||||
"huff and puff"
|
||||
"mirror mirror"
|
||||
"tick tock"))
|
||||
(extra-prompt-message "")
|
||||
(is-selected nil)
|
||||
(user-input-value nil))
|
||||
|
||||
;; Switch to an empty buffer
|
||||
(switch-to-buffer-other-window prompt-buffer-name)
|
||||
(read-only-mode -1)
|
||||
(erase-buffer)
|
||||
;; Display the options
|
||||
(cl-loop for opt-idx from 1 to (length option-list) do
|
||||
(insert (format "%d\) %s \n" opt-idx (nth (1- opt-idx) option-list))))
|
||||
|
||||
(while (not is-selected)
|
||||
;; Read user input
|
||||
(setq user-input-value (read-string (concat "select an option" extra-prompt-message " : ")))
|
||||
(setq user-input-value (read user-input-value))
|
||||
;; Validate user input
|
||||
(if (and (fixnump user-input-value)
|
||||
(<= user-input-value (length option-list))
|
||||
(> user-input-value 0))
|
||||
;; Display result
|
||||
(progn
|
||||
(end-of-buffer)
|
||||
(insert (concat "\nYou selected: " (nth (1- user-input-value) option-list)))
|
||||
(setq is-selected 't)
|
||||
)
|
||||
(progn
|
||||
(setq extra-prompt-message " (please input a valid number)")
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
22
Task/Menu/Euphoria/menu.eu
Normal file
22
Task/Menu/Euphoria/menu.eu
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
include get.e
|
||||
|
||||
function menu_select(sequence items, object prompt)
|
||||
if length(items) = 0 then
|
||||
return ""
|
||||
else
|
||||
for i = 1 to length(items) do
|
||||
printf(1,"%d) %s\n",{i,items[i]})
|
||||
end for
|
||||
|
||||
if atom(prompt) then
|
||||
prompt = "Choice?"
|
||||
end if
|
||||
|
||||
return items[prompt_number(prompt,{1,length(items)})]
|
||||
end if
|
||||
end function
|
||||
|
||||
constant items = {"fee fie", "huff and puff", "mirror mirror", "tick tock"}
|
||||
constant prompt = "Which is from the three pigs? "
|
||||
|
||||
printf(1,"You chose %s.\n",{menu_select(items,prompt)})
|
||||
34
Task/Menu/LOLCODE/menu.lol
Normal file
34
Task/Menu/LOLCODE/menu.lol
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
HAI 1.3
|
||||
|
||||
I HAS A ITEMZ ITZ A BUKKIT
|
||||
ITEMZ HAS A SRS 0 ITZ "fee fie"
|
||||
ITEMZ HAS A SRS 1 ITZ "huff and puff"
|
||||
ITEMZ HAS A SRS 2 ITZ "mirror mirror"
|
||||
ITEMZ HAS A SRS 3 ITZ "tick tock"
|
||||
ITEMZ HAS A LENGTH ITZ 4
|
||||
|
||||
HOW IZ I MENU YR LIST
|
||||
I HAS A INPUT
|
||||
IM IN YR INPUTLOOP
|
||||
IM IN YR SUBLOOP UPPIN YR N TIL BOTH SAEM N AN LIST'Z LENGTH
|
||||
I HAS A M ITZ SUM OF N AN 1
|
||||
I HAS A ITEM ITZ LIST'Z SRS N
|
||||
VISIBLE ":{M}. :{ITEM}"
|
||||
IM OUTTA YR SUBLOOP
|
||||
VISIBLE "MAEK UR CHOICE::"
|
||||
GIMMEH INPUT
|
||||
INPUT IS NOW A NUMBR
|
||||
I HAS A UPLIM ITZ BOTH SAEM INPUT AN BIGGR OF INPUT AN 1
|
||||
I HAS A LOWLIM ITZ BOTH SAEM INPUT AN SMALLR OF INPUT AN LIST'Z LENGTH
|
||||
BOTH OF UPLIM AN LOWLIM, O RLY?
|
||||
YA RLY, GTFO
|
||||
NO WAI, VISIBLE "UR INPUT IS FAIL"
|
||||
OIC
|
||||
IM OUTTA YR INPUTLOOP
|
||||
I HAS A CHOICE ITZ LIST'Z SRS DIFF OF INPUT AN 1
|
||||
VISIBLE "U CHOSE :{CHOICE}"
|
||||
IF U SAY SO
|
||||
|
||||
I IZ MENU YR ITEMZ MKAY
|
||||
|
||||
KTHXBYE
|
||||
|
|
@ -2,7 +2,7 @@ val choose = fn*(entries list) {
|
|||
if not entries: return ""
|
||||
|
||||
# print the menu
|
||||
writeln join(map(entries, 1..len(entries), by=fn e, i:"{{i:2}}: {{e}}"), delim="\n")
|
||||
writeln join(map(entries, 1..len(entries), by=fn(e, i) { "{{i:2}}: {{e}}" }), delim="\n")
|
||||
|
||||
val idx = read(
|
||||
prompt="Select entry #: ",
|
||||
|
|
|
|||
15
Task/Menu/Pluto/menu.pluto
Normal file
15
Task/Menu/Pluto/menu.pluto
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
require "io2"
|
||||
|
||||
local function menu(list)
|
||||
local n = #list
|
||||
if n == 0 then return "" end
|
||||
local prompt = "\n M E N U\n\n"
|
||||
for i = 1, n do prompt ..= $"{i}. {list[i]}\n" end
|
||||
prompt ..= $"\nEnter your choice (1 - {n}): "
|
||||
local index = io.readInt(prompt, 1, n)
|
||||
return list[index]
|
||||
end
|
||||
|
||||
local list = {"fee fie", "huff and puff", "mirror mirror", "tick tock"}
|
||||
local choice = menu(list)
|
||||
print($"\nYou chose : {choice}")
|
||||
77
Task/Menu/PowerShell/menu.ps1
Normal file
77
Task/Menu/PowerShell/menu.ps1
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
function Select-TextItem
|
||||
{
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Prints a textual menu formatted as an index value followed by its corresponding string for each object in the list.
|
||||
.DESCRIPTION
|
||||
Prints a textual menu formatted as an index value followed by its corresponding string for each object in the list;
|
||||
Prompts the user to enter a number;
|
||||
Returns an object corresponding to the selected index number.
|
||||
.PARAMETER InputObject
|
||||
An array of objects.
|
||||
.PARAMETER Prompt
|
||||
The menu prompt string.
|
||||
.EXAMPLE
|
||||
“fee fie”, “huff and puff”, “mirror mirror”, “tick tock” | Select-TextItem
|
||||
.EXAMPLE
|
||||
“huff and puff”, “fee fie”, “tick tock”, “mirror mirror” | Sort-Object | Select-TextItem -Prompt "Select a string"
|
||||
.EXAMPLE
|
||||
Select-TextItem -InputObject (Get-Process)
|
||||
.EXAMPLE
|
||||
(Get-Process | Where-Object {$_.Name -match "notepad"}) | Select-TextItem -Prompt "Select a Process" | Stop-Process -ErrorAction SilentlyContinue
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
Param
|
||||
(
|
||||
[Parameter(Mandatory=$true,
|
||||
ValueFromPipeline=$true)]
|
||||
$InputObject,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]
|
||||
$Prompt = "Enter Selection"
|
||||
)
|
||||
|
||||
Begin
|
||||
{
|
||||
$menuOptions = @()
|
||||
}
|
||||
Process
|
||||
{
|
||||
$menuOptions += $InputObject
|
||||
}
|
||||
End
|
||||
{
|
||||
if(!$inputObject){
|
||||
return ""
|
||||
}
|
||||
do
|
||||
{
|
||||
[int]$optionNumber = 1
|
||||
|
||||
foreach ($option in $menuOptions)
|
||||
{
|
||||
Write-Host ("{0,3}: {1}" -f $optionNumber,$option)
|
||||
|
||||
$optionNumber++
|
||||
}
|
||||
|
||||
Write-Host ("{0,3}: {1}" -f 0,"To cancel")
|
||||
|
||||
$choice = Read-Host $Prompt
|
||||
|
||||
$selectedValue = ""
|
||||
|
||||
if ($choice -gt 0 -and $choice -le $menuOptions.Count)
|
||||
{
|
||||
$selectedValue = $menuOptions[$choice - 1]
|
||||
}
|
||||
|
||||
}
|
||||
until ($choice -match "^[0-9]+$" -and ($choice -eq 0 -or $choice -le $menuOptions.Count))
|
||||
|
||||
return $selectedValue
|
||||
}
|
||||
}
|
||||
|
||||
“fee fie”, “huff and puff”, “mirror mirror”, “tick tock” | Select-TextItem -Prompt "Select a string"
|
||||
6
Task/Menu/Rebol/menu.rebol
Normal file
6
Task/Menu/Rebol/menu.rebol
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
menu: function [items][
|
||||
print either empty? items [""] [until [
|
||||
repeat n length? items [print [n ":" items/:n]]
|
||||
attempt [pick items to-integer ask "Your choice: "]
|
||||
]]
|
||||
]
|
||||
36
Task/Menu/VBScript/menu.vbs
Normal file
36
Task/Menu/VBScript/menu.vbs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
'The Function
|
||||
Function Menu(ArrList, Prompt)
|
||||
Select Case False 'Non-standard usage hahaha
|
||||
Case IsArray(ArrList)
|
||||
Menu = "" 'Empty output string for non-arrays
|
||||
Exit Function
|
||||
Case UBound(ArrList) >= LBound(ArrList)
|
||||
Menu = "" 'Empty output string for empty arrays
|
||||
Exit Function
|
||||
End Select
|
||||
'Display menu and prompt
|
||||
Do While True
|
||||
For i = LBound(ArrList) To UBound(ArrList)
|
||||
WScript.StdOut.WriteLine((i + 1) & ". " & ArrList(i))
|
||||
Next
|
||||
WScript.StdOut.Write(Prompt)
|
||||
Choice = WScript.StdIn.ReadLine
|
||||
'Check if input is valid
|
||||
If IsNumeric(Choice) Then 'Check for numeric-ness
|
||||
If CStr(CLng(Choice)) = Choice Then 'Check for integer-ness (no decimal part)
|
||||
Index = Choice - 1 'Arrays are 0-based
|
||||
'Check if Index is in array
|
||||
If LBound(ArrList) <= Index And Index <= UBound(ArrList) Then
|
||||
Exit Do
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
WScript.StdOut.WriteLine("Invalid choice.")
|
||||
Loop
|
||||
Menu = ArrList(Index)
|
||||
End Function
|
||||
|
||||
'The Main Thing
|
||||
Sample = Array("fee fie", "huff and puff", "mirror mirror", "tick tock")
|
||||
InputText = "Which is from the three pigs: "
|
||||
WScript.StdOut.WriteLine("Output: " & Menu(Sample, InputText))
|
||||
Loading…
Add table
Add a link
Reference in a new issue