Menu: Difference between revisions
→{{header|langur}}
mNo edit summary |
Langurmonkey (talk | contribs) |
||
(11 intermediate revisions by 5 users not shown) | |||
Line 783:
=={{header|D}}==
<syntaxhighlight lang="d">
import std.stdio, std.conv, std.string, std.array, std.typecons;
string menuSelect(in string[] entries) {
Line 791 ⟶ 792:
try {
immutable n = input.to!int;
return typeof(return)((n >= 0 && n <= nEntries) ? n : -1);
} catch (Exception e) // Very generic
Line 804 ⟶ 806:
writefln(" %d) %s", i, entry);
"> ".write;
immutable input = readln.chomp;
immutable choice = validChoice(input, cast(int) (entries.length - 1));
if (choice.isNull)
"Wrong choice.".writeln;
Line 816 ⟶ 821:
immutable items = ["fee fie", "huff and puff",
"mirror mirror", "tick tock"];
writeln("You chose '", items.menuSelect, "'.");
}
{{out}}
<pre>
Choose one:
0) fee fie
1) huff and puff
Line 825 ⟶ 834:
3) tick tock
> 2
You chose 'mirror mirror'.
</pre>
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
Line 1,316 ⟶ 1,327:
print menu_select( menu() )</syntaxhighlight>
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
_window = 1
begin enum 1
_response
_popupBtn
end enum
void local fn BuildPopUpMenu
menu 101
menu 101, 0,, @"Select numbered menu item from the Three Pigs"
menu 101, 1,, @"1. fee fie"
menu 101, 2,, @"2. huff and puff"
menu 101, 3,, @"3. mirror mirror"
menu 101, 4,, @"4. tick tock"
menu 101, 5,, @" ?????????"
end fn
void local fn BuildWindow
CGRect r = fn CGRectMake( 0, 0, 480, 360 )
window _window, @"Rosetta Code Menu Task", r, NSWindowStyleMaskTitled + NSWindowStyleMaskClosable + NSWindowStyleMaskMiniaturizable
r = fn CGRectMake( 45, 240, 380, 34 )
textlabel _response,, r, _window
ControlSetAlignment( _response, NSTextAlignmentCenter )
r = fn CGRectMake( 65, 200, 340, 34 )
popupbutton _popupBtn,,,, r, YES
PopUpButtonSetMenu( _popupBtn, 101 )
end fn
void local fn DoMenu( menuID as long, itemID as long )
select (menuID)
select (ItemID)
case 1 : ControlSetStringValue( _response, @"1. Sorry, wrong: From Jack the Giant Killer." )
case 2 : ControlSetStringValue( _response, @"2. CORRECT!: From The Three Little Pigs." )
case 3 : ControlSetStringValue( _response, @"3. Sorry, wrong: From Snow White and the Seven Dwarfs." )
case 4 : ControlSetStringValue( _response, @"4. Sorry, wrong: From Tick Tock Goes the Clock Rhyme." )
case 5 : ControlSetStringValue( _response, @"Surely you could just make a guess! Try again." )
end select
end select
end fn
fn BuildPopUpMenu
fn BuildWindow
on menu fn DoMenu
HandleEvents
</syntaxhighlight>
[[file:Rosetta_Code_FutureBasic_Menu_Task.png]]
=={{header|Gambas}}==
Line 1,764 ⟶ 1,828:
=={{header|langur}}==
▲<syntaxhighlight lang="langur">val .select = f(.entries) {
▲ if not isArray(.entries): throw "invalid args"
if len(.entries) == 0: return ""
# print the menu
writeln join "\n", map(
val .idx =
"Select entry #: ",
if not
val .y =
.y > 0 and .y <= len(.entries)
},
Line 2,989 ⟶ 3,052:
mirror mirror
</pre>
=={{header|RPL}}==
≪ → prompt options
≪ '''IF''' options SIZE '''THEN'''
prompt options 1 CHOOSE
'''IF''' NOT '''THEN''' "" '''END'''
'''ELSE''' "" '''END'''
≫ '<span style="color:blue">SELECT</span>' STO
"Make a choice" { } <span style="color:blue">SELECT</span>
"Make a choice" { "fee fie" "huff and puff" "mirror mirror" "tick tock" } <span style="color:blue">SELECT</span>
=={{header|Ruby}}==
Line 3,621 ⟶ 3,695:
=={{header|Wren}}==
{{libheader|Wren-ioutil}}
<syntaxhighlight lang="
var menu = Fn.new { |list|
|