-
Notifications
You must be signed in to change notification settings - Fork 17
/
drawmenu.mac
115 lines (92 loc) · 2.57 KB
/
drawmenu.mac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* vim: set ft=cpp: */
#include "macro.h"
#include "system.h"
#include "utils.h"
#include "keycodes.h"
#include "prompt.h"
#pragma title Sample Menu Macro
// The default selected menu option.
assign(option, 0)
// Draw all the menu options.
// Syntax: call(drawmenu, xpos, ypos, width)
function(drawmenu,
// Choose Menu position
$pop(width)
$pop(ypos)
$pop(xpos)
// Select the current entry.
assign(entry, -1)
// Most drawing and positioning commands only work inside prompt().
prompt(
clrscreen()
attrclr()
boxtop($(xpos), $(ypos), $(width))
)
// Move to the next line.
$inc(ypos)
// Draw a header.
prompt(boxtxt($(xpos),
$(ypos),
$(width),
bold(`Please Select an Option...`)))
// Draw the menu entries.
foreach(msg,
`This is an option`,
`This is another option`,
`This is a third option`,
`I can keep doing this`,
`Every option is added to the list`)
// Move to the next line.
$inc(ypos) $inc(entry)
// If this option is active, highlight it.
if ($(option) = $(entry))
// This draws the option in reverse video.
prompt(boxsel($(xpos), $(ypos), $(width), $(msg)))
else
prompt(boxtxt($(xpos), $(ypos), $(width), $(msg)))
endif
endfor
// Draw the bottom of the menu box.
$inc(ypos)
prompt(boxbot($(xpos), $(ypos), $(width)))
// Move the cursor out of the way.
prompt(curshome())
// If we never found an active entry, scroll around to top and try again.
if ($(option) < 0 $or $(option) > $(entry))
assign(option, 0)
call(drawmenu, $(xpos), $(ypos) - $(entry) - 3, $(width))
endif
)
// Choose the next option above.
function(menuup,
$dec(option)
call(drawmenu, 5, 5, 60)
)
// Choose the next option down.
function(menudown,
$inc(option)
call(drawmenu, 5, 5, 60)
)
// Choose the hilighted option.
function(menuquit,
// Remove any menu junk left on the screen.
prompt(clrscreen())
// Do something with the result.
status(`You selected $(option)`)
// All done.
quit()
)
// Draw the base menu.
call(drawmenu, 5, 5, 60)
// Wait for a key press.
while ($true)
// If you use look(), the menu will constantly poll for input.
// char() will block and wait for a key.
char(key, ``)
// Dispatch the read key to a handler.
casecall ($(key))
match({up}, menuup)
match({down}, menudown)
match({enter}, menuquit)
endcase
endwhile