Advertisement
Alakazard12

Nova Code

Dec 31st, 2013
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 78.67 KB | None | 0 0
  1. -- Nova GUI API lightweight edition. By alakazard12
  2. -- Feel free to use this as long as you give me credit.
  3.  
  4. local LGW, LGH = term.getSize()
  5.  
  6. local VColors = {}
  7. local VClasses = {
  8.     ["TextButton"] = true;
  9.     ["TextLabel"] = true;
  10.     ["TextBox"] = true;
  11.     ["ImageButton"] = true;
  12.     ["ImageLabel"] = true;
  13. }
  14.  
  15. for _,Color in pairs(colors) do
  16.     if type(Color) == "number" then
  17.         VColors[Color] = true
  18.     end
  19. end
  20.  
  21. local function Round(Number)
  22.     return math.floor(Number + 0.5)
  23. end
  24.  
  25. local Check
  26. function Check(Object, BG, PX, PY, ChangeP)
  27.     if Object.Visible == true then
  28.         if Object.Class == "TextButton" or Object.Class == "TextBox" or Object.Class == "TextLabel" or Object.Class == "ImageButton" or Object.Class == "ImageLabel" then
  29.             -- if ChangeP ~= true then
  30.                 PX = PX + Object.Position[1] - 1
  31.                 PY = PY + Object.Position[2] - 1
  32.             -- end
  33.             if Object.ShowBackground == true then
  34.                 BG = Object.BackgroundColor
  35.             end
  36.             if Object.Class == "TextBox" and Object.Focused == true then
  37.                 BG = Object.ActiveTextColor
  38.             end
  39.             term.setBackgroundColor(BG)
  40.             for Y = 1, Object.Size[2] do
  41.                 term.setCursorPos(PX, PY + Y - 1)
  42.                 term.write(string.rep(" ", Object.Size[1]))
  43.             end
  44.  
  45.             if Object.Class == "ImageButton" or Object.Class == "ImageLabel" and Object.Image then
  46.                 paintutils.drawImage(Object.Image, PX, PY)
  47.             end
  48.  
  49.             if Object.Class == "TextButton" or Object.Class == "TextBox" or Object.Class == "TextLabel" then
  50.                 if Object.ShowText == true then
  51.                     term.setTextColor(Object.TextColor)
  52.  
  53.                     local Text = Object.Text
  54.                     if Object.TextChar then
  55.                         Text = string.rep(Object.TextChar, #Text)
  56.                     end
  57.  
  58.                     if Object.Focused == true then
  59.                         Text = Text .. " "
  60.                     end
  61.  
  62.                     if Object.MultiLine == true then
  63.                         local LastP = 1
  64.                         local LastS
  65.                         local Lines = {}
  66.                         local DidBreak = false
  67.                         local RPassed = false
  68.                         local ROnLine = false
  69.                         local ROnNum
  70.                         local RLine
  71.                         for On = 1, #Text do
  72.                             if Text:sub(On, On) == " " then
  73.                                 LastS = On
  74.                             end
  75.  
  76.                             if On - LastP + 2 > Object.Size[1] then
  77.                                 if #Lines == Object.Size[2] then
  78.                                     break
  79.                                 end
  80.  
  81.                                 if LastS then
  82.                                     table.insert(Lines, Text:sub(LastP, LastS))
  83.                                     LastP = LastS + 1
  84.                                 else
  85.                                     table.insert(Lines, Text:sub(LastP, On))
  86.                                     LastP = On + 1
  87.                                 end
  88.  
  89.                                 LastS = nil
  90.  
  91.                                 if #Lines == Object.Size[2] then
  92.                                     if Object.Focused == false then
  93.                                         DidBreak = true
  94.                                         break
  95.                                     else
  96.                                         table.remove(Lines, 1)
  97.                                     end
  98.                                 end
  99.                             end
  100.                         end
  101.  
  102.                         if DidBreak == false then
  103.                             table.insert(Lines, Text:sub(LastP))
  104.                         elseif Object.Focused == true then
  105.                             table.remove(Lines, 1)
  106.                             table.insert(Lines, Text:sub(LastP))
  107.                         end
  108.  
  109.                         local TextCount = 0
  110.  
  111.                         for _,Line in pairs(Lines) do
  112.                             local XA = 0
  113.                             local YA = 0
  114.  
  115.                             if Object.TextXAlignment == 0 then
  116.                                 XA = PX
  117.                             elseif Object.TextXAlignment == 1 then
  118.                                 XA = PX + Round((Object.Size[1] - #Line) / 2)
  119.                             else
  120.                                 XA = PX + Round(Object.Size[1] - #Line)
  121.                             end
  122.  
  123.                             if Object.TextYAlignment == 0 then
  124.                                 YA = PY + _ - 1
  125.                             elseif Object.TextYAlignment == 1 then
  126.                                 YA = PY + Round((Object.Size[2] - #Lines) / 2) + _ - 1
  127.                             else
  128.                                 YA = PY + Round(Object.Size[2] - #Lines) + _ - 1
  129.                             end
  130.  
  131.                             term.setCursorPos(XA, YA)
  132.                             term.write(Line)
  133.                         end
  134.                     else
  135.                         if #Text > Object.Size[1] then
  136.                             if Object.Focused == false then
  137.                                 Text = string.sub(Text, 1, Object.Size[1])
  138.                             -- elseif Object.RTextPos then
  139.                             -- Text = string.sub(Text, Object.RTextPos, Object.RTextPos + Object.Size[1] - 1)
  140.                             else
  141.                                 Text = string.sub(Text, #Text - Object.Size[1] + 1, #Text)
  142.                             end
  143.                         end
  144.  
  145.                         local XA = 0
  146.                         local YA = 0
  147.  
  148.                         if Object.TextXAlignment == 0 then
  149.                             XA = PX
  150.                         elseif Object.TextXAlignment == 1 then
  151.                             XA = PX + Round((Object.Size[1] - #Text) / 2)
  152.                         else
  153.                             XA = PX + Round(Object.Size[1] - #Text)
  154.                         end
  155.  
  156.                         if Object.TextYAlignment == 0 then
  157.                             YA = PY
  158.                         elseif Object.TextYAlignment == 1 then
  159.                             YA = PY + Round((Object.Size[2] - 1) / 2)
  160.                         else
  161.                             YA = PY + Round(Object.Size[2] - 1)
  162.                         end
  163.  
  164.                         term.setCursorPos(XA, YA)
  165.                         term.write(Text)
  166.                     end
  167.                     -- if Object.RTextPos == nil then
  168.                         Object.TextPos = {term.getCursorPos()}
  169.                         Object.TextPos[1] = Object.TextPos[1] - 1
  170.                     -- end
  171.                 end
  172.             end
  173.  
  174.             for _,Obj in pairs(Object.Children) do
  175.                 Check(Obj, BG, PX, PY)
  176.             end
  177.         end
  178.     end
  179. end
  180.  
  181. local function SortListen(Tbl)
  182.     local Clone = {}
  183.     for _,Item in pairs(Tbl) do
  184.         Clone[_] = Item
  185.     end
  186.     table.sort(Clone, function(A, B)
  187.         return A.ZIndex > B.ZIndex
  188.     end)
  189.     return Clone
  190. end
  191.  
  192. local function NewClass(Par, Class, Main)
  193.     if type(Class) ~= "string" then
  194.         error("bad argument #1: string expected, got " .. type(Class), 2)
  195.     end
  196.     if not VClasses[Class] then
  197.         error("Invalid class name.", 2)
  198.     end
  199.  
  200.     local PublicTable = {}
  201.     local LocalTable = {}
  202.  
  203.     LocalTable.Parent = Par
  204.     LocalTable.Class = Class
  205.  
  206.     function PublicTable:ClearChildren()
  207.         LocalTable.Children = {}
  208.     end
  209.  
  210.     if Class == "ImageButton" or Class == "ImageLabel" then
  211.         LocalTable.Size = {2, 2}
  212.         LocalTable.Position = {1, 1}
  213.         LocalTable.Visible = true
  214.         LocalTable.Active = true
  215.         LocalTable.Children = {}
  216.         LocalTable.ZIndex = 0
  217.         LocalTable.ShowBackground = true
  218.  
  219.         function PublicTable:Size(X, Y)
  220.             if type(X) ~= "number" then
  221.                 error("bad argument #1: number expected, got " .. type(X), 2)
  222.             end
  223.             if type(Y) ~= "number" then
  224.                 error("bad argument #2: number expected, got " .. type(Y), 2)
  225.             end
  226.  
  227.             LocalTable.Size = {X, Y}
  228.         end
  229.  
  230.         function PublicTable:Image(Image)
  231.             if type(Image) ~= "table" then
  232.                 error("bad argument #1: table expected, got " .. type(Image), 2)
  233.             end
  234.  
  235.             LocalTable.Image = Image
  236.         end
  237.  
  238.         function PublicTable:GetSize()
  239.             return unpack(LocalTable.Size)
  240.         end
  241.  
  242.         function PublicTable:ShowBackground(Bool)
  243.             if type(Bool) ~= "boolean" then
  244.                 error("bad argument #1: boolean expected, got " .. type(Bool), 2)
  245.             end
  246.             LocalTable.ShowBackground = Bool
  247.         end
  248.  
  249.         function PublicTable:GetShowBackground()
  250.             return LocalTable.ShowBackground
  251.         end
  252.  
  253.         function PublicTable:ZIndex(Number)
  254.             if type(Number) ~= "number" then
  255.                 error("bad argument #1: number expected, got " .. type(Number), 2)
  256.             end
  257.             LocalTable.ZIndex = Number
  258.             table.sort(Par.Children, function(A, B)
  259.                 return A.ZIndex < B.ZIndex
  260.             end)
  261.         end
  262.  
  263.         function PublicTable:GetZIndex()
  264.             return LocalTable.ZIndex
  265.         end
  266.  
  267.         function PublicTable:Position(X, Y)
  268.             if type(X) ~= "number" then
  269.                 error("bad argument #1: number expected, got " .. type(X), 2)
  270.             end
  271.             if type(Y) ~= "number" then
  272.                 error("bad argument #2: number expected, got " .. type(Y), 2)
  273.             end
  274.             LocalTable.Position = {X, Y}
  275.         end
  276.  
  277.         function PublicTable:GetPosition()
  278.             return unpack(LocalTable.Position)
  279.         end
  280.  
  281.         function PublicTable:Visible(Bool)
  282.             if type(Bool) ~= "boolean" then
  283.                 error("bad argument #1: boolean expected, got " .. type(Bool), 2)
  284.             end
  285.             LocalTable.Visible = Bool
  286.         end
  287.  
  288.         function PublicTable:GetVisible()
  289.             return LocalTable.Visible
  290.         end
  291.  
  292.         function PublicTable:Active(Bool)
  293.             if type(Bool) ~= "boolean" then
  294.                 error("bad argument #1: boolean expected, got " .. type(Bool), 2)
  295.             end
  296.             LocalTable.Active = Bool
  297.         end
  298.  
  299.         function PublicTable:GetActive()
  300.             return LocalTable.Active
  301.         end
  302.  
  303.         function PublicTable:BackgroundColor(Color)
  304.             if type(Color) ~= "number" then
  305.                 error("bad argument #1: number expected, got " .. type(Color), 2)
  306.             end
  307.             if VColors[Color] ~= true then
  308.                 error("Invalid color.", 2)
  309.             end
  310.             LocalTable.BackgroundColor = Color
  311.         end
  312.  
  313.         function PublicTable:GetBackgroundColor()
  314.             return LocalTable.BackgroundColor
  315.         end
  316.  
  317.         if Class == "ImageButton" then
  318.             function PublicTable:Button1Click(Function)
  319.                 if Function == nil then
  320.                     LocalTable.Button1Click = nil
  321.                 else
  322.                     if type(Function) ~= "function" then
  323.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  324.                     end
  325.                     LocalTable.Button1Click = Function
  326.                 end
  327.             end
  328.  
  329.             function PublicTable:GetButton1Click()
  330.                 return LocalTable.Button1Click
  331.             end
  332.  
  333.             function PublicTable:MouseScroll(Function)
  334.                 if Function == nil then
  335.                     LocalTable.MouseScroll = nil
  336.                 else
  337.                     if type(Function) ~= "function" then
  338.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  339.                     end
  340.                     LocalTable.MouseScroll = Function
  341.                 end
  342.             end
  343.  
  344.             function PublicTable:GetMouseScroll()
  345.                 return LocalTable.MouseScroll
  346.             end
  347.  
  348.             function PublicTable:MouseDrag1(Function)
  349.                 if Function == nil then
  350.                     LocalTable.MouseDrag1 = nil
  351.                 else
  352.                     if type(Function) ~= "function" then
  353.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  354.                     end
  355.                     LocalTable.MouseDrag1 = Function
  356.                 end
  357.             end
  358.  
  359.             function PublicTable:GetMouseDrag1()
  360.                 return LocalTable.MouseDrag1
  361.             end
  362.  
  363.             function PublicTable:MouseDrag2(Function)
  364.                 if Function == nil then
  365.                     LocalTable.MouseDrag2 = nil
  366.                 else
  367.                     if type(Function) ~= "function" then
  368.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  369.                     end
  370.                     LocalTable.MouseDrag2 = Function
  371.                 end
  372.             end
  373.  
  374.             function PublicTable:GetMouseDrag2()
  375.                 return LocalTable.MouseDrag2
  376.             end
  377.  
  378.             function PublicTable:MouseDrag3(Function)
  379.                 if Function == nil then
  380.                     LocalTable.MouseDrag3 = nil
  381.                 else
  382.                     if type(Function) ~= "function" then
  383.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  384.                     end
  385.                     LocalTable.MouseDrag3 = Function
  386.                 end
  387.             end
  388.  
  389.             function PublicTable:GetMouseDrag3()
  390.                 return LocalTable.MouseDrag3
  391.             end
  392.  
  393.             function PublicTable:Button2Click(Function)
  394.                 if Function == nil then
  395.                     LocalTable.Button2Click = nil
  396.                 else
  397.                     if type(Function) ~= "function" then
  398.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  399.                     end
  400.                     LocalTable.Button2Click = Function
  401.                 end
  402.             end
  403.  
  404.             function PublicTable:GetButton2Click()
  405.                 return LocalTable.Button2Click
  406.             end
  407.  
  408.             function PublicTable:Button3Click(Function)
  409.                 if Function == nil then
  410.                     LocalTable.Button3Click = nil
  411.                 else
  412.                     if type(Function) ~= "function" then
  413.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  414.                     end
  415.                     LocalTable.Button3Click = Function
  416.                 end
  417.             end
  418.  
  419.             function PublicTable:GetButton3Click()
  420.                 return LocalTable.Button3Click
  421.             end
  422.         end
  423.  
  424.         function PublicTable:New(Class)
  425.             return NewClass(LocalTable, Class, Main)
  426.         end
  427.  
  428.         function PublicTable:Draw()
  429.             local BG = Main.BackgroundColor
  430.             local FoundBG = false
  431.             local PX, PY = 1, 1
  432.  
  433.             local On = LocalTable.Parent
  434.             while On ~= Main do
  435.                 PX = PX + On.Position[1] - 1
  436.                 PY = PY + On.Position[2] - 1
  437.  
  438.                 if On.ShowBackground and FoundBG == false then
  439.                     BG = On.BackgroundColor
  440.                     FoundBG = true
  441.                 end
  442.                 On = On.Parent
  443.             end
  444.  
  445.             Check(LocalTable, BG, PX, PY)
  446.         end
  447.     elseif Class == "TextButton" or Class == "TextLabel" or Class == "TextBox" then
  448.         LocalTable.Size = {2, 2}
  449.         LocalTable.Position = {1, 1}
  450.         LocalTable.RawText = ""
  451.         LocalTable.Text = ""
  452.         LocalTable.BackgroundColor = colors.cyan
  453.         LocalTable.TextColor = colors.white
  454.         LocalTable.Visible = true
  455.         LocalTable.Active = true
  456.         LocalTable.Children = {}
  457.         LocalTable.ZIndex = 0
  458.         LocalTable.ShowBackground = true
  459.         LocalTable.ShowText = true
  460.         LocalTable.TextXAlignment = 1
  461.         LocalTable.TextYAlignment = 1
  462.         LocalTable.MultiLine = false
  463.  
  464.         if Class == "TextBox" then
  465.             LocalTable.ActiveTextColor = colors.blue
  466.             LocalTable.Overlap = false
  467.             LocalTable.Focused = false
  468.             LocalTable.ClearTextOnFocus = false
  469.             LocalTable.RTextPos = 8
  470.         end
  471.  
  472.         function PublicTable:TextXAlignment(Num)
  473.             if type(Num) == "string" then
  474.                 if Num:lower() == "left" then
  475.                     Num = 0
  476.                 elseif Num:lower() == "center" then
  477.                     Num = 1
  478.                 elseif Num:lower() == "right" then
  479.                     Num = 2
  480.                 else
  481.                     error("bad argument #1: '" .. Num .. "' is not a valid string", 2)
  482.                 end
  483.             end
  484.  
  485.             if type(Num) ~= "number" then
  486.                 error("bad argument #1: number expected, got " .. type(X), 2)
  487.             end
  488.             LocalTable.TextXAlignment = Num
  489.         end
  490.  
  491.         function PublicTable:GetTextXAlignment()
  492.             return LocalTable.TextXAlignment
  493.         end
  494.  
  495.         function PublicTable:TextYAlignment(Num)
  496.             if type(Num) == "string" then
  497.                 if Num:lower() == "top" then
  498.                     Num = 0
  499.                 elseif Num:lower() == "center" then
  500.                     Num = 1
  501.                 elseif Num:lower() == "bottom" then
  502.                     Num = 2
  503.                 else
  504.                     error("bad argument #1: '" .. Num .. "' is not a valid string", 2)
  505.                 end
  506.             end
  507.  
  508.             if type(Num) ~= "number" then
  509.                 error("bad argument #1: number expected, got " .. type(X), 2)
  510.             end
  511.             LocalTable.TextYAlignment = Num
  512.         end
  513.  
  514.         function PublicTable:GetTextYAlignment()
  515.             return LocalTable.TextYAlignment
  516.         end
  517.  
  518.         function PublicTable:Size(X, Y)
  519.             if type(X) ~= "number" then
  520.                 error("bad argument #1: number expected, got " .. type(X), 2)
  521.             end
  522.             if type(Y) ~= "number" then
  523.                 error("bad argument #2: number expected, got " .. type(Y), 2)
  524.             end
  525.  
  526.             LocalTable.Size = {X, Y}
  527.         end
  528.  
  529.         function PublicTable:GetSize()
  530.             return unpack(LocalTable.Size)
  531.         end
  532.  
  533.         function PublicTable:ShowBackground(Bool)
  534.             if type(Bool) ~= "boolean" then
  535.                 error("bad argument #1: boolean expected, got " .. type(Bool), 2)
  536.             end
  537.             LocalTable.ShowBackground = Bool
  538.         end
  539.  
  540.         function PublicTable:GetShowBackground()
  541.             return LocalTable.ShowBackground
  542.         end
  543.  
  544.         function PublicTable:ShowText(Bool)
  545.             if type(Bool) ~= "boolean" then
  546.                 error("bad argument #1: boolean expected, got " .. type(Bool), 2)
  547.             end
  548.             LocalTable.ShowText = Bool
  549.         end
  550.  
  551.         function PublicTable:GetShowText()
  552.             return LocalTable.ShowText
  553.         end
  554.  
  555.         function PublicTable:MultiLine(Bool)
  556.             if type(Bool) ~= "boolean" then
  557.                 error("bad argument #1: boolean expected, got " .. type(Bool), 2)
  558.             end
  559.             LocalTable.MultiLine = Bool
  560.         end
  561.  
  562.         function PublicTable:GetMultiLine()
  563.             return LocalTable.MultiLine
  564.         end
  565.  
  566.         function PublicTable:ZIndex(Number)
  567.             if type(Number) ~= "number" then
  568.                 error("bad argument #1: number expected, got " .. type(Number), 2)
  569.             end
  570.             LocalTable.ZIndex = Number
  571.             table.sort(Par.Children, function(A, B)
  572.                 return A.ZIndex < B.ZIndex
  573.             end)
  574.         end
  575.  
  576.         function PublicTable:GetZIndex()
  577.             return LocalTable.ZIndex
  578.         end
  579.  
  580.         function PublicTable:Position(X, Y)
  581.             if type(X) ~= "number" then
  582.                 error("bad argument #1: number expected, got " .. type(X), 2)
  583.             end
  584.             if type(Y) ~= "number" then
  585.                 error("bad argument #2: number expected, got " .. type(Y), 2)
  586.             end
  587.             LocalTable.Position = {X, Y}
  588.         end
  589.  
  590.         function PublicTable:GetPosition()
  591.             return unpack(LocalTable.Position)
  592.         end
  593.  
  594.         function PublicTable:Visible(Bool)
  595.             if type(Bool) ~= "boolean" then
  596.                 error("bad argument #1: boolean expected, got " .. type(Bool), 2)
  597.             end
  598.             LocalTable.Visible = Bool
  599.         end
  600.  
  601.         function PublicTable:GetVisible()
  602.             return LocalTable.Visible
  603.         end
  604.  
  605.         function PublicTable:Active(Bool)
  606.             if type(Bool) ~= "boolean" then
  607.                 error("bad argument #1: boolean expected, got " .. type(Bool), 2)
  608.             end
  609.             LocalTable.Active = Bool
  610.         end
  611.  
  612.         function PublicTable:GetActive()
  613.             return LocalTable.Active
  614.         end
  615.  
  616.         function PublicTable:Text(Text)
  617.             if Text == nil then
  618.                 Text = ""
  619.             end
  620.             if type(Text) ~= "string" then
  621.                 error("bad argument #1: string expected, got " .. type(Text), 2)
  622.             end
  623.             LocalTable.Text = Text
  624.         end
  625.  
  626.         function PublicTable:GetText()
  627.             return LocalTable.Text
  628.         end
  629.  
  630.         function PublicTable:BackgroundColor(Color)
  631.             if type(Color) ~= "number" then
  632.                 error("bad argument #1: number expected, got " .. type(Color), 2)
  633.             end
  634.             if VColors[Color] ~= true then
  635.                 error("Invalid color.", 2)
  636.             end
  637.             LocalTable.BackgroundColor = Color
  638.         end
  639.  
  640.         function PublicTable:GetBackgroundColor()
  641.             return LocalTable.BackgroundColor
  642.         end
  643.  
  644.         function PublicTable:TextColor(Color)
  645.             if type(Color) ~= "number" then
  646.                 error("bad argument #1: number expected, got " .. type(Color), 2)
  647.             end
  648.             if VColors[Color] ~= true then
  649.                 error("Invalid color.", 2)
  650.             end
  651.             LocalTable.TextColor = Color
  652.         end
  653.  
  654.         function PublicTable:GetTextColor()
  655.             return LocalTable.TextColor
  656.         end
  657.  
  658.         function PublicTable:MouseScroll(Function)
  659.                 if Function == nil then
  660.                     LocalTable.MouseScroll = nil
  661.                 else
  662.                 if type(Function) ~= "function" then
  663.                     error("bad argument #1: function expected, got " .. type(Function), 2)
  664.                 end
  665.                 LocalTable.MouseScroll = Function
  666.             end
  667.         end
  668.  
  669.         if Class == "TextButton" then
  670.             function PublicTable:Button1Click(Function)
  671.                 if Function == nil then
  672.                     LocalTable.Button1Click = nil
  673.                 else
  674.                     if type(Function) ~= "function" then
  675.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  676.                     end
  677.                     LocalTable.Button1Click = Function
  678.                 end
  679.             end
  680.  
  681.             function PublicTable:GetButton1Click()
  682.                 return LocalTable.Button1Click
  683.             end
  684.  
  685.             function PublicTable:GetMouseScroll()
  686.                 return LocalTable.MouseScroll
  687.             end
  688.  
  689.             function PublicTable:MouseDrag1(Function)
  690.                 if Function == nil then
  691.                     LocalTable.MouseDrag1 = nil
  692.                 else
  693.                     if type(Function) ~= "function" then
  694.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  695.                     end
  696.                     LocalTable.MouseDrag1 = Function
  697.                 end
  698.             end
  699.  
  700.             function PublicTable:GetMouseDrag1()
  701.                 return LocalTable.MouseDrag1
  702.             end
  703.  
  704.             function PublicTable:MouseDrag2(Function)
  705.                 if Function == nil then
  706.                     LocalTable.MouseDrag2 = nil
  707.                 else
  708.                     if type(Function) ~= "function" then
  709.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  710.                     end
  711.                     LocalTable.MouseDrag2 = Function
  712.                 end
  713.             end
  714.  
  715.             function PublicTable:GetMouseDrag2()
  716.                 return LocalTable.MouseDrag2
  717.             end
  718.  
  719.             function PublicTable:MouseDrag3(Function)
  720.                 if Function == nil then
  721.                     LocalTable.MouseDrag3 = nil
  722.                 else
  723.                     if type(Function) ~= "function" then
  724.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  725.                     end
  726.                     LocalTable.MouseDrag3 = Function
  727.                 end
  728.             end
  729.  
  730.             function PublicTable:GetMouseDrag3()
  731.                 return LocalTable.MouseDrag3
  732.             end
  733.  
  734.             function PublicTable:Button2Click(Function)
  735.                 if Function == nil then
  736.                     LocalTable.Button2Click = nil
  737.                 else
  738.                     if type(Function) ~= "function" then
  739.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  740.                     end
  741.                     LocalTable.Button2Click = Function
  742.                 end
  743.             end
  744.  
  745.             function PublicTable:GetButton2Click()
  746.                 return LocalTable.Button2Click
  747.             end
  748.  
  749.             function PublicTable:Button3Click(Function)
  750.                 if Function == nil then
  751.                     LocalTable.Button3Click = nil
  752.                 else
  753.                     if type(Function) ~= "function" then
  754.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  755.                     end
  756.                     LocalTable.Button3Click = Function
  757.                 end
  758.             end
  759.  
  760.             function PublicTable:GetButton3Click()
  761.                 return LocalTable.Button3Click
  762.             end
  763.         elseif Class == "TextBox" then
  764.             function PublicTable:ActiveTextColor(Color)
  765.                 if type(Color) ~= "number" then
  766.                     error("bad argument #1: number expected, got " .. type(Color), 2)
  767.                 end
  768.                 if VColors[Color] ~= true then
  769.                     error("Invalid color.", 2)
  770.                 end
  771.                 LocalTable.ActiveTextColor = Color
  772.             end
  773.  
  774.             function PublicTable:EnterPress(Function)
  775.                 if Function == nil then
  776.                     LocalTable.EnterPress = nil
  777.                 else
  778.                     if type(Function) ~= "function" then
  779.                         error("bad argument #1: function expected, got " .. type(Function), 2)
  780.                     end
  781.                     LocalTable.EnterPress = Function
  782.                 end
  783.             end
  784.  
  785.             function PublicTable:GetEnterPress()
  786.                 return LocalTable.EnterPress
  787.             end
  788.  
  789.             function PublicTable:Overlap(Bool)
  790.                 if type(Bool) ~= "boolean" then
  791.                     error("bad argument #1: boolean expected, got " .. type(Bool), 2)
  792.                 end
  793.                 LocalTable.Overlap = Bool
  794.             end
  795.  
  796.             function PublicTable:GetOverlap()
  797.                 return LocalTable.Overlap
  798.             end
  799.  
  800.             function PublicTable:ClearTextOnFocus(Bool)
  801.                 if type(Bool) ~= "boolean" then
  802.                     error("bad argument #1: boolean expected, got " .. type(Bool), 2)
  803.                 end
  804.                 LocalTable.ClearTextOnFocus = Bool
  805.             end
  806.  
  807.             function PublicTable:GetClearTextOnFocus()
  808.                 return LocalTable.ClearTextOnFocus
  809.             end
  810.  
  811.             function PublicTable:Focus()
  812.                 Main.MakeFocus = LocalTable
  813.                 os.queueEvent("")
  814.             end
  815.  
  816.             function PublicTable:StopFocus()
  817.                 Main.StopFocus = true
  818.                 os.queueEvent("")
  819.             end
  820.  
  821.             function PublicTable:TextChar(Char)
  822.                 if Char == nil then
  823.                     LocalTable.TextChar = nil
  824.                 else
  825.                     if type(Char) ~= "string" then
  826.                         error("bad argument #1: string expected, got " .. type(Char), 2)
  827.                     end
  828.                     LocalTable.TextChar = Char
  829.                 end
  830.             end
  831.  
  832.             function PublicTable:GetTextChar()
  833.                 return LocalTable.TextChar
  834.             end
  835.         end
  836.  
  837.         function PublicTable:New(Class)
  838.             return NewClass(LocalTable, Class, Main)
  839.         end
  840.  
  841.         function PublicTable:Draw()
  842.             local BG = Main.BackgroundColor
  843.             local FoundBG = false
  844.             local PX, PY = 1, 1
  845.  
  846.             local On = LocalTable.Parent
  847.             while On ~= Main do
  848.                 PX = PX + On.Position[1] - 1
  849.                 PY = PY + On.Position[2] - 1
  850.  
  851.                 if On.ShowBackground and FoundBG == false then
  852.                     BG = On.BackgroundColor
  853.                     FoundBG = true
  854.                 end
  855.                 On = On.Parent
  856.             end
  857.  
  858.             Check(LocalTable, BG, PX, PY , true)
  859.         end
  860.     end
  861.  
  862.     LocalTable.Pub = PublicTable
  863.  
  864.     table.insert(Par.Children, LocalTable)
  865.  
  866.     function PublicTable:Destroy()
  867.         for _,Object in pairs(Par.Children) do
  868.             if LocalTable == Object then
  869.                 table.remove(Par.Children, _)
  870.                 break
  871.             end
  872.         end
  873.         LocalTable = nil
  874.         PublicTable = nil
  875.     end
  876.  
  877.     return PublicTable
  878. end
  879.  
  880. local function NewUI()
  881.     local LocalTable = {}
  882.     local PublicTable = {}
  883.  
  884.     LocalTable.BackgroundColor = colors.red
  885.     LocalTable.Visible = true
  886.     LocalTable.Active = true
  887.     LocalTable.Children = {}
  888.     LocalTable.Listening = false
  889.  
  890.     function PublicTable:BackgroundColor(Color)
  891.         if type(Color) ~= "number" then
  892.             error("bad argument #1: number expected, got " .. type(Color), 2)
  893.         end
  894.         if not VColors[Color] then
  895.             error("Invalid color.", 2)
  896.         end
  897.         LocalTable.BackgroundColor = Color
  898.     end
  899.  
  900.     function PublicTable:New(Class)
  901.         return NewClass(LocalTable, Class, LocalTable)
  902.     end
  903.  
  904.     function PublicTable:ClearChildren()
  905.         LocalTable.Children = {}
  906.     end
  907.  
  908.     function PublicTable:ErrorHandle(Function)
  909.         if type(Function) ~= "function" and Function ~= nil then
  910.             error("bad argument #1: function expected, got " .. type(Function), 2)
  911.         end
  912.  
  913.         LocalTable.ErrorHandle = Function
  914.     end
  915.  
  916.     function PublicTable:Output(Function)
  917.         if type(Function) ~= "function" and Function ~= nil then
  918.             error("bad argument #1: function expected, got " .. type(Function), 2)
  919.         end
  920.  
  921.         LocalTable.Output = Function
  922.     end
  923.  
  924.     function PublicTable:Listen()
  925.         LocalTable.Listening = true
  926.         local ActiveBox
  927.         local LastClick1
  928.         local LastClick2
  929.         local LastClick3
  930.  
  931.         while LocalTable.Listening == true do
  932.             local Event, P1, P2, P3, P4, P5 = os.pullEvent()
  933.             if LocalTable.Listening == false then
  934.                 break
  935.             end
  936.  
  937.             if LocalTable.MakeFocus then
  938.                 if ActiveBox then
  939.                     ActiveBox.Focused = false
  940.                     ActiveBox.StopFocus = nil
  941.                     term.setCursorBlink(false)
  942.                     if ActiveBox.Overlap == true then
  943.                         ActiveBox.Pub:Draw()
  944.                     else
  945.                         PublicTable:Draw()
  946.                     end
  947.                 end
  948.                 ActiveBox = LocalTable.MakeFocus
  949.                 LocalTable.MakeFocus = nil
  950.                 ActiveBox.Focused = true
  951.                 if ActiveBox.Overlap == true then
  952.                     ActiveBox.Pub:Draw()
  953.                 else
  954.                     PublicTable:Draw()
  955.                 end
  956.  
  957.                 term.setCursorBlink(true)
  958.                 term.setTextColor(ActiveBox.TextColor)
  959.                 term.setCursorPos(unpack(ActiveBox.TextPos))
  960.             end
  961.  
  962.             if ActiveBox and ActiveBox.StopFocus then
  963.                 ActiveBox.Focused = false
  964.                 ActiveBox.StopFocus = nil
  965.                 term.setCursorBlink(false)
  966.                 if ActiveBox.Overlap == true then
  967.                     ActiveBox.Pub:Draw()
  968.                 else
  969.                     PublicTable:Draw()
  970.                 end
  971.                 if ActiveBox.EnterPress then
  972.                     ActiveBox.EnterPress()
  973.                 end
  974.                 ActiveBox = nil
  975.             end
  976.  
  977.             if LocalTable.Output then
  978.                 if LocalTable.ErrorHandle then
  979.                     local Success, Err = pcall(LocalTable.Output, Event, P1, P2, P3, P4, P5)
  980.                     if not Success then
  981.                         LocalTable.ErrorHandle(Err)
  982.                     end
  983.                 else
  984.                     LocalTable.Output(Event, P1, P2, P3, P4, P5)
  985.                 end
  986.             end
  987.  
  988.             if Event == "char" then
  989.                 if ActiveBox then
  990.                     ActiveBox.Text = ActiveBox.Text .. P1
  991.                     if ActiveBox.Overlap == true then
  992.                         ActiveBox.Pub:Draw()
  993.                     else
  994.                         PublicTable:Draw()
  995.                     end
  996.                     term.setTextColor(ActiveBox.TextColor)
  997.  
  998.                     term.setCursorPos(unpack(ActiveBox.TextPos))
  999.                 end
  1000.             elseif Event == "key" then
  1001.                 if ActiveBox then
  1002.                     if P1 == 14 then
  1003.                         if #ActiveBox.Text > 0 then
  1004.                             ActiveBox.Text = string.sub(ActiveBox.Text, 1, #ActiveBox.Text - 1)
  1005.                             if ActiveBox.Overlap == true then
  1006.                                 ActiveBox.Pub:Draw()
  1007.                             else
  1008.                                 PublicTable:Draw()
  1009.                             end
  1010.                             term.setTextColor(ActiveBox.TextColor)
  1011.  
  1012.                             term.setCursorPos(unpack(ActiveBox.TextPos))
  1013.                         end
  1014.                     elseif P1 == 28 then
  1015.                         ActiveBox.Focused = false
  1016.                         term.setCursorBlink(false)
  1017.  
  1018.                         if ActiveBox.Overlap == true then
  1019.                             ActiveBox.Pub:Draw()
  1020.                         else
  1021.                             PublicTable:Draw()
  1022.                         end
  1023.  
  1024.                         if ActiveBox.EnterPress then
  1025.                             if LocalTable.ErrorHandle then
  1026.                                 local Success, Err = pcall(ActiveBox.EnterPress)
  1027.                                 if not Success then
  1028.                                     LocalTable.ErrorHandle(Err)
  1029.                                 end
  1030.                             else
  1031.                                 ActiveBox.EnterPress()
  1032.                             end
  1033.                         end
  1034.                         ActiveBox = nil
  1035.                     end
  1036.                 end
  1037.             elseif Event == "mouse_scroll" then
  1038.                 local PStop = false
  1039.                 local Check
  1040.                 function Check(Object, Par, PX, PY)
  1041.                     if Object.Active == true then
  1042.                         if PStop == true then return end
  1043.                         if Object.Class == "TextLabel" or Object.Class == "TextButton" or Object.Class == "ImageButton" then
  1044.                             if P2 >= Object.Position[1] + PX - 1 and P2 <= Object.Position[1] + Object.Size[1] + PX - 2 and P3 >= Object.Position[2] + PY - 1 and P3 <= Object.Position[2] + Object.Size[2] + PY - 2 then
  1045.                                 if Object.MouseScroll then
  1046.                                     if LocalTable.ErrorHandle then
  1047.                                         local Success, Err = pcall(Object.MouseScroll, P1)
  1048.                                         if not Success then
  1049.                                             LocalTable.ErrorHandle(Err)
  1050.                                         end
  1051.                                     else
  1052.                                         Object.MouseScroll(P1)
  1053.                                     end
  1054.                                     PStop = true
  1055.                                 end
  1056.                             end
  1057.                         end
  1058.  
  1059.                         for _,Object in pairs(SortListen(Object.Children)) do
  1060.                             Check(Object, Object, PX + Object.Position[1] - 1, PY + Object.Position[2] - 1)
  1061.                         end
  1062.                     end
  1063.                 end
  1064.  
  1065.                 for _,Object in pairs(SortListen(LocalTable.Children))  do
  1066.                     Check(Object, LocalTable, 1, 1)
  1067.                 end
  1068.             elseif Event == "mouse_drag" then
  1069.                 if P1 == 1 and LastClick1 then
  1070.                     if LastClick1.MouseDrag1 then
  1071.                         if LocalTable.ErrorHandle then
  1072.                             local Success, Err = pcall(LastClick1.MouseDrag1, P2, P3)
  1073.                             if not Success then
  1074.                                 LocalTable.ErrorHandle(Err)
  1075.                             end
  1076.                         else
  1077.                             LastClick1.MouseDrag1(P2, P3)
  1078.                         end
  1079.                     end
  1080.                 elseif P1 == 2 and LastClick2 then
  1081.                     if LastClick2.MouseDrag2 then
  1082.                         if LocalTable.ErrorHandle then
  1083.                             local Success, Err = pcall(Object.MouseDrag2, P2, P3)
  1084.                             if not Success then
  1085.                                 LocalTable.ErrorHandle(Err)
  1086.                             end
  1087.                         else
  1088.                             Object.MouseDrag2(P2, P3)
  1089.                         end
  1090.                     end
  1091.                 elseif P1 == 3 and LastClick3 then
  1092.                     if LastClick3.MouseDrag3 then
  1093.                         if LocalTable.ErrorHandle then
  1094.                             local Success, Err = pcall(Object.MouseDrag3, P2, P3)
  1095.                             if not Success then
  1096.                                 LocalTable.ErrorHandle(Err)
  1097.                             end
  1098.                         else
  1099.                             Object.MouseDrag3(P2, P3)
  1100.                         end
  1101.                     end
  1102.                 end
  1103.             elseif Event == "mouse_click" then
  1104.                 LastClick1 = nil
  1105.                 LastClick2 = nil
  1106.                 LastClick3 = nil
  1107.                 local PStop = false
  1108.                 local StopFocus = true
  1109.                 local Check
  1110.                 function Check(Object, Par, PX, PY)
  1111.                     if Object.Active == true then
  1112.                         if PStop == true then return end
  1113.                         if Object.Class == "TextButton" or Object.Class == "ImageButton" or Object.Class == "TextBox" then
  1114.                             if P2 >= Object.Position[1] + PX - 1 and P2 <= Object.Position[1] + Object.Size[1] + PX - 2 and P3 >= Object.Position[2] + PY - 1 and P3 <= Object.Position[2] + Object.Size[2] + PY - 2 then
  1115.                                 if ActiveBox and Object ~= ActiveBox then
  1116.                                     ActiveBox.Focused = false
  1117.                                     ActiveBox.StopFocus = nil
  1118.                                     term.setCursorBlink(false)
  1119.                                     if ActiveBox.Overlap == true then
  1120.                                         ActiveBox.Pub:Draw()
  1121.                                     else
  1122.                                         PublicTable:Draw()
  1123.                                     end
  1124.  
  1125.                                     if ActiveBox.EnterPress then
  1126.                                         if LocalTable.ErrorHandle then
  1127.                                             local Success, Err = pcall(ActiveBox.EnterPress)
  1128.                                             if not Success then
  1129.                                                 LocalTable.ErrorHandle(Err)
  1130.                                             end
  1131.                                         else
  1132.                                             ActiveBox.EnterPress()
  1133.                                         end
  1134.                                     end
  1135.                                     ActiveBox = nil
  1136.                                 end
  1137.                                 if P1 == 1 then
  1138.                                     LastClick1 = Object
  1139.                                     if (Object.Class == "TextButton" or Object.Class == "ImageButton") and Object.Button1Click then
  1140.                                         if LocalTable.ErrorHandle then
  1141.                                             local Success, Err = pcall(Object.Button1Click, P2, P3)
  1142.                                             if not Success then
  1143.                                                 LocalTable.ErrorHandle(Err)
  1144.                                             end
  1145.                                         else
  1146.                                             Object.Button1Click(P2, P3)
  1147.                                         end
  1148.                                     elseif Object.Class == "TextBox" then
  1149.                                         ActiveBox = Object
  1150.                                         Object.Focused = true
  1151.  
  1152.                                         if Object.ClearTextOnFocus == true then
  1153.                                             Object.Text = ""
  1154.                                         end
  1155.  
  1156.                                         Object.RawText = ""
  1157.                                         Object.RTextPos = 6
  1158.  
  1159.                                         if Object.Overlap == true then
  1160.                                             Object.Pub:Draw()
  1161.                                         else
  1162.                                             PublicTable:Draw()
  1163.                                         end
  1164.                                         term.setCursorBlink(true)
  1165.                                         term.setTextColor(ActiveBox.TextColor)
  1166.                                         term.setCursorPos(unpack(Object.TextPos))
  1167.                                     end
  1168.                                 elseif P1 == 2 then
  1169.                                     LastClick2 = Object
  1170.                                     if (Object.Class == "TextButton" or Object.Class == "ImageButton") and Object.Button2Click then
  1171.                                         if LocalTable.ErrorHandle then
  1172.                                             local Success, Err = pcall(Object.Button2Click, P2, P3)
  1173.                                             if not Success then
  1174.                                                 LocalTable.ErrorHandle(Err)
  1175.                                             end
  1176.                                         else
  1177.                                             Object.Button2Click(P2, P3)
  1178.                                         end
  1179.                                     end
  1180.                                 elseif P1 == 3 then
  1181.                                     LastClick3 = Object
  1182.                                     if (Object.Class == "TextButton" or Object.Class == "ImageButton") and Object.Button3Click then
  1183.                                         if LocalTable.ErrorHandle then
  1184.                                             local Success, Err = pcall(Object.Button3Click, P2, P3)
  1185.                                             if not Success then
  1186.                                                 LocalTable.ErrorHandle(Err)
  1187.                                             end
  1188.                                         else
  1189.                                             Object.Button3Click(P2, P3)
  1190.                                         end
  1191.                                     end
  1192.                                 end
  1193.  
  1194.                                 PStop = true
  1195.                             end
  1196.                         end
  1197.  
  1198.                         for _,Object2 in pairs(SortListen(Object.Children)) do
  1199.                             Check(Object2, Object, PX + Object.Position[1] - 1, PY + Object.Position[2] - 1)
  1200.                         end
  1201.                     end
  1202.                 end
  1203.  
  1204.                 for _,Object in pairs(SortListen(LocalTable.Children))  do
  1205.                     Check(Object, LocalTable, 1, 1)
  1206.                 end
  1207.             end
  1208.         end
  1209.     end
  1210.  
  1211.     function PublicTable:StopListen()
  1212.         LocalTable.Listening = false
  1213.     end
  1214.  
  1215.     function PublicTable:Draw()
  1216.         term.setBackgroundColor(LocalTable.BackgroundColor)
  1217.         term.clear()
  1218.  
  1219.         for _,Item in ipairs(LocalTable.Children) do
  1220.             Check(Item, LocalTable.BackgroundColor, 1, 1)
  1221.         end
  1222.     end
  1223.     return PublicTable
  1224. end
  1225.  
  1226. -- End of alakazard12's Nova GUI API
  1227.  
  1228. local tArgs = {...}
  1229.  
  1230. local FilePath = table.concat(tArgs, " ")
  1231. if FilePath then
  1232.     FilePath = shell.resolve(FilePath)
  1233. end
  1234.  
  1235. if FilePath == "" then
  1236.     FilePath = nil
  1237. end
  1238.  
  1239. local Debug = true
  1240.  
  1241. local function LogText(Text)
  1242.     if Debug == true then
  1243.         if fs.exists("NCLog") then
  1244.             local File = fs.open("NCLog", "r")
  1245.             Text = File.readAll() .. "\n" .. Text
  1246.             File.close()
  1247.         end
  1248.  
  1249.         local File = fs.open("NCLog", "w")
  1250.         File.write(Text)
  1251.         File.close()
  1252.     end
  1253. end
  1254.  
  1255. local Logo = {[1]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=0,[18]=0,[19]=0,[20]=0,[21]=0,[22]=0,[23]=0,[24]=0,[25]=0,[26]=0,[27]=0,[28]=0,[29]=0,[30]=0,[31]=0,[32]=0,[33]=0,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,},[2]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=0,[18]=0,[19]=0,[20]=0,[21]=0,[22]=0,[23]=0,[24]=0,[25]=0,[26]=0,[27]=0,[28]=0,[29]=0,[30]=0,[31]=0,[32]=0,[33]=0,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,},[3]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=0,[18]=2,[19]=2,[20]=2,[21]=2,[22]=2,[23]=2,[24]=2,[25]=2,[26]=2,[27]=2,[28]=2,[29]=2,[30]=2,[31]=2,[32]=2,[33]=0,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,[50]=0,},[4]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=2,[18]=2,[19]=256,[20]=256,[21]=256,[22]=256,[23]=256,[24]=256,[25]=256,[26]=256,[27]=256,[28]=256,[29]=256,[30]=256,[31]=256,[32]=2,[33]=2,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,[50]=0,},[5]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=2,[17]=2,[18]=256,[19]=1,[20]=32768,[21]=256,[22]=256,[23]=256,[24]=256,[25]=256,[26]=256,[27]=256,[28]=256,[29]=256,[30]=32768,[31]=1,[32]=256,[33]=2,[34]=2,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,[50]=0,},[6]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=2,[17]=256,[18]=256,[19]=256,[20]=256,[21]=256,[22]=256,[23]=256,[24]=256,[25]=256,[26]=256,[27]=256,[28]=256,[29]=256,[30]=256,[31]=256,[32]=256,[33]=256,[34]=2,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,[50]=0,},[7]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=2,[17]=256,[18]=256,[19]=256,[20]=256,[21]=256,[22]=32768,[23]=32768,[24]=32768,[25]=32768,[26]=32768,[27]=32768,[28]=32768,[29]=256,[30]=256,[31]=256,[32]=256,[33]=256,[34]=2,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,[50]=0,},[8]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=2,[17]=16384,[18]=16384,[19]=16384,[20]=16384,[21]=16384,[22]=16384,[23]=16384,[24]=16384,[25]=16384,[26]=16384,[27]=16384,[28]=16384,[29]=16384,[30]=16384,[31]=16384,[32]=16384,[33]=16384,[34]=2,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,[50]=0,},[9]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=2,[17]=16384,[18]=16384,[19]=16384,[20]=16384,[21]=16384,[22]=16384,[23]=16384,[24]=16384,[25]=16384,[26]=16384,[27]=16384,[28]=16384,[29]=16384,[30]=16384,[31]=16384,[32]=16384,[33]=16384,[34]=2,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,[50]=0,},[10]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=2,[17]=2,[18]=16384,[19]=16384,[20]=16384,[21]=16384,[22]=16384,[23]=16384,[24]=16384,[25]=16384,[26]=16384,[27]=16384,[28]=16384,[29]=16384,[30]=16384,[31]=16384,[32]=16384,[33]=2,[34]=2,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,[50]=0,},[11]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=2,[18]=2,[19]=16384,[20]=16384,[21]=16384,[22]=16384,[23]=16384,[24]=16384,[25]=16384,[26]=16384,[27]=16384,[28]=16384,[29]=16384,[30]=16384,[31]=16384,[32]=2,[33]=2,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,[50]=0,},[12]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=0,[18]=2,[19]=2,[20]=2,[21]=2,[22]=2,[23]=2,[24]=2,[25]=2,[26]=2,[27]=2,[28]=2,[29]=2,[30]=2,[31]=2,[32]=2,[33]=0,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,[50]=0,},[13]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=0,[18]=0,[19]=0,[20]=0,[21]=0,[22]=0,[23]=0,[24]=0,[25]=0,[26]=0,[27]=0,[28]=0,[29]=0,[30]=0,[31]=0,[32]=0,[33]=0,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,},[14]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=0,[18]=0,[19]=0,[20]=0,[21]=0,[22]=0,[23]=0,[24]=0,[25]=0,[26]=0,[27]=0,[28]=0,[29]=0,[30]=0,[31]=0,[32]=0,[33]=0,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,},[15]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=0,[18]=0,[19]=0,[20]=0,[21]=0,[22]=0,[23]=0,[24]=0,[25]=0,[26]=0,[27]=0,[28]=0,[29]=0,[30]=0,[31]=0,[32]=0,[33]=0,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,},[16]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=0,[18]=0,[19]=0,[20]=0,[21]=0,[22]=0,[23]=0,[24]=0,[25]=0,[26]=0,[27]=0,[28]=0,[29]=0,[30]=0,[31]=0,[32]=0,[33]=0,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,},[17]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=0,[18]=0,[19]=0,[20]=0,[21]=0,[22]=0,[23]=0,[24]=0,[25]=0,[26]=0,[27]=0,[28]=0,[29]=0,[30]=0,[31]=0,[32]=0,[33]=0,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,},[18]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,[9]=0,[10]=0,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=0,[17]=0,[18]=0,[19]=0,[20]=0,[21]=0,[22]=0,[23]=0,[24]=0,[25]=0,[26]=0,[27]=0,[28]=0,[29]=0,[30]=0,[31]=0,[32]=0,[33]=0,[34]=0,[35]=0,[36]=0,[37]=0,[38]=0,[39]=0,[40]=0,[41]=0,[42]=0,[43]=0,[44]=0,[45]=0,[46]=0,[47]=0,[48]=0,[49]=0,},}
  1256.  
  1257. local plainColour = colors.white
  1258. local syntaxColour = colors.cyan
  1259. local stringColour = colors.red
  1260. local backgroundColour = colors.gray
  1261. local booleanColour = colors.blue
  1262. local functionColour = colors.lightGray
  1263. local ccColour = colors.yellow
  1264. local commentColour = colors.lime
  1265.  
  1266. term.setBackgroundColor(colors.gray)
  1267. term.clear()
  1268. paintutils.drawImage(Logo, 1, 1)
  1269. term.setCursorPos(21, 17)
  1270. term.setTextColor(colors.red)
  1271. term.setBackgroundColor(colors.gray)
  1272. term.write("Nova Code")
  1273.  
  1274. sleep(0.5)
  1275.  
  1276. local MainUI = NewUI()
  1277. MainUI:BackgroundColor(backgroundColour)
  1278.  
  1279. local DDraw = MainUI:New("TextLabel")
  1280. DDraw:Text("")
  1281. DDraw:ShowBackground(false)
  1282. DDraw:Size(51, 17)
  1283. DDraw:Position(1, 2)
  1284.  
  1285. local TBar = MainUI:New("TextLabel")
  1286. TBar:Text("")
  1287. TBar:Size(51, 1)
  1288. TBar:Position(1, 1)
  1289. TBar:BackgroundColor(colors.red)
  1290.  
  1291. local Num = DDraw:New("TextLabel")
  1292. Num:Text("")
  1293. Num:Size(2, 18)
  1294. Num:Position(1, 1)
  1295. Num:BackgroundColor(colors.lightGray)
  1296.  
  1297. local FileB = TBar:New("TextButton")
  1298. FileB:Size(4, 1)
  1299. FileB:Text("File")
  1300. FileB:TextColor(colors.white)
  1301. FileB:Position(2, 1)
  1302. FileB:ShowBackground(false)
  1303.  
  1304. local EditB = TBar:New("TextButton")
  1305. EditB:Size(4, 1)
  1306. EditB:Text("Edit")
  1307. EditB:TextColor(colors.white)
  1308. EditB:Position(8, 1)
  1309. EditB:ShowBackground(false)
  1310.  
  1311. local RunDB = TBar:New("TextButton")
  1312. RunDB:Size(3, 1)
  1313. RunDB:Text("Run")
  1314. RunDB:TextColor(colors.white)
  1315. RunDB:Position(14, 1)
  1316. RunDB:ShowBackground(false)
  1317.  
  1318. local FileM = MainUI:New("TextLabel")
  1319. FileM:Size(20, 3)
  1320. FileM:Position(2, 2)
  1321. FileM:Text("")
  1322. FileM:BackgroundColor(colors.white)
  1323. FileM:ZIndex(5)
  1324. FileM:Visible(false)
  1325. FileM:Active(false)
  1326.  
  1327. local SaveB = FileM:New("TextButton")
  1328. SaveB:Size(20, 1)
  1329. SaveB:ShowBackground(false)
  1330. SaveB:TextColor(colors.black)
  1331. SaveB:Text("  Save           S")
  1332. SaveB:TextXAlignment(0)
  1333.  
  1334. local SaveAB = FileM:New("TextButton")
  1335. SaveAB:Size(20, 1)
  1336. SaveAB:ShowBackground(false)
  1337. SaveAB:TextColor(colors.black)
  1338. SaveAB:Text("  Save As")
  1339. SaveAB:TextXAlignment(0)
  1340. SaveAB:Position(1, 2)
  1341.  
  1342. local ExitB = FileM:New("TextButton")
  1343. ExitB:Size(20, 1)
  1344. ExitB:ShowBackground(false)
  1345. ExitB:TextColor(colors.black)
  1346. ExitB:Text("  Exit           Q")
  1347. ExitB:TextXAlignment(0)
  1348. ExitB:Position(1, 3)
  1349.  
  1350. local EditM = MainUI:New("TextLabel")
  1351. EditM:Size(20, 3)
  1352. EditM:Position(8, 2)
  1353. EditM:Text("")
  1354. EditM:BackgroundColor(colors.white)
  1355. EditM:ZIndex(5)
  1356. EditM:Active(false)
  1357. EditM:Visible(false)
  1358.  
  1359. local CopyLB = EditM:New("TextButton")
  1360. CopyLB:Size(20, 1)
  1361. CopyLB:ShowBackground(false)
  1362. CopyLB:TextColor(colors.black)
  1363. CopyLB:Text("  Copy Line      C")
  1364. CopyLB:TextXAlignment(0)
  1365.  
  1366. local PasteB = EditM:New("TextButton")
  1367. PasteB:Size(20, 1)
  1368. PasteB:ShowBackground(false)
  1369. PasteB:TextColor(colors.black)
  1370. PasteB:Text("  Paste          P")
  1371. PasteB:TextXAlignment(0)
  1372. PasteB:Position(1, 2)
  1373.  
  1374. local DeleteB = EditM:New("TextButton")
  1375. DeleteB:Size(20, 1)
  1376. DeleteB:ShowBackground(false)
  1377. DeleteB:TextColor(colors.black)
  1378. DeleteB:Text("  Delete Line    D")
  1379. DeleteB:TextXAlignment(0)
  1380. DeleteB:Position(1, 3)
  1381.  
  1382. local RunM = MainUI:New("TextLabel")
  1383. RunM:Size(20, 2)
  1384. RunM:Position(14, 2)
  1385. RunM:Text("")
  1386. RunM:BackgroundColor(colors.white)
  1387. RunM:ZIndex(5)
  1388. RunM:Active(false)
  1389. RunM:Visible(false)
  1390.  
  1391. local RunB = RunM:New("TextButton")
  1392. RunB:Size(20, 1)
  1393. RunB:ShowBackground(false)
  1394. RunB:TextColor(colors.black)
  1395. RunB:Text("  Run            R")
  1396. RunB:TextXAlignment(0)
  1397.  
  1398. local RunAB = RunM:New("TextButton")
  1399. RunAB:Size(20, 1)
  1400. RunAB:ShowBackground(false)
  1401. RunAB:TextColor(colors.black)
  1402. RunAB:Text("  Run With Args  A")
  1403. RunAB:TextXAlignment(0)
  1404. RunAB:Position(1, 2)
  1405.  
  1406. local SaveAM = MainUI:New("TextLabel")
  1407. SaveAM:Size(41, 9)
  1408. SaveAM:Position(5, 5)
  1409. SaveAM:Text("Save As")
  1410. SaveAM:TextYAlignment(0)
  1411. SaveAM:BackgroundColor(colors.white)
  1412. SaveAM:TextColor(colors.black)
  1413.  
  1414. local PathT = SaveAM:New("TextLabel")
  1415. PathT:Text("Path:")
  1416. PathT:Size(5, 1)
  1417. PathT:TextColor(colors.black)
  1418. PathT:ShowBackground(false)
  1419. PathT:Position(2, 4)
  1420.  
  1421. local PathInput = SaveAM:New("TextBox")
  1422. PathInput:Text(FilePath or "")
  1423. PathInput:Position(8, 4)
  1424. PathInput:Size(32, 1)
  1425. PathInput:BackgroundColor(colors.gray)
  1426. PathInput:ActiveTextColor(colors.lightGray)
  1427. PathInput:TextColor(colors.white)
  1428. PathInput:Overlap(true)
  1429. PathInput:TextXAlignment(0)
  1430.  
  1431. local SavePT = SaveAM:New("TextButton")
  1432. SavePT:Text("Save")
  1433. SavePT:Size(6, 1)
  1434. SavePT:BackgroundColor(colors.lightGray)
  1435. SavePT:TextColor(colors.black)
  1436. SavePT:Position(15, 7)
  1437.  
  1438. local CancelPT = SaveAM:New("TextButton")
  1439. CancelPT:Text("Cancel")
  1440. CancelPT:Size(8, 1)
  1441. CancelPT:BackgroundColor(colors.lightGray)
  1442. CancelPT:TextColor(colors.black)
  1443. CancelPT:Position(22, 7)
  1444.  
  1445. SaveAM:Visible(false)
  1446. SaveAM:Active(false)
  1447.  
  1448. local RunAM = MainUI:New("TextLabel")
  1449. RunAM:Size(41, 9)
  1450. RunAM:Position(5, 5)
  1451. RunAM:Text("Run With Args")
  1452. RunAM:TextYAlignment(0)
  1453. RunAM:BackgroundColor(colors.white)
  1454. RunAM:TextColor(colors.black)
  1455.  
  1456. local ArgT = RunAM:New("TextLabel")
  1457. ArgT:Text("Args:")
  1458. ArgT:Size(5, 1)
  1459. ArgT:TextColor(colors.black)
  1460. ArgT:ShowBackground(false)
  1461. ArgT:Position(2, 4)
  1462.  
  1463. local ArgInput = RunAM:New("TextBox")
  1464. ArgInput:Text(FilePath or "")
  1465. ArgInput:Position(8, 4)
  1466. ArgInput:Size(32, 1)
  1467. ArgInput:BackgroundColor(colors.gray)
  1468. ArgInput:ActiveTextColor(colors.lightGray)
  1469. ArgInput:TextColor(colors.white)
  1470. ArgInput:Overlap(true)
  1471. ArgInput:TextXAlignment(0)
  1472.  
  1473. local RunPT = RunAM:New("TextButton")
  1474. RunPT:Text("Run")
  1475. RunPT:Size(6, 1)
  1476. RunPT:BackgroundColor(colors.lightGray)
  1477. RunPT:TextColor(colors.black)
  1478. RunPT:Position(15, 7)
  1479.  
  1480. local CancelPRT = RunAM:New("TextButton")
  1481. CancelPRT:Text("Cancel")
  1482. CancelPRT:Size(8, 1)
  1483. CancelPRT:BackgroundColor(colors.lightGray)
  1484. CancelPRT:TextColor(colors.black)
  1485. CancelPRT:Position(22, 7)
  1486.  
  1487. RunAM:Visible(false)
  1488. RunAM:Active(false)
  1489.  
  1490. local ErrorM = MainUI:New("TextLabel")
  1491. ErrorM:Size(35, 6)
  1492. ErrorM:Text("")
  1493. ErrorM:BackgroundColor(colors.white)
  1494. ErrorM:ShowText(false)
  1495. ErrorM:Position(8, 7)
  1496.  
  1497. local ErrorTitle = ErrorM:New("TextLabel")
  1498. ErrorTitle:TextColor(colors.white)
  1499. ErrorTitle:Size(35, 1)
  1500. ErrorTitle:BackgroundColor(colors.lightGray)
  1501.  
  1502. local EMessage = ErrorM:New("TextLabel")
  1503. EMessage:Size(33, 2)
  1504. EMessage:ShowBackground(false)
  1505. EMessage:TextColor(colors.red)
  1506. EMessage:Text("")
  1507. EMessage:MultiLine(true)
  1508. EMessage:Position(2, 3)
  1509.  
  1510. local DoneB = ErrorM:New("TextButton")
  1511. DoneB:Text("Done")
  1512. DoneB:Size(6, 1)
  1513. DoneB:Position(15, 5)
  1514. DoneB:BackgroundColor(colors.lightGray)
  1515. DoneB:TextColor(colors.black)
  1516.  
  1517. ErrorM:Visible(false)
  1518. ErrorM:Active(false)
  1519.  
  1520. --[[
  1521. local VBar = MainUI:New("TextLabel")
  1522. VBar:Size(1, 16)
  1523. VBar:Position(51, 2)
  1524. VBar:BackgroundColor(colors.lightGray)
  1525. VBar:Text("")
  1526.  
  1527. local VScroll = VBar:New("TextButton")
  1528. VScroll:Size(1, 5)
  1529. VScroll:Position(1, 2)
  1530. VScroll:BackgroundColor(colors.black)
  1531. VScroll:Text("")
  1532.  
  1533. local VUp = VBar:New("TextButton")
  1534. VUp:Size(1, 1)
  1535. VUp:Position(1, 1)
  1536. VUp:BackgroundColor(colors.black)
  1537. VUp:Text("^")
  1538.  
  1539. local VDown = VBar:New("TextButton")
  1540. VDown:Size(1, 1)
  1541. VDown:Position(1, 17)
  1542. VDown:BackgroundColor(colors.black)
  1543. VDown:Text("v")
  1544.  
  1545. local HBar = MainUI:New("TextLabel")
  1546. HBar:Size(50, 1)
  1547. HBar:Position(1, 19)
  1548. HBar:BackgroundColor(colors.lightGray)
  1549. HBar:Text("")
  1550.  
  1551. local HScroll = HBar:New("TextButton")
  1552. HScroll:Size(8, 1)
  1553. HScroll:Position(2, 1)
  1554. HScroll:BackgroundColor(colors.black)
  1555. HScroll:Text("")
  1556.  
  1557. local HLeft = HBar:New("TextButton")
  1558. HLeft:Size(1, 1)
  1559. HLeft:Position(1, 1)
  1560. HLeft:BackgroundColor(colors.black)
  1561. HLeft:Text("<")
  1562.  
  1563. local HRight = HBar:New("TextButton")
  1564. HRight:Size(1, 1)
  1565. HRight:Position(50, 1)
  1566. HRight:BackgroundColor(colors.black)
  1567. HRight:Text(">")]]
  1568.  
  1569.  
  1570. local NLines = {}
  1571. for i = 1, 18 do
  1572.     local NewLine = Num:New("TextLabel")
  1573.     NewLine:Text("")
  1574.     NewLine:Size(2, 1)
  1575.     NewLine:ShowBackground(false)
  1576.     NewLine:TextColor(colors.black)
  1577.     NewLine:Position(1, i)
  1578.     NewLine:TextXAlignment(0)
  1579.     NLines[i] = NewLine
  1580. end
  1581.  
  1582. local TLines = {}
  1583. local NWidth = 2
  1584. local TWidth = 48
  1585. local VWidth = 18
  1586. local ScrollV = 1
  1587. local ScrollH = 1
  1588. local EditLine = 1
  1589. local EditX = 0
  1590. local EditNLine = 1
  1591. local EditNX = 0
  1592. local EditText = ""
  1593. local CursorPosX = 1
  1594. local CursorPosY = 1
  1595. local Format = {
  1596.     ["Seclude"] = {
  1597.         ["end"] = syntaxColour;
  1598.         ["while"] = syntaxColour;
  1599.         ["true"] = booleanColour;
  1600.         ["false"] = booleanColour;
  1601.         ["if"] = syntaxColour;
  1602.         ["do"] = syntaxColour;
  1603.         ["for"] = syntaxColour;
  1604.         ["in"] = syntaxColour;
  1605.         ["function"] = syntaxColour;
  1606.         ["local"] = syntaxColour;
  1607.         ["and"] = syntaxColour;
  1608.         ["or"] = syntaxColour;
  1609.         ["else"] = syntaxColour;
  1610.         ["elseif"] = syntaxColour;
  1611.         ["break"] = syntaxColour;
  1612.         ["nil"] = booleanColour;
  1613.         ["not"] = syntaxColour;
  1614.         ["repeat"] = syntaxColour;
  1615.         ["return"] = syntaxColour;
  1616.         ["then"] = syntaxColour;
  1617.         ["until"] = syntaxColour;
  1618.         ["print"] = functionColour;
  1619.         ["table.insert"] = functionColour;
  1620.         ["table.remove"] = functionColour;
  1621.     }
  1622. }
  1623.  
  1624. local function FormText(Text)
  1625.     local New = {}
  1626.     local LastM = 0
  1627.     local stringStart1
  1628.     local stringStart2
  1629.     local commentStart1
  1630.     for i = 1, #Text do
  1631.         if Text:sub(i, i) == '"' and Text:sub(i - 1, i - 1) ~= "\\" and not ((stringStart2 and not stringStart1) or commentStart1) then
  1632.             if stringStart1 then
  1633.                 table.insert(New, {Text:sub(stringStart1, i), stringColour})
  1634.                 LastM = i
  1635.                 stringStart1 = nil
  1636.             else
  1637.                 stringStart1 = i
  1638.                 if LastM and i ~= 1 then
  1639.                     table.insert(New, {Text:sub(LastM + 1, i - 1), plainColour})
  1640.                 end
  1641.                 LastM = i - 1
  1642.             end
  1643.         end
  1644.         if Text:sub(i, i) == "'" and Text:sub(i - 1, i - 1) ~= "\\" and not ((stringStart1 and not stringStart2) or commentStart1) then
  1645.             if stringStart2 then
  1646.                 table.insert(New, {Text:sub(stringStart2, i), stringColour})
  1647.                 LastM = i
  1648.                 stringStart2 = nil
  1649.             else
  1650.                 stringStart2 = i
  1651.                 if LastM and i ~= 1 then
  1652.                     table.insert(New, {Text:sub(LastM + 1, i - 1), plainColour})
  1653.                 end
  1654.                 LastM = i - 1
  1655.             end
  1656.         end
  1657.         if Text:sub(i, i) == "-" and Text:sub(i - 1, i - 1) == "-" and not (stringStart2 or stringStart1) then
  1658.             commentStart1 = i - 1
  1659.             if LastM and i ~= 1 then
  1660.                 table.insert(New, {Text:sub(LastM + 1, i - 2), plainColour})
  1661.             end
  1662.             LastM = i - 2
  1663.         end
  1664.         if not stringStart1 and not stringStart2 and not commentStart1 then
  1665.             for r,v in pairs(Format["Seclude"]) do
  1666.                 if Text:sub(i, #r + i - 1) == r then
  1667.                     if i == 1 or Text:sub(i - 1, i - 1) == " " or Text:sub(i - 1, i - 1) == ")" or Text:sub(i - 1, i - 1) == "(" or Text:sub(i - 1, i - 1) == "]" or Text:sub(i - 1, i - 1) == "[" then
  1668.                         if i + #r - 1 == #Text or Text:sub(i + #r, i + #r) == " " or Text:sub(i + #r, i + #r) == "(" or Text:sub(i + #r, i + #r) == ")"  or Text:sub(i + #r, i + #r) == "[" or Text:sub(i + #r, i + #r) == "]" then
  1669.                             if LastM and i ~= 1 then
  1670.                                 table.insert(New, {Text:sub(LastM + 1, i - 1), plainColour})
  1671.                             end
  1672.                             table.insert(New, {Text:sub(i, #r + i - 1), v})
  1673.                             LastM = i + #r - 1
  1674.                         end
  1675.                     end
  1676.                 end
  1677.             end
  1678.         end
  1679.     end
  1680.     if LastM then
  1681.         if commentStart1 then
  1682.             table.insert(New, {Text:sub(LastM + 1, #Text), commentColour})
  1683.         elseif stringStart1 or stringStart2 then
  1684.             table.insert(New, {Text:sub(LastM + 1, #Text), stringColour})
  1685.         else
  1686.             table.insert(New, {Text:sub(LastM + 1, #Text), plainColour})
  1687.         end
  1688.     end
  1689.     return New
  1690. end
  1691.  
  1692. local function DisplayLine(FormatTextT, Line)
  1693.     term.setCursorPos(1, Line + 1)
  1694.     term.setBackgroundColor(backgroundColour)
  1695.     term.clearLine()
  1696.     term.setBackgroundColor(colors.gray)
  1697.  
  1698.     term.setCursorPos(NWidth + 1, Line + 1)
  1699.     local LWrote = 0
  1700.    
  1701.     local NewT = {}
  1702.     local MWrote = 0
  1703.     for i,v in pairs(FormatTextT) do
  1704.         if MWrote >= ScrollH - 1 then
  1705.             table.insert(NewT, {v[1], v[2]})
  1706.         elseif #v[1] + MWrote >= ScrollH - 1 then
  1707.             if #v[1] + MWrote > ScrollH - 1 then
  1708.                 table.insert(NewT, {v[1]:sub(ScrollH - MWrote, #v[1]), v[2]})
  1709.             end
  1710.             MWrote = MWrote + #v[1]
  1711.         else
  1712.             MWrote = MWrote + #v[1]
  1713.         end
  1714.     end
  1715.  
  1716.     for i,v in pairs(NewT) do
  1717.         if LWrote + #v[1] > TWidth then
  1718.             if LWrote < TWidth then
  1719.                 v[1] = v[1]:sub(1, TWidth - LWrote)
  1720.                 term.setTextColor(v[2])
  1721.                 term.write(v[1])
  1722.                 LWrote = LWrote + #v[1]
  1723.             end
  1724.         else
  1725.             term.setTextColor(v[2])
  1726.             term.write(v[1])
  1727.             LWrote = LWrote + #v[1]
  1728.         end
  1729.     end
  1730.     term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
  1731.     term.setCursorBlink(true)
  1732. end
  1733.  
  1734. local function DisplayLines()
  1735.     for i = 0, 17 do
  1736.         local v = TLines[i + ScrollV]
  1737.         if not v then
  1738.             for m = i + 1, 18 do
  1739.                 NLines[m]:Text("")
  1740.             end
  1741.             break
  1742.         end
  1743.         NLines[i + 1]:Text(tostring(i + ScrollV))
  1744.         local TempT = v
  1745.         DisplayLine(FormText(TempT), i + 1)
  1746.     end
  1747.     Num:Draw()
  1748.     term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
  1749.     term.setCursorBlink(true)
  1750. end
  1751.  
  1752. local function CheckScroll()
  1753.     local DT = false
  1754.     if EditNX > TWidth then
  1755.         EditNX = EditNX - 1
  1756.         ScrollH = ScrollH + 1
  1757.         if not CheckScroll() then
  1758.             DisplayLines()
  1759.         end
  1760.         DT = true
  1761.     elseif EditNX < 0 then
  1762.         EditNX = EditNX + 1
  1763.         ScrollH = ScrollH - 1
  1764.         if not CheckScroll() then
  1765.             DisplayLines()
  1766.         end
  1767.         DT = true
  1768.     end
  1769.  
  1770.     if EditNLine < 1 then
  1771.         EditNLine = EditNLine + 1
  1772.         ScrollV = ScrollV - 1
  1773.         --[[local Line = TLines[EditLine]
  1774.         local Ratio = (ScrollV - 1) / (#Line - VWidth)
  1775.         VScroll:Position((14-5) * Ratio + 2, 1)
  1776.         HBar:Draw()]]
  1777.         if not CheckScroll() then
  1778.             DisplayLines()
  1779.         end
  1780.         DT = true
  1781.     elseif EditNLine > VWidth then
  1782.         EditNLine = EditNLine - 1
  1783.         ScrollV = ScrollV + 1
  1784.         if not CheckScroll() then
  1785.             DisplayLines()
  1786.         end
  1787.         DT = true
  1788.     end
  1789.  
  1790.     if NWidth ~=  #tostring(#TLines)+ 1 then
  1791.         NWidth = #tostring(#TLines) + 1
  1792.         TWidth = 51 - NWidth
  1793.         Num:Size(NWidth, 18)
  1794.         for i,v in pairs(NLines) do
  1795.             v:Size(NWidth, 1)
  1796.         end
  1797.         MainUI:Draw()
  1798.         DisplayLines()
  1799.         DT = true
  1800.     end
  1801.  
  1802.     return DT
  1803. end
  1804.  
  1805. local ActiveMenu
  1806.  
  1807. local function CloseMenu()
  1808.     ActiveMenu:Visible(false)
  1809.     ActiveMenu:Active(false)
  1810.     MainUI:Draw()
  1811.     DisplayLines()
  1812.     Num:Draw()
  1813.     term.setCursorBlink(true)
  1814.     term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
  1815.     ActiveMenu = nil
  1816. end
  1817.  
  1818. local function OpenMenu(Menu)
  1819.     if Menu == ActiveMenu then
  1820.         CloseMenu()
  1821.     else
  1822.         if ActiveMenu then
  1823.             ActiveMenu:Visible(false)
  1824.             ActiveMenu:Active(false)
  1825.         end
  1826.         Menu:Visible(true)
  1827.         Menu:Active(true)
  1828.         MainUI:Draw()
  1829.         DisplayLines()
  1830.         Num:Draw()
  1831.         Menu:Draw()
  1832.  
  1833.         term.setCursorBlink(false)
  1834.  
  1835.         ActiveMenu = Menu
  1836.     end
  1837. end
  1838.  
  1839. local ActiveSave
  1840. local SaveTog
  1841.  
  1842. local function SaveATog()
  1843.     PathInput:Text(FilePath or "")
  1844.     FileB:Active(false)
  1845.     EditB:Active(false)
  1846.     RunDB:Active(false)
  1847.     SaveAM:Visible(true)
  1848.     SaveAM:Active(true)
  1849.     ActiveSave = true
  1850.     CloseMenu()
  1851.     term.setCursorBlink(false)
  1852.     SaveAM:Draw()
  1853. end
  1854.  
  1855. local function ErrorT(Title, Text)
  1856.     if ActiveMenu then
  1857.         CloseMenu()
  1858.         ErrorM:Draw()
  1859.     end
  1860.     ErrorTitle:Text(Title)
  1861.     EMessage:Text(Text)
  1862.     ErrorM:Visible(true)
  1863.     ErrorM:Active(true)
  1864.     MainUI:Draw()
  1865.     DisplayLines()
  1866.     Num:Draw()
  1867.     ErrorM:Draw()
  1868.     ActiveSave = true
  1869.     FileB:Active(false)
  1870.     EditB:Active(false)
  1871.     RunDB:Active(false)
  1872.     term.setCursorBlink(false)
  1873. end
  1874.  
  1875. function SaveTog()
  1876.     if not FilePath then
  1877.         SaveATog()
  1878.     else
  1879.         local File = fs.open(FilePath, "w")
  1880.         for i,v in pairs(TLines) do
  1881.             File.writeLine(v)
  1882.         end
  1883.         File.close()
  1884.     end
  1885.     if ActiveMenu then
  1886.         CloseMenu()
  1887.     end
  1888. end
  1889.  
  1890. MainUI:ErrorHandle(function(Err) ErrorT("Error", Err) end)
  1891.  
  1892. SavePT:Button1Click(function()
  1893.     FilePath = fs.combine(PathInput:GetText(), "")
  1894.     if FilePath and FilePath ~= "" then
  1895.         SaveAM:Visible(false)
  1896.         SaveAM:Active(false)
  1897.         FileB:Active(true)
  1898.         EditB:Active(true)
  1899.         RunDB:Active(true)
  1900.         MainUI:Draw()
  1901.         DisplayLines()
  1902.         Num:Draw()
  1903.         term.setCursorBlink(true)
  1904.         term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
  1905.         ActiveSave = false
  1906.         SaveTog()
  1907.     else
  1908.         FilePath = nil
  1909.     end
  1910. end)
  1911.  
  1912. CancelPT:Button1Click(function()
  1913.     SaveAM:Visible(false)
  1914.     SaveAM:Active(false)
  1915.     MainUI:Draw()
  1916.     DisplayLines()
  1917.     Num:Draw()
  1918.     term.setCursorBlink(true)
  1919.     term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
  1920.     ActiveSave = false
  1921.     FileB:Active(true)
  1922.     EditB:Active(true)
  1923.     RunDB:Active(true)
  1924. end)
  1925.  
  1926. DoneB:Button1Click(function()
  1927.     ErrorM:Visible(false)
  1928.     ErrorM:Active(false)
  1929.     MainUI:Draw()
  1930.     DisplayLines()
  1931.     Num:Draw()
  1932.     term.setCursorBlink(true)
  1933.     term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
  1934.     ActiveSave = false
  1935.     FileB:Active(true)
  1936.     EditB:Active(true)
  1937.     RunDB:Active(true)
  1938. end)
  1939.  
  1940. local Clip
  1941.  
  1942. local function Copy()
  1943.     local Line = TLines[EditLine]
  1944.     Clip = Line
  1945.     CloseMenu()
  1946. end
  1947.  
  1948. local function Delete()
  1949.     CloseMenu()
  1950.     if #TLines == 1 then
  1951.         TLines[1] = ""
  1952.     else
  1953.         table.remove(TLines, EditLine)
  1954.     end
  1955.     EditX = 0
  1956.     EditNX = 0
  1957.     ScrollH = 1
  1958.     if not TLines[EditLine] then
  1959.         EditLine = EditLine - 1
  1960.         EditNLine = EditNLine - 1
  1961.     end
  1962.     MainUI:Draw()
  1963.     if not (CheckScroll()) then
  1964.         DisplayLines()
  1965.         Num:Draw()
  1966.         term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
  1967.         term.setCursorBlink(true)
  1968.     end
  1969. end
  1970.  
  1971. local function Paste()
  1972.     CloseMenu()
  1973.     if Clip then
  1974.         local Line = TLines[EditLine]
  1975.         if Line == "" then
  1976.             Line = Clip
  1977.         elseif EditX == 0 then
  1978.             Line = Clip .. Line
  1979.         elseif EditX == #Line then
  1980.             Line = Line .. Clip
  1981.         else
  1982.             Line = Line:sub(0, EditX) .. Clip .. Line:sub(EditX + 1, #Line)
  1983.         end
  1984.         EditX = EditX + #Clip
  1985.         EditNX = EditNX + #Clip
  1986.         TLines[EditLine] = Line
  1987.         DisplayLine(FormText(Line), EditNLine)
  1988.         Num:Draw()
  1989.         CheckScroll()
  1990.         term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
  1991.         term.setCursorBlink(true)
  1992.     end
  1993. end
  1994.  
  1995. local function Run(...)
  1996.     if ActiveMenu then
  1997.         CloseMenu()
  1998.     end
  1999.     local Str = TLines[1]
  2000.     for i,v in pairs(TLines) do
  2001.         if i > 1 then
  2002.             Str = Str .. "\n" .. v
  2003.         end
  2004.     end
  2005.  
  2006.     local Func, Err = loadstring(Str, FilePath or "Untitled")
  2007.  
  2008.     if not Func then
  2009.         ErrorT("Error", Err)
  2010.     else
  2011.         term.setBackgroundColor(colors.black)
  2012.         term.clear()
  2013.         term.setTextColor(colors.white)
  2014.         term.setCursorPos(1, 1)
  2015.         local Success, Err = pcall(Func, ...)
  2016.         print("Press any key to continue...")
  2017.         os.pullEvent("key")
  2018.         sleep(0)
  2019.         if not Success then
  2020.             MainUI:Draw()
  2021.             DisplayLines()
  2022.             Num:Draw()
  2023.             ErrorT("Error", Err)
  2024.         else
  2025.             MainUI:Draw()
  2026.             DisplayLines()
  2027.             Num:Draw()
  2028.         end
  2029.         term.setCursorBlink(true)
  2030.         term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
  2031.     end
  2032. end
  2033.  
  2034. RunPT:Button1Click(function()
  2035.     RunAM:Visible(false)
  2036.     RunAM:Active(false)
  2037.     FileB:Active(true)
  2038.     EditB:Active(true)
  2039.     RunDB:Active(true)
  2040.     MainUI:Draw()
  2041.     DisplayLines()
  2042.     Num:Draw()
  2043.     term.setCursorBlink(true)
  2044.     term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
  2045.     ActiveSave = false
  2046.     local Args = {}
  2047.     for Arg in ArgInput:GetText():gmatch("([^ ]+)") do
  2048.         table.insert(Args, Arg)
  2049.     end
  2050.     Run(unpack(Args))
  2051. end)
  2052.  
  2053. CancelPRT:Button1Click(function()
  2054.     RunAM:Visible(false)
  2055.     RunAM:Active(false)
  2056.     MainUI:Draw()
  2057.     DisplayLines()
  2058.     Num:Draw()
  2059.     term.setCursorBlink(true)
  2060.     term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
  2061.     ActiveSave = false
  2062.     FileB:Active(true)
  2063.     EditB:Active(true)
  2064.     RunDB:Active(true)
  2065. end)
  2066.  
  2067. local function RunA()
  2068.     ArgInput:Text("")
  2069.     FileB:Active(false)
  2070.     EditB:Active(false)
  2071.     RunDB:Active(false)
  2072.     RunAM:Visible(true)
  2073.     RunAM:Active(true)
  2074.     ActiveSave = true
  2075.     CloseMenu()
  2076.     term.setCursorBlink(false)
  2077.     RunAM:Draw()
  2078. end
  2079.  
  2080. RunB:Button1Click(function() Run() end)
  2081. RunAB:Button1Click(RunA)
  2082. CopyLB:Button1Click(Copy)
  2083. DeleteB:Button1Click(Delete)
  2084. PasteB:Button1Click(Paste)
  2085.  
  2086. FileB:Button1Click(function() OpenMenu(FileM) end)
  2087. EditB:Button1Click(function() OpenMenu(EditM) end)
  2088. RunDB:Button1Click(function() OpenMenu(RunM) end)
  2089. SaveB:Button1Click(function() SaveTog() end)
  2090. SaveAB:Button1Click(function() SaveATog() end)
  2091.  
  2092. local function Quit()
  2093.     MainUI:StopListen()
  2094.     term.setBackgroundColor(colors.black)
  2095.     term.clear()
  2096.     term.setCursorPos(1, 1)
  2097.     sleep(0.1)
  2098. end
  2099.  
  2100. local function OutputF(Event, P1, P2, P3)
  2101.     if not ActiveSave then
  2102.         if not ActiveMenu then
  2103.             if Event == "char" then
  2104.                 local Line = TLines[EditLine]
  2105.                 if Line == "" then
  2106.                     Line = P1
  2107.                 elseif EditX == 0 then
  2108.                     Line = P1 .. Line
  2109.                 elseif EditX == #Line then
  2110.                     Line = Line .. P1
  2111.                 else
  2112.                     Line = Line:sub(0, EditX) .. P1 .. Line:sub(EditX + 1, #Line)
  2113.                 end
  2114.                 EditX = EditX + 1
  2115.                 EditNX = EditNX + 1
  2116.                 TLines[EditLine] = Line
  2117.                 DisplayLine(FormText(Line), EditNLine)
  2118.                 CheckScroll()
  2119.             elseif Event == "key" then
  2120.                 if P1 == 15 then
  2121.                     local Line = TLines[EditLine]
  2122.                     if Line == "" then
  2123.                         Line = "  "
  2124.                     elseif EditX == 0 then
  2125.                         Line = "  " .. Line
  2126.                     elseif EditX == #Line then
  2127.                         Line = Line .. "  "
  2128.                     else
  2129.                         Line = Line:sub(0, EditX) .. "  " .. Line:sub(EditX + 1, #Line)
  2130.                     end
  2131.                     EditX = EditX + 2
  2132.                     EditNX = EditNX + 2
  2133.                     TLines[EditLine] = Line
  2134.                     DisplayLine(FormText(Line), EditNLine)
  2135.                     CheckScroll()
  2136.                 elseif P1 == 14 then
  2137.                     if EditX ~= 0 then
  2138.                         local Line = TLines[EditLine]
  2139.                         Line = Line:sub(1, EditX - 1) .. Line:sub(EditX + 1, #Line)
  2140.                         TLines[EditLine] = Line
  2141.                         EditX = EditX - 1
  2142.                         EditNX = EditNX - 1
  2143.                         DisplayLine(FormText(Line), EditNLine)
  2144.                         CheckScroll()
  2145.                     elseif EditLine ~= 1 then
  2146.                         local Line = TLines[EditLine]
  2147.                         local Line2 = TLines[EditLine - 1]
  2148.                         EditNX = #Line2 - ScrollH + 1
  2149.                         EditX = #Line2
  2150.                         Line2 = Line2 .. Line
  2151.                         TLines[EditLine - 1] = Line2
  2152.                         table.remove(TLines, EditLine)
  2153.                         EditLine = EditLine - 1
  2154.                         EditNLine = EditNLine - 1
  2155.                         --[[if #TLines < VWidth then
  2156.                             VWidth = VWidth - 1
  2157.                         end ]]
  2158.                         term.clear()
  2159.                         MainUI:Draw()
  2160.                         CheckScroll()
  2161.                         DisplayLines()
  2162.                     end
  2163.                 elseif P1 == 28 then
  2164.                     local Line = TLines[EditLine]
  2165.                     local Amount = 0
  2166.                     if Line:sub(1, 1) == " " then
  2167.                         local On = 1
  2168.                         repeat
  2169.                             Amount = Amount + 1
  2170.                             On = On + 1
  2171.                         until Line:sub(On, On) ~= " "
  2172.                     end
  2173.                     local New = Line:sub(EditX + 1)
  2174.                     if EditX >= Amount then
  2175.                         New = string.rep(" ", Amount) .. Line:sub(EditX + 1)
  2176.                     end
  2177.                     Line = Line:sub(1, EditX)
  2178.                     TLines[EditLine] = Line
  2179.                     table.insert(TLines, EditLine + 1, New)
  2180.                     if EditX >= Amount then
  2181.                         EditX = Amount
  2182.                         EditNX = Amount
  2183.                     else
  2184.                         EditX = 0
  2185.                         EditNX = 0
  2186.                     end
  2187.                     ScrollH = 1
  2188.                     EditNLine = EditNLine + 1
  2189.                     EditLine = EditLine + 1
  2190.                     --[[if VWidth ~= 17 then
  2191.                         VWidth = VWidth + 1
  2192.                     end ]]
  2193.                     term.clear()
  2194.                     MainUI:Draw()
  2195.                     CheckScroll()
  2196.                     DisplayLines()
  2197.                 elseif P1 == 203 then
  2198.                     if EditX ~= 0 then
  2199.                         EditX = EditX - 1
  2200.                         EditNX = EditNX - 1
  2201.                         CheckScroll()
  2202.                     end
  2203.                 elseif P1 == 205 then
  2204.                     if EditX ~= #TLines[EditLine] then
  2205.                         EditX = EditX + 1
  2206.                         EditNX = EditNX + 1
  2207.                         CheckScroll()
  2208.                     end
  2209.                 elseif P1 == 200 then
  2210.                     if EditLine ~= 1 then
  2211.                         EditLine = EditLine - 1
  2212.                         EditNLine = EditNLine - 1
  2213.                         if EditX > #TLines[EditLine] then
  2214.                             local Dif = EditX - #TLines[EditLine]
  2215.                             EditX = #TLines[EditLine]
  2216.                             EditNX = EditNX - Dif
  2217.                         end
  2218.                         CheckScroll()
  2219.                     end
  2220.                 elseif P1 == 208 then
  2221.                     if EditLine ~= #TLines then
  2222.                         EditLine = EditLine + 1
  2223.                         EditNLine = EditNLine + 1
  2224.                         if EditX > #TLines[EditLine] then
  2225.                             local Dif = EditX - #TLines[EditLine]
  2226.                             EditX = #TLines[EditLine]
  2227.                             EditNX = EditNX - Dif
  2228.                         end
  2229.                         CheckScroll()
  2230.                     end
  2231.                 elseif P1 == 29 then
  2232.                     OpenMenu(FileM)
  2233.                     return
  2234.                 elseif P1 == 209 then
  2235.                     if EditLine ~= #TLines then
  2236.                         local Push = 35
  2237.                         if #TLines - EditLine < 35 then
  2238.                             Push = #TLines - EditLine
  2239.                         end
  2240.                         EditLine = EditLine + Push
  2241.                         EditNLine = EditNLine + Push
  2242.                         CheckScroll()
  2243.                     end
  2244.                 elseif P1 == 207 and EditX ~= #TLines[EditLine] then
  2245.                     EditNX = EditNX + (#TLines[EditLine] - EditX)
  2246.                     EditX = #TLines[EditLine]
  2247.                     CheckScroll()
  2248.                 elseif P1 == 201 and EditLine ~= 1 then
  2249.                     local Push = 35
  2250.                     if EditLine <= 35 then
  2251.                         Push = EditLine - 1
  2252.                     end
  2253.                     EditLine = EditLine - Push
  2254.                     EditNLine = EditNLine - Push
  2255.                     CheckScroll()
  2256.                 elseif P1 == 199 then
  2257.                     EditNX = 0
  2258.                     ScrollH = 1
  2259.                     EditX = 0
  2260.                     if not CheckScroll() then
  2261.                         DisplayLines()
  2262.                     end
  2263.                 elseif P1 == 211 then
  2264.                     if EditX ~= #TLines[EditLine] then
  2265.                         local Line = TLines[EditLine]
  2266.                         Line = Line:sub(1, EditX) .. Line:sub(EditX + 2, #Line)
  2267.                         TLines[EditLine] = Line
  2268.                         EditX = EditX
  2269.                         EditNX = EditNX
  2270.                         DisplayLine(FormText(Line), EditNLine)
  2271.                         CheckScroll()
  2272.                     elseif EditLine ~= #TLines then
  2273.                         local Line = TLines[EditLine]
  2274.                         local Line2 = TLines[EditLine + 1]
  2275.                         --EditNX = #Line2 - ScrollH + 1
  2276.                         --EditX = #Line2
  2277.                         Line = Line .. Line2
  2278.                         TLines[EditLine] = Line
  2279.                         table.remove(TLines, EditLine + 1)
  2280.                         --[[if #TLines < VWidth then
  2281.                             VWidth = VWidth - 1
  2282.                         end ]]
  2283.                         term.clear()
  2284.                         MainUI:Draw()
  2285.                         CheckScroll()
  2286.                         DisplayLines()
  2287.                     end
  2288.                 end
  2289.             elseif Event == "mouse_click" and P3 > 1 then
  2290.                 local NewLine = ScrollV + P3 - 2
  2291.                 local NewNLine = P3 - 1
  2292.                 if NewLine > #TLines then
  2293.                     NewNLine = NewNLine - (NewLine - #TLines)
  2294.                     NewLine = #TLines
  2295.                 end
  2296.                 EditLine = NewLine
  2297.                 EditNLine = NewNLine
  2298.                 local NewX = P2 + ScrollH - NWidth - 2
  2299.                 local NewNX = P2 - 1 - NWidth
  2300.                 if NewX < 1 then
  2301.                     NewX = 0
  2302.                     NewNX = 0
  2303.                 end
  2304.                 if #TLines[EditLine] < NewX then
  2305.                     NewNX = NewNX - (NewX - #TLines[EditLine])
  2306.                     NewX = #TLines[EditLine]
  2307.                 end
  2308.                 EditX = NewX
  2309.                 EditNX = NewNX
  2310.                 CheckScroll()
  2311.             end
  2312.  
  2313.             Num:Draw()
  2314.             term.setCursorPos(EditNX + NWidth + 1, EditNLine + 1)
  2315.             term.setCursorBlink(true)
  2316.         elseif Event == "key" then
  2317.             if P1 == 29 then
  2318.                 CloseMenu()
  2319.             elseif P1 == 205 then
  2320.                 if ActiveMenu == FileM then
  2321.                     OpenMenu(EditM)
  2322.                 elseif ActiveMenu == EditM then
  2323.                     OpenMenu(RunM)
  2324.                 elseif ActiveMenu == RunM then
  2325.                     OpenMenu(FileM)
  2326.                 end
  2327.             elseif P1 == 203 then
  2328.                 if ActiveMenu == FileM then
  2329.                     OpenMenu(RunM)
  2330.                 elseif ActiveMenu == EditM then
  2331.                     OpenMenu(FileM)
  2332.                 elseif ActiveMenu == RunM then
  2333.                     OpenMenu(EditM)
  2334.                 end
  2335.             elseif ActiveMenu == FileM then
  2336.                 if P1 == 31 then
  2337.                     SaveTog()
  2338.                 elseif P1 == 16 then
  2339.                     Quit()
  2340.                 end
  2341.             elseif ActiveMenu == EditM then
  2342.                 if P1 == 46 then
  2343.                     Copy()
  2344.                     sleep(0)
  2345.                 elseif P1 == 25 then
  2346.                     Paste()
  2347.                     sleep(0)
  2348.                 elseif P1 == 32 then
  2349.                     Delete()
  2350.                     sleep(0)
  2351.                 end
  2352.             end
  2353.         end
  2354.     end
  2355. end
  2356.  
  2357. MainUI:Output(OutputF)
  2358. MainUI:Draw()
  2359.  
  2360. TLines[1] = ""
  2361.  
  2362. if FilePath and fs.exists(FilePath) and not fs.isDir(FilePath) then
  2363.     TLines = {}
  2364.     local File = fs.open(FilePath, "r")
  2365.     local Line
  2366.     repeat
  2367.         Line = File.readLine()
  2368.         if Line then
  2369.             table.insert(TLines, Line)
  2370.         end
  2371.     until Line == nil
  2372. end
  2373.  
  2374.  
  2375.  
  2376. DisplayLines()
  2377.  
  2378. MainUI:Listen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement