5bitesofcookies

NoColor mod - Use the cursor!

Mar 1st, 2015
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.26 KB | None | 0 0
  1. --CONFIG:
  2. --remove 1 - to disable mutlishell
  3. ---[[
  4. useMultishell = true
  5. --]]
  6. if term.noColorVersion then
  7.     return
  8. end
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20. term.redirect(term.native())
  21. local mShell = multishell
  22. local oShell = shell
  23. multishell = nil
  24. shell = nil
  25. print(multishell)
  26. print(shell)
  27. --load redirect
  28. os.loadAPI"redirect"
  29. --m,ake a new buffer
  30. local w,h = term.getSize()
  31. local ter = redirect.createRedirectBuffer(w,h,0,0,true)
  32.  
  33.  
  34. local w,h = term.getSize()
  35. local bb = false
  36. local tb = false
  37. local bw = false
  38. local tw = false
  39.  
  40. local setTextColor = ter.setTextColor
  41. local setBackgroundColor = ter.setBackgroundColor
  42.  
  43. function term.isColor()
  44.     return true
  45. end
  46.  
  47. function term.isColour()
  48.     return true
  49. end
  50.  
  51. function term.setTextColor(c)
  52.     if c ~= colors.white and c ~= colors.black then
  53.         c = colors.white
  54.     end
  55.    
  56.     if bb == true then
  57.         c = colors.white
  58.     end
  59.    
  60.     if bw == true then
  61.         c = colors.black
  62.     end
  63.    
  64.     if c == colors.black then
  65.         tb = true
  66.     else
  67.         tb = false
  68.     end
  69.    
  70.     if c == colors.white then
  71.         tw = true
  72.     else
  73.         tw = false
  74.     end
  75.    
  76.     return setTextColor(c)
  77. end
  78. --local bb = false
  79.  
  80. function term.setBackgroundColor(c)
  81.     if c ~= colors.white and c ~= colors.black then
  82.         c = colors.black
  83.     end
  84.    
  85.     if c == colors.black then
  86.         bb = true
  87.     else
  88.         bb = false
  89.     end
  90.    
  91.     if c == colors.white then
  92.         bw = true
  93.     else
  94.         bw = false
  95.     end
  96.    
  97.     if tb == true then
  98.         c = colors.white
  99.     end
  100.    
  101.     if tw == true then
  102.         c = colors.black
  103.     end
  104.    
  105.     return setBackgroundColor(c)
  106. end
  107.  
  108. ter.setTextColour = ter.setTextColor
  109. ter.setBackgroundColour = ter.setBackgroundColor
  110.  
  111. function term.usingNoColor()
  112.     return true
  113. end
  114.  
  115. ter.usingNoColour = ter.usingNoColor
  116. UsingNoColor = ter.usingNoColor
  117. UsingNoColour = ter.usingNoColor
  118.  
  119. function term.noColorVersion()
  120.     return "v1-M"--version 1 modded
  121. end
  122.  
  123.  
  124. ter.noColourVersion = ter.noColorVersion
  125. NoColourVersion = ter.noColorVersion
  126. NoColorVersion = ter.noColorVersion
  127. --function ter.native() return ter end
  128. local native = term.current()
  129. --ter = term.current()
  130. term.clear()
  131. term.redirect(ter)
  132. term.clear()
  133. term.setCursorPos(1,1)
  134. --[[code:
  135. 1 - started mousepress
  136. table -- returning event
  137. 2 - user wants 'alt']]
  138. local shellCo = coroutine.create(function()
  139.     if useMultishell then
  140.         os.run({},"rom/programs/advanced/multishell")
  141.     else
  142.         os.run({},"rom/programs/shell")
  143.     end
  144. end)
  145. --[[mouse = coroutine.create(function()
  146.     local inform
  147.     local x
  148.     local y
  149.     local w,h = term.getSize()
  150.     while true do
  151.         local a={coroutine.yield(inform)}
  152.  
  153.         end
  154.     end
  155. end)]]
  156. os.queueEvent"ignoreThis"
  157. function p(a,b,c,d,e,f,g) if false then write(a or ""..b or ""..c or ""..d or ""..e or ""..f or ""..g or "") end end
  158. local nextEvent
  159. local x,y = 1,1
  160. while coroutine.status(shellCo)=="suspended" do
  161.     --print"1"
  162.     local a
  163.     if nextEvent then
  164.         --p(nextEvent)
  165.         --sleep(1)
  166.         a = nextEvent
  167.     else
  168.         a = {coroutine.yield()}
  169.     end
  170.     --print"2"
  171.     --print"2.5"
  172.     nextEvent = nil
  173.     --nextEvent things:
  174.     if a[1] =="key" and a[2]==56 then --alt
  175.         local px,py = term.getCursorPos()--cursor pos before moving
  176.         term.setCursorBlink(false)
  177.         term.setBackgroundColor(colors.black)
  178.         term.redirect(native)
  179.         term.setTextColor(colors.white)
  180.         term.setCursorPos(x,y)
  181.         write"X"
  182.         while true do
  183.             local a = {coroutine.yield()}
  184.             if a[1]=="key" then
  185.                 if a[2]==200 then --up
  186.                     if not (y<=1) then
  187.                         y=y-1
  188.                     end
  189.                 elseif a[2]==208  then --down
  190.                     if not (y>=h) then
  191.                         y=y+1
  192.                     end
  193.                 elseif a[2]==203 then  --left
  194.                     if not (x<=1) then
  195.                         x=x-1
  196.                     end
  197.                 elseif a[2]==205 then --right
  198.                     if not (x>=w) then
  199.                         x=x+1
  200.                     end
  201.                 elseif a[2]==56 then
  202.                     nextEvent = {"key",56}--alt
  203.                     break
  204.                 elseif a[2]==28 then --enter
  205.                     nextEvent ={"mouse_click",1,x,y}--m1 at x,y
  206.                     break
  207.                 elseif a[2]==54 then --shift
  208.                     nextEvent = {"mouse_click",2,x,y}--m2 at x,y
  209.                     break
  210.                 end
  211.             end
  212.             --draw it
  213.             term.redirect(native)
  214.             ter.blit()--draw the screen
  215.             p(x,y)
  216.             term.setCursorPos(x,y)
  217.             write"X"
  218.         end
  219.         ter.blit()
  220.         term.setCursorPos(px,py)
  221.     else
  222.         term.redirect(ter)
  223.         coroutine.resume(shellCo,unpack(a))
  224.     end
  225.     term.redirect(native)
  226.     ter.blit()
  227. end
  228. term.redirect(native)
  229. print"Completed."
  230. multishell = mShell
  231. shell = oShell
Advertisement
Add Comment
Please, Sign In to add comment