Python1320

Python1320

Dec 12th, 2010
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.95 KB | None | 0 0
  1. if !epoe.GUI.RichText then return end
  2. local test=[[Hai! 'derp'
  3. ]]
  4.  
  5. local white=Color(255,255,255,255)
  6. local red=Color(255,0,0,255)
  7. local colors={
  8.         [":"]   = Color(0,255,0)
  9.     ,   ["["]   = Color(255,0,0)
  10.     ,   ["]"]   = Color(255,0,0)
  11.     ,   ["'"]   = Color(100,230,255)
  12.     ,   ['"']   = Color(100,230,255)
  13.     ,   ["!"]   = Color(255,0,0)
  14.     ,   ["#"]   = Color(255,100,0)
  15.     ,   ["="]   = Color(0,255,0)
  16.     ,   ["?"]   = Color(0,165,255)
  17.     ,   ["("]   = Color(0,165,255)
  18.     ,   [")"]   = Color(0,165,255)
  19.     ,   ["-"]   = Color(0,165,255)
  20.     ,   ["1"]   = Color(0,165,255)
  21.     ,   ["2"]   = Color(0,165,255)
  22.     ,   ["3"]   = Color(0,165,255)
  23.     ,   ["4"]   = Color(0,165,255)
  24.     ,   ["5"]   = Color(0,165,255)
  25.     ,   ["6"]   = Color(0,165,255)
  26.     ,   ["7"]   = Color(0,165,255)
  27.     ,   ["8"]   = Color(0,165,255)
  28.     ,   ["9"]   = Color(0,165,255)
  29.     ,   ["0"]   = Color(0,165,255)
  30.     ,
  31. }
  32. local searchme="["
  33. for k,v in pairs(colors) do
  34.     searchme=searchme..'%'..k
  35.    
  36. end
  37. searchme=searchme.."1234567890]"
  38.    
  39. print(searchme)
  40. RichTextHelp={}
  41. local cur_col=white
  42. function RichTextHelp:AppendString(str)
  43.     --PrintTable(str)
  44.     --MsgN("Append: "..tostring(str))
  45.     epoe.GUI:AppendText(str)
  46. end
  47. function RichTextHelp:InsertColorChange(color)
  48.     --if color==white then return end
  49.     --MsgN("Color:    "..(color==white and "white" or color==red and "red" or "??"))
  50.     epoe.GUI:SetColor(color.r,color.g,color.b,255)
  51. end
  52. function RichTextHelp:AppendString_Syntax(str)
  53.     str=str or test
  54.    
  55.     -- quotes highlight
  56.     local pos=str:find([['.*']])
  57.     local quoted= str:match( [['(.*)']] )
  58.     len=quoted and #quoted+2
  59.     self:InsertColorChange(white)
  60.     if pos and len then
  61.         local left=str:sub(1,pos-1)
  62.         --local quote=str:sub(pos+1,pos+len-3)
  63.         local right=str:sub(pos+len,-1)
  64.         if #left>0 then
  65.             self:AppendString_Syntax(left)
  66.         end
  67.         local quotechar=str:sub(pos,pos)
  68.         self:InsertColorChange(red)
  69.         self:AppendString(quotechar..quoted..quotechar)
  70.         --MsgN("====")
  71.         if #right>0 then
  72.             self:AppendString_Syntax(right)
  73.             return
  74.         end
  75.     end
  76.    
  77.     -- quotes highlight
  78.     local pos=str:find([[".*"]])
  79.     local quoted=str:match( [["(.*)"]] )
  80.     len=quoted and #quoted+2
  81.     self:InsertColorChange(white)
  82.     if pos and len then
  83.         local left=str:sub(1,pos-1)
  84.         --local quote=str:sub(pos+1,pos+len-3)
  85.         local right=str:sub(pos+len,-1)
  86.         if #left>0 then
  87.             self:AppendString_Syntax(left)
  88.         end
  89.         local quotechar=str:sub(pos,pos)
  90.         self:InsertColorChange(red)
  91.         self:AppendString(quotechar..quoted..quotechar)
  92.         --MsgN("====")
  93.         if #right>0 then
  94.             self:AppendString_Syntax(right)
  95.             return
  96.         end
  97.     end
  98.    
  99.     -- Normal highlight
  100.     local pos=string.find(str,searchme)
  101.     self:InsertColorChange(white)
  102.     if !pos then self:AppendString(str) return end
  103.     local left=str:sub(1,pos-1)
  104.     local char=str:sub(pos,pos)
  105.     local right=str:sub(pos+1,-1)
  106.     if #left>0 then
  107.         self:AppendString(left)
  108.     end
  109.     self:InsertColorChange(colors[char] or red)
  110.     self:AppendString(char)
  111.     --MsgN("====")
  112.     if #right>0 then
  113.         self:AppendString_Syntax(right)
  114.     end
  115. end
  116.  
  117. --print("Testing with: "..test)
  118. a=RichTextHelp
  119. a:AppendString_Syntax()
Advertisement
Add Comment
Please, Sign In to add comment