Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local bridge = component.openperipheral_bridge
- local text = require("text")
- local unicode = require("unicode")
- local event = require("event")
- local serialization = require("serialization")
- --local fs = require("filesystem")
- local lineWidth = 1
- local letters = {
- "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
- "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
- "А", "Б", "В", "Г", "Д", "Е", "Ё", "Ж", "З", "И", "Й", "К", "Л", "М", "Н", "О", "П", "Р", "С", "Т", "У", "Ф", "Х", "Ц", "Ч", "Ш", "Щ", "Ъ", "Ы", "Ь", "Э", "Ю", "Я",
- "а", "б", "в", "г", "д", "е", "ё", "ж", "з", "и", "й", "к", "л", "м", "н", "о", "п", "р", "с", "т", "у", "ф", "х", "ц", "ч", "ш", "щ", "ъ", "ы", "ь", "э", "ю", "я"
- }
- local symbols = {"!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "_", "=", "+", "[", "]", "{", "}", ";", ":", "'", "\"", ",",
- ".", "/", "<", ">", "?", "\\"}
- local checkedChars = {}
- local all_chars = {}
- for i, value in ipairs(letters) do
- table.insert(all_chars, value)
- end
- for i, value in ipairs(symbols) do
- table.insert(all_chars, value)
- end
- local currentCharIndex = 1
- local yLine = 11
- local path = "/home/checkedChars.txt"
- local function saveCharsToFile()
- local serialised = serialization.serialize(checkedChars)
- print()
- local file = io.open(path, "w")
- file:write(serialised)
- file:close()
- print("Записано в файл "..path)
- end
- local function continueFromFile()
- local file = io.open(path, "r")
- if file then
- local string = file:read("*all")
- if string and #string > 0 then
- print("файл прочитан"..#checkedChars)
- checkedChars = serialization.unserialize(string)
- if #checkedChars > 0 then
- currentCharIndex = #checkedChars + 1
- end
- else
- print("Ошибка чтения с файла, файл или пустой или невалидные данные")
- end
- file:close()
- else
- print("Ошибка чтения с файла, файл или пустой или невалидные данные")
- end
- end
- continueFromFile()
- bridge.clear()
- local currSize = bridge.addText(20, 20, tostring(lineWidth), 0x00ffa2)
- local charsBox = bridge.addText(10, 10, all_chars[currentCharIndex] or all_chars[#all_chars], 0xFFFFFF)
- local box = bridge.addBox(10, yLine, lineWidth, 1, 0x00ffa2)
- bridge.sync()
- local function handleKeyEvent(...)
- local args = {...}
- local eventName = args[1]
- local code = args[5]
- print(eventName.. " "..code)
- if eventName == "glasses_key_down" and code == 12 or code == 13 or code == 28 or code == 42 or code == 200 or code == 208 or code == 205 or code == 203 then
- if code == 12 then -- минус
- lineWidth = lineWidth - 1
- elseif code == 13 then --плюс
- lineWidth = lineWidth + 1
- elseif code == 28 then --ентер
- table.insert(checkedChars,currentCharIndex,{char = all_chars[currentCharIndex], charWidth = lineWidth})
- currentCharIndex = #checkedChars + 1
- if currentCharIndex > #all_chars then
- saveCharsToFile()
- end
- print("Символ \'"..all_chars[currentCharIndex].."\' записан")
- elseif code == 42 then --шифт
- saveCharsToFile()
- elseif code == 200 then --стрелочка вверх
- yLine = yLine - 1
- elseif code == 208 then --стрклочка вниз
- yLine = yLine + 1
- elseif code == 205 then --стрелочка вправо
- if currentCharIndex < #checkedChars then
- print("next")
- currentCharIndex = currentCharIndex + 1
- lineWidth = checkedChars[currentCharIndex].charWidth or 1
- end
- elseif code == 203 then --стрелочка влево
- if currentCharIndex > 1 then
- currentCharIndex = currentCharIndex - 1
- lineWidth = checkedChars[currentCharIndex].charWidth or 1
- end
- print("prev")
- end
- currSize.setText(tostring(lineWidth))
- box.setWidth(lineWidth)
- box.setY(yLine)
- charsBox.setText(all_chars[currentCharIndex])
- bridge.sync()
- end
- end
- event.listen("glasses_capture", function()
- local uuid = bridge.getUsers()[1].uuid -- можно использовать только если один пользователь использует терминал
- local capture = bridge.getCaptureControl(uuid)
- capture.setBackground(0x000000, 0.05)
- end)
- event.listen("glasses_key_down", handleKeyEvent)
Advertisement
Add Comment
Please, Sign In to add comment