Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Split, by Symmetryc
- local arg = {...}
- assert(#arg == 2, "Usage: "..shell.getRunningProgram().." <menu_file> <program_file>")
- local max_x, max_y = term.getSize()
- local new_term = {}
- -- pos_x, pos_y, back, text
- local menu = {
- pos_x = 1;
- pos_y = 1;
- back = 1;
- text = 1;
- }
- local prog = {
- pos_x = 1;
- pos_y = 2;
- back = 1;
- text = 1;
- width = max_x;
- height = max_y - 1;
- offset = 1;
- }
- new_term[1] = { -- menu
- setTextColor = function(_n)
- menu.text = _n
- end;
- setBackgroundColor = function(_n)
- menu.back = _n
- end;
- setCursorPos = function(_x, _y)
- menu.pos_x, menu.pos_y = _x, _y;
- end;
- getCursorPos = function()
- return menu.pos_x, menu.pos_y
- end;
- write = function(_str)
- term.setTextColor(menu.text)
- term.setBackgroundColor(menu.back)
- term.setCursorPos(menu.pos_x, menu.pos_y)
- term.write(_str)
- term.setTextColor(prog.text)
- term.setBackgroundColor(prog.back)
- term.setCursorPos(prog.pos_x, prog.pos_y)
- end;
- }
- new_term[2] = { -- prog
- getSize = function()
- return prog.width, prog.height
- end;
- setTextColor = function(_n)
- prog.text = _n
- term.setTextColor(_n)
- end;
- setBackgroundColor = function(_n)
- prog.back = _n
- term.setBackgroundColor(_n)
- end;
- setCursorPos = function(_x, _y)
- prog.pos_x = _x
- prog.pos_y = _y + prog.offset
- term.setCursorPos(_x, prog.pos_y)
- end;
- getCursorPos = function()
- return prog.pos_x, prog.pos_y - prog.offset
- end;
- write = function(_str)
- if prog.pos_y >= prog.offset + 1 then
- term.write(_str)
- end
- end;
- }
- local f = {}
- for i, v in ipairs(arg) do
- new_term[i].setTextColour = new_term[i].setTextColor
- new_term[i].setBackgroundColour = new_term[i].setBackgroundColor
- f[i] = setfenv(loadfile(v), setmetatable({term = new_term[i]}, {__index = _G}))
- end
- return parallel.waitForAny(unpack(f))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement