Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local os = require("os")
- local component = require("component")
- local gc = require("ogcolor")
- local gls = component.glasses
- local function wrap_string(str, wrapLength)
- local lines = {}
- while #str > 0 do
- local lastSpaceIndex
- -- Only check substrings longer than the wrap length
- if #str > wrapLength then
- -- Check for first space so words longer than `wrapLength` don't break.
- lastSpaceIndex = str:sub(1, wrapLength):find'%s%S*$' or str:find'%s'
- end
- table.insert(lines, str:sub(1, lastSpaceIndex))
- if not lastSpaceIndex then break end
- str = str:sub(lastSpaceIndex + 1)
- end
- return lines
- end
- local ognotify = {}
- --Send Notifications
- function ognotify.send(title,desc,timeout,bcolor,balpha,tcolor,talpha,dcolor,dalpha)
- local description = wrap_string(desc,35) -- 35 is approx. max num of characters before text protrudes from box
- --Background Rectangle
- local rect = gls.addRect()
- rect.setColor(table.unpack(bcolor))
- rect.setPosition(750,10)
- rect.setSize(25+(10 * #description),200)
- rect.setAlpha(balpha)
- --Title text
- local titleWidget = gls.addTextLabel()
- titleWidget.setText(title)
- titleWidget.setColor(table.unpack(tcolor))
- titleWidget.setPosition(690,15)
- titleWidget.setScale(1.1)
- titleWidget.setAlpha(talpha)
- --Description text
- local descWidget = {}
- local yPos = 30
- for i in ipairs(description) do
- --table.insert(descWidget,)
- descWidget[i] = gls.addTextLabel()
- descWidget[i].setScale(1.0)
- descWidget[i].setColor(table.unpack(dcolor))
- descWidget[i].setAlpha(dalpha)
- descWidget[i].setPosition(760,yPos)
- descWidget[i].setText(description[i])
- yPos = yPos + 10
- end
- os.sleep(timeout)
- --Clear notification
- gls.removeObject(rect.getID())
- gls.removeObject(titleWidget.getID())
- for i in ipairs(descWidget) do
- gls.removeObject(descWidget[i].getID())
- end
- return True
- end
- return ognotify
Advertisement
Add Comment
Please, Sign In to add comment