Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local b
- local updaterate
- local alive = true
- local function tdlMain(arg)
- if not fs.exists("button") then
- shell.run("pastebin get LTDZZZEJ button")
- end
- if not fs.exists("dsa") then
- shell.run("pastebin get J9mhuXuf dsa")
- end
- if not fs.exists("startup") then
- local tempfile = fs.open("startup", "w")
- tempfile.writeLine('shell.run("npp")')
- tempfile.close()
- end
- b = require("button").terminal
- local data = require("dsa")
- local items = {}
- local startsize = {term.getSize()}
- local maxitems = startsize[2] - 5
- updaterate = 0.1
- if not fs.exists("npp.data") then
- fs.open("npp.data", "w").close()
- end
- local function centerWrite(text, customY)
- local width = term.getSize()
- term.setCursorPos(math.ceil((width / 2) - (text:len() / 2)), customY)
- term.write(text)
- end
- term.setCursorPos(1, 1)
- local function tdl()
- term.setTextColor(colors.white)
- centerWrite("CC notepad+", 1)
- term.setTextColor(colors.gray)
- centerWrite(string.rep("-", startsize[1] + 1), 2)
- term.setTextColor(colors.cyan)
- end
- while true do
- term.setBackgroundColor(colors.black)
- term.clear()
- tdl()
- if click ~= nil then
- for i = 1, maxitems do
- items[i] = data.getLine("npp.data", i)
- if items[i] == "" then
- items[i] = nil
- break
- end
- end
- do
- local width = term.getSize()
- local text = ">create items<"
- if b.button(1, click, math.ceil((width / 2) - (text:len() / 2)), 3, text) then
- if #items <= maxitems - 1 then
- centerWrite("make new item", 4)
- centerWrite("please enter name", 5)
- centerWrite("max length: " .. width, 6)
- local count = 1
- for i = 1, #items do
- count = count + 1
- end
- repeat
- term.setCursorPos(1, 7)
- items[count] = read()
- if #items[count] >= width then
- term.setCursorPos(1, 7)
- term.write("your item is too long" .. string.rep(" ", width - 21))
- sleep(1.5)
- term.clearLine()
- end
- until (#items[count] <= width - 1 and #items[count] > 0) or items[count] == "__exit"
- if items[count] == "__exit" then
- items[count] = string.rep("-", width + 1)
- end
- data.writeLine("npp.data", count, items[count])
- else
- centerWrite("you reached", 4)
- centerWrite("max item count", 5)
- sleep(1.5)
- end
- end
- term.setTextColor(colors.white)
- end
- for k, v in ipairs(items) do
- local width = term.getSize()
- local text = data.getLine("npp.data", k)
- if text:gsub(string.sub(text, 2), "") == "\127" then
- term.setTextColor(colors.orange)
- end
- local texts = text:gsub("\127", "")
- if b.button(1, click, math.ceil((width / 2) - (string.len(texts) / 2)), k + 4, texts) then
- items[k] = nil
- items = data.ser(items)
- fs.open("npp.data", "w").close()
- for i = 1, #items do
- data.writeLine("npp.data", i, items[i])
- end
- end
- term.setTextColor(colors.white)
- end
- for k, v in ipairs(items) do
- local width = term.getSize()
- local text = data.getLine("npp.data", k)
- if text:gsub(string.sub(text, 2), "") == "\127" then
- term.setTextColor(colors.orange)
- end
- local texts = text:gsub("\127", "")
- if b.button(2, click, math.ceil((width / 2) - (string.len(texts) / 2)), k + 4, texts) then
- if text:gsub(string.sub(text, 2), "") ~= "\127" then
- data.writeLine("npp.data", k, "\127" .. text)
- else
- data.writeLine("npp.data", k, text:gsub("\127", ""))
- end
- end
- term.setTextColor(colors.white)
- end
- local scale = {term.getSize()}
- term.setTextColor(colors.red)
- if b.button(1, click, 1, scale[2], ">exit<") then
- term.clear()
- term.setCursorPos(1, 1)
- alive = false
- break
- end
- term.setTextColor(colors.yellow)
- if b.button(1, click, scale[1] - 11, scale[2], ">update npp<") then
- shell.run("rename npp npp.old")
- shell.run("pastebin get yU5gzMZ1 npp")
- shell.run("rm npp.old")
- shell.run("npp")
- break
- end
- if b.button(1, click, scale[1] - 4, 1, ">\16\b<") then
- shell.run("edit npp.data")
- end
- if b.button(2, click, scale[1] - 4, 1, ">\16\b<") then
- term.clear()
- tdl()
- local run, err = loadfile("npp.data", "bt", _ENV)
- if not err then
- ok, err = pcall(run)
- end
- if not ok then
- local width = term.getSize()
- for i = 3, width - 1 do
- term.setCursorPos(term.getCursorPos(), i)
- term.clearLine()
- end
- tdl()
- centerWrite("your code has crashed", 4)
- centerWrite("reason:", 5)
- term.setCursorPos(1, 6)
- print(err or "unknown")
- sleep(1.5)
- end
- sleep(1)
- end
- end
- sleep(0.1)
- end
- end
- local updatec = function()
- while alive do
- if b then click = b.timetouch(updaterate)
- else sleep(1) end
- end
- end
- local arg = ...
- if arg == "update" then
- shell.run("rename npp npp.old")
- shell.run("pastebin get yU5gzMZ1 npp")
- shell.run("rm npp.old")
- shell.run("npp")
- end
- local ok, err = pcall(parallel.waitForAll,tdlMain,updatec)
- if not ok then
- term.clear()
- term.setCursorPos(1, 1)
- if string.sub(err, 9) ~= "invalid pattern capture" then
- print(
- "CC notepad+ has crashed\nreason:\n" ..
- err .. "\nhold Q for 1 second to start again\n or press anything else\nto exit"
- )
- local _, event = os.pullEvent("char")
- if event == "q" then
- sleep(1)
- local _, event = os.pullEvent("char")
- if event == "q" then
- shell.run("npp")
- end
- end
- else
- print("data storage corruted\nmaking copy\nand deleting")
- shell.run("copy npp.data npp.data." .. tostring(math.random(1, 100000)))
- shell.run("rm npp.data")
- sleep(2)
- shell.run("npp")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement