Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --alright, let's make an editor in pure CC (like the text window/richTextBox u know )
- -- we'll at first use the CC's edit and LuaIDE source
- local fn="fn"
- local
- local Languages={
- ["Lua"]={
- Enabled=true,
- Tip={
- --Standard={ nope, lets do it all in one, dynamically, that'll be easier
- math={
- [1]=true,
- [3]={
- pow={true},
- sin={true},},
- },
- s={"string", "stringFn", "sleep",},
- st={"string", "stringFn", },
- str={"string", "stringFn", }, -- u see? lets make the permutations for all of the
- stri={"string", "stringFn", }, -- known functions and apis and reindex them on code
- strin={"string", "stringFn", },-- change. stringFn was chosen for demo
- string={
- [1]=true
- [2]={"stringFn",},
- [3]={ lower={true},
- upper={true},
- len={true}, },
- ico=api,
- str="string",
- },
- stringF={ "stringFn", },
- stringFn={true},
- sl={"sleep"},
- sle={"sleep"},
- slee={"sleep"},
- sleep={true},
- },
- --},
- Highlight={
- Keyword={
- Value={"true","false","nil"}
- Common={"local","function"}
- Loop={"for","while","do","repeat","until","end"},
- Conditional={"if","then","elseif","else"},
- Other={"in","return"}
- },
- --Function={"error","print"}, NOPE! better to store functions for the "IntelliSense" and then highlight them
- Match={
- String={ "^\".-[^\\]\"", "^\'.-[^\\]\'", "^%[%[.-%]%]" },
- Comment={ "^%-%-%[%[.-%]%]", "^%-%-.*" }
- },
- },
- },
- ["Javascript"]={Enabled=false,},
- }
- local function tryWrite( sLine, regex, colour )
- local match = string.match( sLine, regex )
- if match then
- if type(colour) == "number" then
- term.setTextColour( colour )
- else
- term.setTextColour( colour(match) )
- end
- term.write( match )
- term.setTextColour( textColour )
- return string.sub( sLine, string.len(match) + 1 )
- end
- return nil
- end
- local function writeHighlighted( sLine )
- while string.len(sLine) > 0 do
- sLine =
- tryWrite( sLine, "^%-%-%[%[.-%]%]", commentColour ) or
- tryWrite( sLine, "^%-%-.*", commentColour ) or
- tryWrite( sLine, "^\".-[^\\]\"", stringColour ) or -- hmm we'll edit this so its gonna be modular
- tryWrite( sLine, "^\'.-[^\\]\'", stringColour ) or
- tryWrite( sLine, "^%[%[.-%]%]", stringColour ) or
- tryWrite( sLine, "^[%w_]+", function( match )
- if tKeywords[ match ] then
- return keywordColour
- end
- return textColour
- end ) or
- tryWrite( sLine, "^[^%w_]", textColour )
- end
- end
- local function makeTip(x,y,w,h,input,bgColor,txtColor,lang)
- term.setCursorPos(x,y)
- term.setBackgroundColor(bgColor)
- term.setTextColor(txtColor)
- local res={}
- local function helper(tScan)
- for k,v in pairs(tScan) do
- if v[1]~=true then
- --k=v[res[k].reps+1]
- --v=Languages[lang].Tip[k]
- for k1,v1 in pairs(v) do
- end
- end
- if input==k then
- res[#res+1]={ ico=v.ico, str=(v.str or k) }
- end
- end
- end
- for k,v in pairs(Languages[lang].Tip) do
- if v[1]~=true then
- --k=v[res[k].reps+1]
- --v=Languages[lang].Tip[k]
- for k1,v1 in pairs(v) do
- end
- end
- if input==k then
- res[#res+1]={ ico=v.ico, str=(v.str or k) }
- end
- end
- for curr=y,h do
- if not res[curr-y] then break end
- term.setCursorPos(x,curr)
- term.write((res[curr-y].ico) or "")
- term.setCursorPos(x+3,curr)
- term.write((res[curr-y].str):sub(1,w-3)..string.rep(" ",w-3-(res[curr-y].str):len) or "")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment