Advertisement
Alakazard12

NoveCode OC Port

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