385 posts
Location
San Diego, CA
Posted 16 January 2016 - 10:47 PM
cyanisaac's basic menu APIFor all of your basic, keyboard-controlled menu needs.
[namedspoiler="Download]
[url="
http://pastebin.com/UK4ATXvH"]
http://pastebin.com/UK4ATXvHYou can choose to load this as a file if you would like, or you can bundle it in with your programs.
Usage
menu.doMenu(title, options)
title - a string that appears as the title of a menu.
options - an ordered table with strings. If the options table is too long for the screen to display the function will error. I will work on improving this soon.
Return value - number of option in table that is selected.
menu.doInfoScreen(title, info)
title - a string that appears as the title of the screen.
info - a string that is printed to the screen. If the string is too long for the screen to display, it will get cut off. I will work on improving this sometime in the future.
Return value - No value is returned.Licensing
This API is licensed under the MIT license, meaning you can do whatever you want as long as you attribute myself and ProjectB and don't sue me.
Please include somewhere in your code something similar to the following attribution:
-- Menu API provided by cyanisaac and ProjectB, licensed under the MIT license.
This should suffice. If you want to support me, consider sending Krist (KST) to my Krist address: kccec1d1aa
Edited on 25 January 2016 - 11:11 PM
385 posts
Location
San Diego, CA
Posted 17 January 2016 - 01:16 AM
I made a small demo. Load the Basic Menu API as "menu", and then run this program:
pastebin run fSvFMJ5Z
This is a small mockup settings program. The menu API handles all of the rendering and control of the menus, so all you have to focus on are your other custom screens and your control flow.
(Please note that the mockup settings program is missing some screens as it isn't plugged into any end applications - it's a mockup).
256 posts
Posted 17 January 2016 - 01:23 AM
Nice, but the text centering looks a little broken. Try adding one to all centered text?
function center(text, height, color)
local x,y=term.getSize()
if height ~= nil then
term.setCursorPos(((x - string.len(text)) / 2) + 1, height)
else
term.setCursorPos(((x - string.len(text)) / 2) + 1, y / 2)
end
if color ~= nil then
term.setTextColor(color)
end
term.write(text)
print("")
end
224 posts
Posted 17 January 2016 - 01:23 AM
Does it come with a scroll feature with large lists?
385 posts
Location
San Diego, CA
Posted 17 January 2016 - 01:30 AM
Does it come with a scroll feature with large lists?
No, if the list is too long for the computer to display, the API will error. Hence why the name is "cyanisaac's
basic menu API." (This API is really barebones). This is a known issue however, and I will be implementing a fix for it SoonTM. As you can see it is already in the "future improvements" list.
For now, just keep your lists short, or implement a button that says "More Options…" that links to another menu.
385 posts
Location
San Diego, CA
Posted 17 January 2016 - 08:32 PM
In the event that anyone is wondering, ProjectB is fine with me releasing this as an API. I've also added him as a "copyright holder" in the license included with the API, since although he didn't write the code it's extremely similar to O's menu system (almost a copy).
So yeah, we're on good terms, this API is allowed to exist.
385 posts
Location
San Diego, CA
Posted 19 January 2016 - 06:05 PM
Later today I will be pushing out an update with a bit of code cleanup, and a new doInfoScreen() function that will allow you to create a screen with information, and the user can press ENTER to exit the screen.
I am going to look to implement some further screens like Y/N info screens, and then after that I will look into colour options.
385 posts
Location
San Diego, CA
Posted 23 January 2016 - 06:27 PM
Somehow I got a bit delayed.
Update to the API is available on Pastebin. Changes include:
- Added doInfoScreen(title, info)
- Some code cleanup and other miscellaneous changes.
Report any issues you find. Thanks for using this API! :D/>
EDIT: Having serious trouble editing the post because the forum software is glitching out with formatting. Going to try recreating the post.
EDIT 2: The forums really screwed up the post.
EDIT 3: After three attempts, several browsers, advanced text editors, and many prayers, I got the forums to cooperate with me and let me modify the post. Woot.
Edited on 23 January 2016 - 05:55 PM