Advertisement
Symmetryc

Split

Feb 16th, 2014
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.80 KB | None | 0 0
  1. -- Split, by Symmetryc
  2. local arg = {...}
  3. assert(#arg == 2, "Usage: "..shell.getRunningProgram().." <menu_file> <program_file>")
  4. local max_x, max_y = term.getSize()
  5. local new_term = {}
  6. -- pos_x, pos_y, back, text
  7. local menu = {
  8.     pos_x = 1;
  9.     pos_y = 1;
  10.     back = 1;
  11.     text = 1;
  12. }
  13. local prog = {
  14.     pos_x = 1;
  15.     pos_y = 2;
  16.     back = 1;
  17.     text = 1;
  18.     width = max_x;
  19.     height = max_y - 1;
  20.     offset = 1;
  21. }
  22. new_term[1] = { -- menu
  23.     setTextColor = function(_n)
  24.         menu.text = _n
  25.     end;
  26.     setBackgroundColor = function(_n)
  27.         menu.back = _n
  28.     end;
  29.     setCursorPos = function(_x, _y)
  30.         menu.pos_x, menu.pos_y = _x, _y;
  31.     end;
  32.     getCursorPos = function()
  33.         return menu.pos_x, menu.pos_y
  34.     end;
  35.     write = function(_str)
  36.         term.setTextColor(menu.text)
  37.         term.setBackgroundColor(menu.back)
  38.         term.setCursorPos(menu.pos_x, menu.pos_y)
  39.         term.write(_str)
  40.         term.setTextColor(prog.text)
  41.         term.setBackgroundColor(prog.back)
  42.         term.setCursorPos(prog.pos_x, prog.pos_y)
  43.     end;
  44. }
  45. new_term[2] = { -- prog
  46.     getSize = function()
  47.         return prog.width, prog.height
  48.     end;
  49.     setTextColor = function(_n)
  50.         prog.text = _n
  51.         term.setTextColor(_n)
  52.     end;
  53.     setBackgroundColor = function(_n)
  54.         prog.back = _n
  55.         term.setBackgroundColor(_n)
  56.     end;
  57.     setCursorPos = function(_x, _y)
  58.         prog.pos_x = _x
  59.         prog.pos_y = _y + prog.offset
  60.         term.setCursorPos(_x, prog.pos_y)
  61.     end;
  62.     getCursorPos = function()
  63.         return prog.pos_x, prog.pos_y - prog.offset
  64.     end;
  65.     write = function(_str)
  66.         if prog.pos_y >= prog.offset + 1 then
  67.             term.write(_str)
  68.         end
  69.     end;
  70. }
  71. local f = {}
  72. for i, v in ipairs(arg) do
  73.     new_term[i].setTextColour = new_term[i].setTextColor
  74.     new_term[i].setBackgroundColour = new_term[i].setBackgroundColor
  75.     f[i] = setfenv(loadfile(v), setmetatable({term = new_term[i]}, {__index = _G}))
  76. end
  77. return parallel.waitForAny(unpack(f))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement