Operating system for OpenComputers
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

130 Zeilen
2.2KB

  1. local tA = {...}
  2. local ft, p, fp, ct, il, it, c, C = {}, 1, fp or tA[1] or "", {}, "", {}, "", C -- file table, pointer, filename, command table, input line, input table, command, content
  3. function ct.readfile(fp,rp)
  4. if not fp then return end
  5. if not rp then ft = {} end
  6. local f=io.open(fp,"rb")
  7. if f then
  8. C=f:read("*a")
  9. f:close()
  10. for l in C:gmatch("[^\n]+") do
  11. ft[#ft+1] = l
  12. end
  13. end
  14. end
  15. function ct.writefile(nfp)
  16. if not nfp then nfp = fp end
  17. print(nfp)
  18. f=io.open(nfp,"wb")
  19. if f then
  20. for k,v in ipairs(ft) do
  21. print(v)
  22. f:write(v.."\n")
  23. end
  24. coroutine.yield()
  25. f:close()
  26. coroutine.yield()
  27. print(f.b)
  28. end
  29. end
  30. function ct.list(s,e)
  31. s,e = s or 1, e or #ft
  32. for i = s,e do
  33. if ft[i] then
  34. print(string.format("%4d\t %s",i,ft[i]))
  35. end
  36. end
  37. end
  38. function ct.sp(np)
  39. np=tonumber(np)
  40. if np then
  41. if np > #ft then
  42. np = #ft
  43. elseif np < 1 then
  44. np = 0
  45. end
  46. p=np
  47. end
  48. end
  49. function ct.pointer(np)
  50. ct.sp(np)
  51. print(string.format("%4d\t %s",p,ft[p]))
  52. end
  53. function ct.insert(np)
  54. ct.sp(np)
  55. while true do
  56. io.write(string.format("%4d\t ",p))
  57. local l=io.read()
  58. if l == "." then break end
  59. table.insert(ft,p,l)
  60. p=p+1
  61. end
  62. end
  63. function ct.append(np)
  64. ct.sp(np)
  65. p=p+1
  66. if #ft < 1 then p = 1 end
  67. ct.insert()
  68. end
  69. function ct.delete(np,n)
  70. ct.sp(np)
  71. _G.clip = ""
  72. for i = 1, (n or 1) do
  73. _G.clip = _G.clip .. table.remove(ft,p) .. "\n"
  74. end
  75. end
  76. function ct.substitute(np,n)
  77. ct.delete(np,n)
  78. ct.insert(np)
  79. end
  80. function ct.filename(np)
  81. if np then fp = np end
  82. print(fp)
  83. end
  84. local function rawpaste()
  85. for line in string.gmatch(_G.clip,"[^\n]") do
  86. print(string.format("%4d\t %s",p,line))
  87. table.insert(ft,p,line)
  88. end
  89. end
  90. function ct.pasteprevious(np)
  91. ct.sp(np)
  92. rawpaste()
  93. end
  94. function ct.paste(np)
  95. ct.sp(np)
  96. p = p + 1
  97. rawpaste()
  98. end
  99. ct.o = ct.readfile
  100. ct.w = ct.writefile
  101. ct.l = ct.list
  102. ct.p = ct.pointer
  103. ct.i = ct.insert
  104. ct.a = ct.append
  105. ct.s = ct.substitute
  106. ct.d = ct.delete
  107. ct.f = ct.filename
  108. ct.PP = ct.pasteprevious
  109. ct.P = ct.paste
  110. ct.readfile(fp)
  111. while true do
  112. io.write("skex2> ")
  113. il,it=io.read(),{}
  114. for w in il:gmatch("%S+") do
  115. it[#it+1] = w
  116. end
  117. c=table.remove(it,1)
  118. if c == "quit" or c == "q" then
  119. break
  120. elseif c:sub(1,1) == "!" then
  121. print(pcall(load(c:sub(2))))
  122. elseif ct[c] ~= nil then
  123. ct[c](table.unpack(it))
  124. end
  125. end