Andy73

Editor

Jul 28th, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.21 KB | None | 0 0
  1. --alright, let's make an editor in pure CC (like the text window/richTextBox u know )
  2. -- we'll at first use the CC's edit and LuaIDE source
  3.  
  4. local fn="fn"
  5. local
  6.  
  7. local Languages={
  8. ["Lua"]={
  9. Enabled=true,
  10. Tip={
  11. --Standard={ nope, lets do it all in one, dynamically, that'll be easier
  12. math={
  13. [1]=true,
  14. [3]={
  15. pow={true},
  16. sin={true},},
  17. },
  18. s={"string", "stringFn", "sleep",},
  19. st={"string", "stringFn", },
  20. str={"string", "stringFn", },  -- u see? lets make the permutations for all of the
  21. stri={"string", "stringFn", }, -- known functions and apis and reindex them on code
  22. strin={"string", "stringFn", },-- change. stringFn was chosen for demo
  23. string={
  24. [1]=true
  25. [2]={"stringFn",},
  26. [3]={ lower={true},
  27. upper={true},
  28. len={true}, },
  29. ico=api,
  30. str="string",
  31. },
  32. stringF={ "stringFn", },
  33. stringFn={true},
  34. sl={"sleep"},
  35. sle={"sleep"},
  36. slee={"sleep"},
  37. sleep={true},
  38. },
  39. --},
  40.  
  41.  
  42. Highlight={
  43. Keyword={
  44. Value={"true","false","nil"}
  45. Common={"local","function"}
  46. Loop={"for","while","do","repeat","until","end"},
  47. Conditional={"if","then","elseif","else"},
  48. Other={"in","return"}
  49. },
  50. --Function={"error","print"}, NOPE! better to store functions for the "IntelliSense" and then highlight them
  51. Match={
  52. String={ "^\".-[^\\]\"", "^\'.-[^\\]\'", "^%[%[.-%]%]" },
  53. Comment={ "^%-%-%[%[.-%]%]", "^%-%-.*" }
  54. },
  55. },
  56.  
  57.  
  58. },
  59. ["Javascript"]={Enabled=false,},
  60. }
  61.  
  62. local function tryWrite( sLine, regex, colour )
  63.     local match = string.match( sLine, regex )
  64.     if match then
  65.         if type(colour) == "number" then
  66.             term.setTextColour( colour )
  67.         else
  68.             term.setTextColour( colour(match) )
  69.         end
  70.         term.write( match )
  71.         term.setTextColour( textColour )
  72.         return string.sub( sLine, string.len(match) + 1 )
  73.     end
  74.     return nil
  75. end
  76.  
  77. local function writeHighlighted( sLine )
  78.     while string.len(sLine) > 0 do 
  79.         sLine =
  80.             tryWrite( sLine, "^%-%-%[%[.-%]%]", commentColour ) or
  81.             tryWrite( sLine, "^%-%-.*", commentColour ) or
  82.             tryWrite( sLine, "^\".-[^\\]\"", stringColour ) or  -- hmm we'll edit this so its gonna be modular
  83.             tryWrite( sLine, "^\'.-[^\\]\'", stringColour ) or
  84.             tryWrite( sLine, "^%[%[.-%]%]", stringColour ) or
  85.             tryWrite( sLine, "^[%w_]+", function( match )
  86.                 if tKeywords[ match ] then
  87.                     return keywordColour
  88.                 end
  89.                 return textColour
  90.             end ) or
  91.             tryWrite( sLine, "^[^%w_]", textColour )
  92.     end
  93. end
  94.  
  95. local function makeTip(x,y,w,h,input,bgColor,txtColor,lang)
  96. term.setCursorPos(x,y)
  97. term.setBackgroundColor(bgColor)
  98. term.setTextColor(txtColor)
  99. local res={}
  100. local function helper(tScan)
  101. for k,v in pairs(tScan) do
  102.  if v[1]~=true then
  103.   --k=v[res[k].reps+1]
  104.   --v=Languages[lang].Tip[k]
  105.   for k1,v1 in pairs(v) do
  106.    
  107.   end
  108.  end
  109.  if input==k then
  110.   res[#res+1]={ ico=v.ico, str=(v.str or k) }
  111.  end
  112. end
  113. end
  114. for k,v in pairs(Languages[lang].Tip) do
  115.  if v[1]~=true then
  116.   --k=v[res[k].reps+1]
  117.   --v=Languages[lang].Tip[k]
  118.   for k1,v1 in pairs(v) do
  119.    
  120.   end
  121.  end
  122.  if input==k then
  123.   res[#res+1]={ ico=v.ico, str=(v.str or k) }
  124.  end
  125. end
  126. for curr=y,h do
  127. if not res[curr-y] then break end
  128. term.setCursorPos(x,curr)
  129. term.write((res[curr-y].ico) or "")
  130. term.setCursorPos(x+3,curr)
  131. term.write((res[curr-y].str):sub(1,w-3)..string.rep(" ",w-3-(res[curr-y].str):len) or "")
  132. end
  133. end
Advertisement
Add Comment
Please, Sign In to add comment