langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
9
Task/Menu/OCaml/menu.ocaml
Normal file
9
Task/Menu/OCaml/menu.ocaml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
let rec select choices prompt = (* "choices" is an array of strings *)
|
||||
if Array.length choices = 0 then invalid_arg "no choices";
|
||||
Array.iteri (Printf.printf "%d: %s\n") choices;
|
||||
print_string prompt;
|
||||
let index = read_int () in
|
||||
if index >= 0 && index < Array.length choices then
|
||||
choices.(index)
|
||||
else
|
||||
select choices prompt
|
||||
50
Task/Menu/OpenEdge-Progress/menu.openedge
Normal file
50
Task/Menu/OpenEdge-Progress/menu.openedge
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
FUNCTION bashMenu RETURNS CHAR(
|
||||
i_c AS CHAR
|
||||
):
|
||||
|
||||
DEF VAR ii AS INT.
|
||||
DEF VAR hfr AS HANDLE.
|
||||
DEF VAR hmenu AS HANDLE EXTENT.
|
||||
DEF VAR ikey AS INT.
|
||||
DEF VAR ireturn AS INT INITIAL ?.
|
||||
|
||||
EXTENT( hmenu ) = NUM-ENTRIES( i_c ).
|
||||
|
||||
CREATE FRAME hfr ASSIGN
|
||||
WIDTH = 80
|
||||
HEIGHT = NUM-ENTRIES( i_c )
|
||||
PARENT = CURRENT-WINDOW
|
||||
VISIBLE = TRUE
|
||||
.
|
||||
|
||||
DO ii = 1 TO NUM-ENTRIES( i_c ):
|
||||
|
||||
CREATE TEXT hmenu ASSIGN
|
||||
FRAME = hfr
|
||||
FORMAT = "x(79)"
|
||||
SCREEN-VALUE = SUBSTITUTE( "&1. &2", ii, ENTRY( ii, i_c ) )
|
||||
ROW = ii
|
||||
VISIBLE = TRUE
|
||||
.
|
||||
|
||||
END.
|
||||
|
||||
IF i_c = "" THEN
|
||||
ireturn = 1.
|
||||
|
||||
DO WHILE ireturn = ?:
|
||||
|
||||
READKEY.
|
||||
ikey = INTEGER( CHR( LASTKEY ) ) NO-ERROR.
|
||||
IF ikey >= 1 AND ikey <= NUM-ENTRIES( i_c ) THEN
|
||||
ireturn = ikey.
|
||||
|
||||
END.
|
||||
|
||||
RETURN ENTRY( ireturn, i_c ).
|
||||
|
||||
END FUNCTION.
|
||||
|
||||
MESSAGE
|
||||
bashMenu( "fee fie,huff and puff,mirror mirror,tick tock" )
|
||||
VIEW-AS ALERT-BOX.
|
||||
31
Task/Menu/Oz/menu.oz
Normal file
31
Task/Menu/Oz/menu.oz
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
declare
|
||||
fun {Select Prompt Items}
|
||||
case Items of nil then ""
|
||||
else
|
||||
for
|
||||
Item in Items
|
||||
Index in 1..{Length Items}
|
||||
do
|
||||
{System.showInfo Index#") "#Item}
|
||||
end
|
||||
{System.printInfo Prompt}
|
||||
try
|
||||
{Nth Items {ReadInt}}
|
||||
catch _ then
|
||||
{Select Prompt Items}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
fun {ReadInt}
|
||||
class TextFile from Open.file Open.text end
|
||||
StdIo = {New TextFile init(name:stdin)}
|
||||
in
|
||||
{String.toInt {StdIo getS($)}}
|
||||
end
|
||||
|
||||
Item = {Select "Which is from the three pigs: "
|
||||
["fee fie" "huff and puff" "mirror mirror" "tick tock"]}
|
||||
|
||||
in
|
||||
{System.showInfo "You chose: "#Item}
|
||||
2
Task/Menu/PARI-GP/menu.pari
Normal file
2
Task/Menu/PARI-GP/menu.pari
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
choose(v)=my(n);for(i=1,#v,print(i". "v[i]));while(type(n=input())!="t_INT"|n>#v|n<1,);v[n]
|
||||
choose(["fee fie","huff and puff","mirror mirror","tick tock"])
|
||||
17
Task/Menu/PL-I/menu.pli
Normal file
17
Task/Menu/PL-I/menu.pli
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
test: proc options (main);
|
||||
|
||||
declare menu(4) character(100) varying static initial (
|
||||
'fee fie', 'huff and puff', 'mirror mirror', 'tick tock');
|
||||
declare (i, k) fixed binary;
|
||||
|
||||
do i = lbound(menu,1) to hbound(menu,1);
|
||||
put skip edit (trim(i), ': ', menu(i) ) (a);
|
||||
end;
|
||||
put skip list ('please choose an item number');
|
||||
get list (k);
|
||||
if k >= lbound(menu,1) & k <= hbound(menu,1) then
|
||||
put skip edit ('you chose ', menu(k)) (a);
|
||||
else
|
||||
put skip list ('Could not find your phrase');
|
||||
|
||||
end test;
|
||||
18
Task/Menu/Perl-6/menu.pl6
Normal file
18
Task/Menu/Perl-6/menu.pl6
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
sub menu ( $prompt, @items ) {
|
||||
return '' unless @items.elems;
|
||||
repeat until my $selection ~~ /^ \d+ $/ && @items[--$selection] {
|
||||
my $i = 1;
|
||||
say " {$i++}) $_" for @items;
|
||||
$selection = prompt $prompt;
|
||||
}
|
||||
return @items[$selection];
|
||||
}
|
||||
|
||||
my @choices = 'fee fie', 'huff and puff', 'mirror mirror', 'tick tock';
|
||||
my $prompt = 'Enter the number corresponding to your selection: ';
|
||||
|
||||
my $answer = menu( $prompt, [] );
|
||||
say "You chose: $answer" if $answer.chars;
|
||||
|
||||
$answer = menu( $prompt, @choices );
|
||||
say "You chose: $answer" if $answer.chars;
|
||||
11
Task/Menu/PowerShell/menu-1.psh
Normal file
11
Task/Menu/PowerShell/menu-1.psh
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
function Get-Choice ([array] $Items) {
|
||||
Set-StrictMode -Version Latest
|
||||
|
||||
do {
|
||||
$Items | ForEach-Object { $i = 0 } { '{0,3}. {1}' -f (++$i),$_ }
|
||||
$choice = Read-Host Your choice
|
||||
} while ($choice -notmatch '^\d+$' -or
|
||||
!(1..$Items.Length -eq $choice))
|
||||
|
||||
$Items[$choice-1]
|
||||
}
|
||||
1
Task/Menu/PowerShell/menu-2.psh
Normal file
1
Task/Menu/PowerShell/menu-2.psh
Normal file
|
|
@ -0,0 +1 @@
|
|||
Get-Choice 'fee fie', 'huff and puff', 'mirror mirror', 'tick tock'
|
||||
14
Task/Menu/ProDOS/menu.dos
Normal file
14
Task/Menu/ProDOS/menu.dos
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
:a
|
||||
printline ==========MENU==========
|
||||
printline 1. Fee Fie
|
||||
printline 2. Huff Puff
|
||||
printline 3. Mirror, Mirror
|
||||
printline 4. Tick, Tock
|
||||
editvar /newvar /value=a /userinput=1 /title=What page do you want to go to?
|
||||
if -a- /hasvalue 1 printline You chose a line from the book Jack and the Beanstalk. & exitcurrentprogram 1
|
||||
if -a- /hasvalue 2 printline You chose a line from the book The Three Little Pigs. & exitcurrentprogram 1
|
||||
if -a- /hasvalue 3 printline You chose a line from the book Snow White. & exitcurrentprogram 1
|
||||
if -a- /hasvalue 4 printline You chose a line from the book Beauty and the Beast. & exitcurrentprogram 1
|
||||
printline You either chose an invalid choice or didn't chose.
|
||||
editvar /newvar /value=goback /userinput=1 /title=Do you want to chose something else?
|
||||
if -goback- /hasvalue y goto :a else exitcurrentprogram 1
|
||||
27
Task/Menu/PureBasic/menu.purebasic
Normal file
27
Task/Menu/PureBasic/menu.purebasic
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
If OpenConsole()
|
||||
Define i, txt$, choice
|
||||
Dim txts.s(4)
|
||||
EnableGraphicalConsole(1) ;- Enable graphical mode in the console
|
||||
Repeat
|
||||
ClearConsole()
|
||||
Restore TheStrings ; Set reads address
|
||||
For i=1 To 4
|
||||
Read.s txt$
|
||||
txts(i)=txt$
|
||||
ConsoleLocate(3,i): Print(Str(i)+": "+txt$)
|
||||
Next
|
||||
ConsoleLocate(3,6): Print("Your choice? ")
|
||||
choice=Val(Input())
|
||||
Until choice>=1 And choice<=4
|
||||
ClearConsole()
|
||||
ConsoleLocate(3,2): Print("You chose: "+txts(choice))
|
||||
;
|
||||
;-Now, wait for the user before ending to allow a nice presentation
|
||||
ConsoleLocate(3,5): Print("Press ENTER to quit"): Input()
|
||||
EndIf
|
||||
End
|
||||
|
||||
DataSection
|
||||
TheStrings:
|
||||
Data.s "fee fie", "huff And puff", "mirror mirror", "tick tock"
|
||||
EndDataSection
|
||||
23
Task/Menu/REBOL/menu.rebol
Normal file
23
Task/Menu/REBOL/menu.rebol
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
REBOL [
|
||||
Title: "Text Menu"
|
||||
Author: oofoe
|
||||
Date: 2009-12-08
|
||||
URL: http://rosettacode.org/wiki/Select
|
||||
]
|
||||
|
||||
choices: ["fee fie" "huff and puff" "mirror mirror" "tick tock"]
|
||||
choice: ""
|
||||
|
||||
valid?: func [
|
||||
choices [block! list! series!]
|
||||
choice
|
||||
][
|
||||
if error? try [choice: to-integer choice] [return false]
|
||||
all [0 < choice choice <= length? choices]
|
||||
]
|
||||
|
||||
while [not valid? choices choice][
|
||||
repeat i length? choices [print [" " i ":" choices/:i]]
|
||||
choice: ask "Which is from the three pigs? "
|
||||
]
|
||||
print ["You chose:" pick choices to-integer choice]
|
||||
31
Task/Menu/Run-BASIC/menu.run
Normal file
31
Task/Menu/Run-BASIC/menu.run
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
dim choose$(5)
|
||||
choose$(1) = "1 Fee Fie"
|
||||
choose$(2) = "2 Huff Puff"
|
||||
choose$(3) = "3 Mirror, Mirror"
|
||||
choose$(4) = "4 Tick, Tock"
|
||||
choose$(5) = "Exit"
|
||||
|
||||
[start]
|
||||
print "Menu Selection"
|
||||
listbox #lb,choose$(),5
|
||||
button #sel, "Accept",[select]
|
||||
wait
|
||||
|
||||
[select]
|
||||
selected$=#lb selection$()
|
||||
print " "
|
||||
if selected$<>"" then
|
||||
print "You selected ";selected$
|
||||
else
|
||||
print "No selection made"
|
||||
end if
|
||||
button #con, "Continue",[go2]
|
||||
wait
|
||||
[go2]
|
||||
if selected$<>"Exit" then
|
||||
cls
|
||||
goto [start]
|
||||
else
|
||||
cls
|
||||
end
|
||||
end if
|
||||
29
Task/Menu/Seed7/menu.seed7
Normal file
29
Task/Menu/Seed7/menu.seed7
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
$ include "seed7_05.s7i";
|
||||
|
||||
const func string: menuSelect (in array string: items, in string: prompt) is func
|
||||
result
|
||||
var string: selection is "";
|
||||
local
|
||||
var string: item is "";
|
||||
var integer: index is 0;
|
||||
var integer: num is 0;
|
||||
begin
|
||||
if length(items) <> 0 then
|
||||
repeat
|
||||
for item key index range items do
|
||||
writeln(index <& ". " <& item);
|
||||
end for;
|
||||
write(prompt);
|
||||
readln(num);
|
||||
until num >= 1 and num <= length(items);
|
||||
selection := items[num];
|
||||
end if
|
||||
end func;
|
||||
|
||||
const array string: items is [] ("fee fie", "huff and puff", "mirror mirror", "tick tock");
|
||||
const string: prompt is "Which is from the three pigs? ";
|
||||
|
||||
const proc: main is func
|
||||
begin
|
||||
writeln("You chose " <& menuSelect(items, prompt));
|
||||
end func;
|
||||
19
Task/Menu/UNIX-Shell/menu-1.sh
Normal file
19
Task/Menu/UNIX-Shell/menu-1.sh
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# choose 'choice 1' 'choice 2' ...
|
||||
# Prints menu to standard error. Prompts with PS3.
|
||||
# Reads REPLY from standard input. Sets CHOICE.
|
||||
choose() {
|
||||
CHOICE= # Default CHOICE is empty string.
|
||||
[[ $# -gt 0 ]] || return # Return if "$@" is empty.
|
||||
select CHOICE; do # Select from "$@".
|
||||
if [[ -n $CHOICE ]]; then
|
||||
break
|
||||
else
|
||||
echo Invalid choice.
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
PS3='Which is from the three pigs: '
|
||||
choose 'fee fie' 'huff and puff' 'mirror mirror' 'tick tock'
|
||||
[[ -n $CHOICE ]] && echo You chose: $CHOICE
|
||||
[[ -z $CHOICE ]] && echo No input.
|
||||
54
Task/Menu/UNIX-Shell/menu-2.sh
Normal file
54
Task/Menu/UNIX-Shell/menu-2.sh
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
# choose 'choice 1' 'choice 2' ...
|
||||
# Prints menu to standard error. Prompts with $prompt.
|
||||
# Returns choice. If no input, returns empty list.
|
||||
fn choose args {
|
||||
# If args are empty, return empty list.
|
||||
~ $#args 0 && return
|
||||
|
||||
# Echo to standard error.
|
||||
let (reply =; choice =; fn-menu =; fn-ch =) >[1=2] {
|
||||
fn-menu = {
|
||||
# Show menu.
|
||||
let (i = 1) for (c = $args) {
|
||||
echo $i') '$c
|
||||
i = `{expr $i + 1}
|
||||
}
|
||||
}
|
||||
fn-ch = {
|
||||
# Set choice = $args($reply), but ignore error
|
||||
# if $reply is not a valid index.
|
||||
choice = <={catch @ e {result} {
|
||||
result $args($reply)
|
||||
}}
|
||||
}
|
||||
|
||||
menu
|
||||
forever {
|
||||
# Show prompt, read reply.
|
||||
echo -n $prompt
|
||||
reply = <={%read}
|
||||
|
||||
# If no input, return empty list.
|
||||
~ $#reply 0 && return
|
||||
|
||||
# Parse reply and return choice.
|
||||
reply = <={%split \ \t\n $reply}
|
||||
if {~ $#reply 0} {
|
||||
# Empty reply: show menu again.
|
||||
menu
|
||||
} {~ $#reply 1 && ch; ~ $#choice 1} {
|
||||
return $choice
|
||||
} {
|
||||
echo Invalid choice.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let (choice = <={
|
||||
local (prompt = 'Which is from the three pigs: ')
|
||||
choose 'fee fie' 'huff and puff' 'mirror mirror' 'tick tock'
|
||||
}) {
|
||||
~ $#choice 1 && echo You chose: $choice
|
||||
~ $#choice 0 && echo No input.
|
||||
}
|
||||
23
Task/Menu/XPL0/menu.xpl0
Normal file
23
Task/Menu/XPL0/menu.xpl0
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
include c:\cxpl\codes;
|
||||
string 0;
|
||||
|
||||
func Menu(List);
|
||||
int List;
|
||||
int Size, I, C;
|
||||
[Size:= List(0);
|
||||
if Size < 1 then return List(0);
|
||||
for I:= 1 to Size-1 do
|
||||
[IntOut(0, I); Text(0, ": ");
|
||||
Text(0, List(I)); CrLf(0);
|
||||
];
|
||||
CrLf(0);
|
||||
Text(0, List(Size)); \display prompt
|
||||
loop [C:= ChIn(0); \buffered keyboard requires Enter key
|
||||
if C>=^1 & C<=Size-1+^0 then return List(C-^0);
|
||||
Text(0, "Please enter 1 thru "); IntOut(0, Size-1);
|
||||
Text(0, ": ");
|
||||
];
|
||||
];
|
||||
|
||||
Text(0, Menu([5, "fee fie", "huff and puff", "mirror mirror", "tick tock",
|
||||
"Which phrase is from the Three Little Pigs? "]))
|
||||
Loading…
Add table
Add a link
Reference in a new issue