9551

simple code/note-pad --mini

Jul 3rd, 2021 (edited)
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.76 KB | None | 0 0
  1. local function e(t)if not fs.exists("button")then
  2. shell.run("pastebin get LTDZZZEJ button")end if not fs.exists("dsa")then
  3. shell.run("pastebin get J9mhuXuf dsa")end if not fs.exists("startup")then local
  4. a=fs.open("startup","w")a.writeLine('shell.run("npp")')a.close()end local
  5. o=require("button").terminal local i=require("dsa")local n={}local
  6. s={term.getSize()}local h=s[2]-5 local r=0.1 if not fs.exists("npp.data")then
  7. fs.open("npp.data","w").close()end local function d(l,u)local
  8. c=term.getSize()term.setCursorPos(math.ceil((c/2)-(l:len()/2)),u)term.write(l)end
  9. term.setCursorPos(1,1)local function
  10. m()term.setTextColor(colors.white)d("CC notepad+",1)term.setTextColor(colors.gray)d(string.rep("-",s[1]+1),2)term.setTextColor(colors.cyan)end
  11. while true do term.setBackgroundColor(colors.black)term.clear()m()if click~=nil
  12. then for f=1,h do n[f]=i.getLine("npp.data",f)if n[f]==""then n[f]=nil break
  13. end end do local w=term.getSize()local y=">create items<"if
  14. o.button(1,click,math.ceil((w/2)-(y:len()/2)),3,y)then if#n<=h-1 then
  15. d("make new item",4)d("please enter name",5)d("max length: "..w,6)local p=1 for
  16. v=1,#n do p=p+1 end repeat term.setCursorPos(1,7)n[p]=read()if#n[p]>=w then
  17. term.setCursorPos(1,7)term.write("your item is too long"..string.rep(" ",w-21))sleep(1.5)term.clearLine()end
  18. until(#n[p]<=w-1 and#n[p]>0)or n[p]=="__exit"if n[p]=="__exit"then
  19. n[p]=string.rep("-",w+1)end i.writeLine("npp.data",p,n[p])else
  20. d("you reached",4)d("max item count",5)sleep(1.5)end end
  21. term.setTextColor(colors.white)end for b,g in ipairs(n)do local
  22. k=term.getSize()local q=i.getLine("npp.data",b)if
  23. q:gsub(string.sub(q,2),"")=="\127"then term.setTextColor(colors.orange)end
  24. local j=q:gsub("\127","")if
  25. o.button(1,click,math.ceil((k/2)-(string.len(j)/2)),b+4,j)then n[b]=nil
  26. n=i.ser(n)fs.open("npp.data","w").close()for x=1,#n do
  27. i.writeLine("npp.data",x,n[x])end end term.setTextColor(colors.white)end for
  28. z,E in ipairs(n)do local T=term.getSize()local A=i.getLine("npp.data",z)if
  29. A:gsub(string.sub(A,2),"")=="\127"then term.setTextColor(colors.orange)end
  30. local O=A:gsub("\127","")if
  31. o.button(2,click,math.ceil((T/2)-(string.len(O)/2)),z+4,O)then if
  32. A:gsub(string.sub(A,2),"")~="\127"then i.writeLine("npp.data",z,"\127"..A)else
  33. i.writeLine("npp.data",z,A:gsub("\127",""))end end
  34. term.setTextColor(colors.white)end local
  35. I={term.getSize()}term.setTextColor(colors.red)if
  36. o.button(1,click,1,I[2],">exit<")then term.clear()term.setCursorPos(1,1)break
  37. end term.setTextColor(colors.yellow)if
  38. o.button(1,click,I[1]-11,I[2],">update npp<")then
  39. shell.run("rename npp npp.old")shell.run("pastebin get dRMEt5t1 npp")shell.run("rm npp.old")shell.run("npp")break
  40. end if o.button(1,click,I[1]-4,1,">\16\b<")then shell.run("edit npp.data")end
  41. if o.button(2,click,I[1]-4,1,">\16\b<")then term.clear()m()local
  42. N,S=loadfile("npp.data","bt",_ENV)if not S then ok,S=pcall(N)end if not ok then
  43. local H=term.getSize()for R=3,H-1 do
  44. term.setCursorPos(term.getCursorPos(),R)term.clearLine()end
  45. m()d("your code has crashed",4)d("reason:",5)term.setCursorPos(1,6)print(S
  46. or"unknown")sleep(1.5)end sleep(1)end end click=o.timetouch(r)end end local
  47. D=...if D=="update"then
  48. shell.run("rename npp npp.old")shell.run("pastebin get dRMEt5t1 npp")shell.run("rm npp.old")shell.run("npp")end
  49. local L,U=pcall(e)if not L then term.clear()term.setCursorPos(1,1)if
  50. string.sub(U,9)~="invalid pattern capture"then
  51. print("CC notepad+ has crashed\nreason:\n"..U.."\nhold Q for 1 second to start again\n or press anything else\nto exit")local
  52. C,M=os.pullEvent("char")if M=="q"then sleep(1)local C,M=os.pullEvent("char")if
  53. M=="q"then shell.run("npp")end end else
  54. 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
  55. end
Add Comment
Please, Sign In to add comment