Posted 22 February 2016 - 04:08 AM
So, this is an api(ish) that is intended for general time-saving. Or it will be. As I make new functions, I'll upload them, however, at the moment it only has 3 functions, one of which is the updater. Any feedback is MUCH appreciated, thanks!
http://pastebin.com/XZS4eF9Z
Functions:
drawScreen:
Or this:
The function will return the selected option when it's done, in number format. So if the user selected the first option, (and your table is formatted correctly) it would return 1. EDIT: Should mention, it supports arrow keys as well as mouse clicks.
Raw Coding:
silentPastebin:
Raw Code:
Also, the updater function requires you to give it a path. For some reason, shell.dir() wasn't wanting to work, sorry. Again, any feedback is greatly appreciated, thanks!
http://pastebin.com/XZS4eF9Z
pastebin get XZS4eF9Z jenisis
Functions:
drawScreen:
Spoiler
This is a basic screen function. It takes two tables, first a "static" table and then the button table. The "statics" will be placed at the top and are, well, static. Both tables should be formatted like this:
table = {
"This would be a button",
"And so would this"
}
Or this:
table[1] = "This would be a button
table[2] = "And so would this"
The function will return the selected option when it's done, in number format. So if the user selected the first option, (and your table is formatted correctly) it would return 1. EDIT: Should mention, it supports arrow keys as well as mouse clicks.
Raw Coding:
Spoiler
function drawScreen(staticScreen, tableScreen)
running = true
rkeyp = true
cselected = 1
num = 1
static = true
while running == true do
term.clear()
term.setCursorPos(1, 1)
screenX, screenY = term.getSize()
rkeyp = true
isPrint = true
num = 1
static = true
staticNum = 1
while static == true do
line = staticScreen[staticNum]
if line ~= nil then
print(line)
staticNum = staticNum + 1
else
static = false
end
end
num = 1
print(" ")
while isPrint == true do
line = tableScreen[num]
if line ~= nil and num ~= cselected then
print(line)
num = num + 1
elseif line ~= nil and num == cselected then
print("["..line.."]")
num = num + 1
else
isPrint = false
end
end
while rkeyp == true do
breaker = os.startTimer(1)
event = {os.pullEvent()}
param = event[2]
if event[1] == "key" then
if param == 200 then
cselected = cselected - 1
if cselected <= 0 then
cselected = num - 1
end
rkeyp = false
elseif param == 208 then
cselected = cselected + 1
if cselected >= num then
cselected = 1
end
rkeyp = false
elseif param == 28 then
return cselected
elseif param == 15 then
return 999
end
elseif event[1] == "mouse_click" then
start = staticNum
selectedNum = event[4] - start
if selectedNum > 0 and selectedNum <= num then
return selectedNum
end
end
end
end
end
silentPastebin:
Spoiler
Fairly simple, basically the pastebin program, except it doesn't print anything, and it doesn't put anything on pastebin, therefore the arguments are the code followed by the path. It will return Success, Failed, or Exists.Raw Code:
Spoiler
function silentPastebin(target, path)
if fs.exists(path) then
return "Exists"
end
paste = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode(target))
if paste then
text = paste.readAll()
paste.close()
file = fs.open(path, "w")
file.write(text)
file.close()
return "Success"
else
return "Failed"
end
end
Also, the updater function requires you to give it a path. For some reason, shell.dir() wasn't wanting to work, sorry. Again, any feedback is greatly appreciated, thanks!
Edited on 22 February 2016 - 04:47 AM