Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local event = require("event")
- local fs = require("filesystem")
- local keyboard = require("keyboard")
- local shell = require("shell")
- local term = require("term")
- local text = require("text")
- local unicode = require("unicode")
- local sides = require("sides")
- local colors=require("colors")
- local line = " "
- --getString:
- -- Given a row and col, and an initial string, edit a string
- -- len is the maximum number of characters allowed in the string
- local function getString (row, col, start, len)
- local currLine = start
- if string.len(currLine) > 0 then
- currLine = currLine:gsub("^%s*(.-)%s*$", "%1")
- end
- local finished = false
- while not finished do
- local event, address, char, code, arg3 = event.pull()
- term.setCursor(col, row)
- if string.len(currLine) <= len then
- print(currLine)
- end
- if type(address) == "string" and component.isPrimary(address) then
- if event == "key_down" then
- if code == keyboard.keys.back then
- if string.len(currLine) > 0 then
- currLine = string.sub(currLine, 1, (string.len(currLine) - 1))
- if currPos > 0 then
- currPos = currPos - 1
- end
- end
- elseif code == keyboard.keys.enter then
- finished = true
- elseif not keyboard.isControl(char) then
- if string.len(currLine) < len then
- currLine = currLine..string.char(char)
- end
- end
- end
- end
- end
- return (currLine)
- end
- line = getString (5, 10, line, 30)
- term.setCursor(7, 10)
- print(line)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement