Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local x, y, w, text, filter, evf = table.unpack({...})
- local EU = require("ExtraUtilits")
- local gpu = require("component").gpu
- local unicode = require("unicode")
- local reason = false
- local function wind()
- gpu.setBackground(0x323232)
- gpu.fill(x, y, w + 2, 3, " ")
- if text then
- gpu.setForeground(0x00ffff)
- gpu.set(x, y, text)
- end
- gpu.setBackground(0x161616)
- gpu.fill(x + 1, y + 1, w, 1, " ")
- end
- local buttons = {
- {x + w + 2 - 5, y + 2, 4, 1, 2499366, 15563520, "OK"}
- }
- local text = ""
- local function filtrate(byte, filter)
- local char = unicode.char(byte)
- if not filter then
- if byte >= 21 and byte <= 126 or byte >= 1040 and byte <= 1103 then
- return char
- end
- elseif filter == "number" then
- if tonumber(char) then
- return tonumber(char)
- end
- elseif filter == "string" then
- if tonumber(char) == nil then
- if byte <= 21 and byte <= 126 or byte >= 1040 and byte <= 1103 then
- return char
- end
- end
- end
- end
- local function drawText()
- if gpu.getBackground ~= 0x161616 then gpu.setBackground(0x161616) end
- if gpu.getForeground ~= 0x00ffff then gpu.setForeground(0x00ffff) end
- local visible_text = string.sub(text, -w)
- gpu.fill(x+1, y+1, w, 1, " ")
- gpu.set(x + 1, y + 1, visible_text)
- end
- buttons.eventFunc = function(ev)
- local eventType = ev[1]
- if eventType == "key_down" then
- local eventType, _, key = table.unpack(ev)
- if key == 9 then buttons.close = true reason = "closed" elseif key == 13 then buttons.close = true elseif key == 8 then text = string.sub(text, 0, -2) else
- local char = filtrate(key, filter)
- if char then text = text .. char end
- end
- drawText()
- end
- end
- buttons[1][8] = function()
- buttons.close = true
- end
- EU.screenBackup(function()
- wind()
- EU.draw(buttons)
- EU.buttonPress(buttons)
- end)
- if not reason then
- if filter == "number" then
- text = tonumber(text)
- end
- return text
- else
- return nil, reason
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement