2019-04-21 05:26:09 +00:00
|
|
|
-- Workspaces for ComputerCraft
|
|
|
|
-- by LDDestroier
|
|
|
|
|
2019-04-23 18:35:15 +00:00
|
|
|
local tArg = {...}
|
|
|
|
|
2019-04-26 00:00:10 +00:00
|
|
|
local instances = {}
|
|
|
|
local configPath = ".workspace_config" -- finish later
|
2019-06-18 15:08:52 +00:00
|
|
|
|
|
|
|
-- a custom shell that records the last ran program
|
|
|
|
local customShell = function()
|
|
|
|
local sHistory = {}
|
|
|
|
term.setTextColor(colors.yellow)
|
|
|
|
term.setBackgroundColor(colors.black)
|
|
|
|
term.clear()
|
|
|
|
term.setCursorPos(1, 1)
|
|
|
|
term.write(os.version() .. " (Workspace)")
|
|
|
|
term.setCursorPos(1, 2)
|
|
|
|
|
|
|
|
-- some code is directly taken from rom/programs/shell.lua
|
|
|
|
-- oh well
|
|
|
|
|
|
|
|
local input
|
|
|
|
while true do
|
|
|
|
term.setTextColor(colors.yellow)
|
|
|
|
write( shell.dir() .. "> " )
|
|
|
|
term.setTextColor(colors.white)
|
|
|
|
if settings.get( "shell.autocomplete" ) then
|
|
|
|
input = read( nil, tCommandHistory, shell.complete )
|
|
|
|
else
|
|
|
|
input = read( nil, tCommandHistory )
|
|
|
|
end
|
|
|
|
if input:match("%S") and sHistory[#sHistory] ~= input then
|
|
|
|
sHistory[#sHistory + 1] = input
|
|
|
|
end
|
|
|
|
shell.run(input)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-26 00:00:10 +00:00
|
|
|
local config = {
|
|
|
|
workspaceMoveSpeed = 0.1,
|
|
|
|
defaultProgram = "rom/programs/shell.lua",
|
|
|
|
timesRan = 0,
|
|
|
|
WSmap = {
|
|
|
|
{true,true,true},
|
|
|
|
{true,true,true},
|
|
|
|
{true,true,true},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
-- values determined after every new/removed workspace
|
|
|
|
local gridWidth, gridHeight, gridMinX, gridMinY
|
|
|
|
|
2019-06-18 15:08:52 +00:00
|
|
|
-- used by argument parser
|
|
|
|
local argList, argErrors
|
|
|
|
|
2019-04-26 00:00:10 +00:00
|
|
|
local getMapSize = function()
|
|
|
|
local xmax, xmin, ymax, ymin = -math.huge, math.huge, -math.huge, math.huge
|
|
|
|
local isRowEmpty
|
|
|
|
for y, v in pairs(config.WSmap) do
|
|
|
|
isRowEmpty = true
|
|
|
|
for x, vv in pairs(v) do
|
|
|
|
if vv then
|
|
|
|
xmin = math.min(xmin, x)
|
|
|
|
xmax = math.max(xmax, x)
|
|
|
|
isRowEmpty = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not isRowEmpty then
|
|
|
|
ymin = math.min(ymin, y)
|
|
|
|
ymax = math.max(ymax, y)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return xmax, ymax, xmin, ymin
|
|
|
|
end
|
|
|
|
|
|
|
|
local saveConfig = function()
|
|
|
|
local file = fs.open(configPath, "w")
|
|
|
|
file.write( textutils.serialize(config) )
|
|
|
|
file.close()
|
|
|
|
end
|
|
|
|
|
|
|
|
local loadConfig = function()
|
|
|
|
if fs.exists(configPath) then
|
|
|
|
local file = fs.open(configPath, "r")
|
|
|
|
local contents = file.readAll()
|
|
|
|
file.close()
|
|
|
|
local newConfig = textutils.unserialize(contents)
|
|
|
|
for k,v in pairs(newConfig) do
|
|
|
|
config[k] = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
loadConfig()
|
|
|
|
saveConfig()
|
|
|
|
|
|
|
|
local keysDown = {}
|
2019-04-23 21:01:40 +00:00
|
|
|
|
|
|
|
-- amount of time (seconds) until workspace indicator disappears
|
|
|
|
local workspaceIndicatorDuration = 0.6
|
|
|
|
|
|
|
|
-- if held down while moving workspace, will swap positions
|
|
|
|
local swapKey = keys.tab
|
2019-04-23 18:35:15 +00:00
|
|
|
|
2019-04-20 01:46:43 +00:00
|
|
|
local scr_x, scr_y = term.getSize()
|
|
|
|
local windowWidth = scr_x
|
|
|
|
local windowHeight = scr_y
|
2019-04-23 21:01:40 +00:00
|
|
|
local doDrawWorkspaceIndicator = false
|
2019-04-21 05:26:09 +00:00
|
|
|
|
2019-04-23 21:01:40 +00:00
|
|
|
local scroll = {0,0} -- change this value when scrolling
|
|
|
|
local realScroll = {0,0} -- this value changes depending on scroll for smoothness purposes
|
2019-04-26 00:00:10 +00:00
|
|
|
local focus = {} -- currently focused instance, declared when loading from config
|
2019-04-23 21:01:40 +00:00
|
|
|
|
2019-04-21 05:44:03 +00:00
|
|
|
local isRunning = true
|
|
|
|
|
2019-04-23 21:01:40 +00:00
|
|
|
local cwrite = function(text, y, terminal)
|
|
|
|
terminal = terminal or term.current()
|
|
|
|
local cx, cy = terminal.getCursorPos()
|
|
|
|
local sx, sy = terminal.getSize()
|
|
|
|
terminal.setCursorPos(sx / 2 - #text / 2, y or (sy / 2))
|
|
|
|
terminal.write(text)
|
|
|
|
end
|
|
|
|
|
2019-04-21 05:26:09 +00:00
|
|
|
-- start up lddterm
|
2019-04-20 01:46:43 +00:00
|
|
|
local lddterm = {}
|
|
|
|
lddterm.alwaysRender = false -- renders after any and all screen-changing functions.
|
2019-04-23 18:35:15 +00:00
|
|
|
lddterm.useColors = true -- normal computers do not allow color, but this variable doesn't do anything yet
|
2019-04-20 01:46:43 +00:00
|
|
|
lddterm.baseTerm = term.current() -- will draw to this terminal
|
|
|
|
lddterm.transformation = nil -- will modify the current buffer as an NFT image before rendering
|
|
|
|
lddterm.cursorTransformation = nil -- will modify the cursor position
|
2019-04-23 18:35:15 +00:00
|
|
|
lddterm.drawFunction = nil -- will draw using this function instead of basic NFT drawing
|
|
|
|
lddterm.adjustX = 0 -- moves entire screen X
|
|
|
|
lddterm.adjustY = 0 -- moves entire screen Y
|
|
|
|
lddterm.selectedWindow = 1 -- determines which window controls the cursor
|
2019-04-20 01:46:43 +00:00
|
|
|
lddterm.windows = {}
|
|
|
|
|
2019-04-23 21:01:40 +00:00
|
|
|
local drawWorkspaceIndicator = function(terminal)
|
2019-04-26 00:00:10 +00:00
|
|
|
gridWidth, gridHeight, gridMinX, gridMinY = getMapSize()
|
2019-04-23 21:01:40 +00:00
|
|
|
terminal = terminal or lddterm.baseTerm
|
2019-04-26 00:00:10 +00:00
|
|
|
for y = gridMinY - 1, gridHeight + 1 do
|
|
|
|
for x = gridMinX - 1, gridWidth + 1 do
|
|
|
|
term.setCursorPos((x - gridMinX) + scr_x / 2 - (gridWidth - gridMinX) / 2, (y - gridMinY) + scr_y / 2 - (gridHeight - gridMinY) / 2)
|
2019-04-23 21:01:40 +00:00
|
|
|
if instances[y] then
|
|
|
|
if instances[y][x] then
|
|
|
|
if focus[1] == x and focus[2] == y then
|
|
|
|
term.blit(" ", "8", "8")
|
2019-04-23 21:18:01 +00:00
|
|
|
elseif instances[y][x].active then
|
2019-04-23 21:01:40 +00:00
|
|
|
term.blit(" ", "7", "7")
|
2019-04-23 21:18:01 +00:00
|
|
|
else
|
|
|
|
term.blit(" ", "f", "f")
|
2019-04-23 21:01:40 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
term.blit(" ", "0", "0")
|
|
|
|
end
|
|
|
|
else
|
|
|
|
term.blit(" ", "0", "0")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-20 01:46:43 +00:00
|
|
|
-- converts hex colors to colors api, and back
|
|
|
|
local to_colors, to_blit = {
|
|
|
|
[' '] = 0,
|
|
|
|
['0'] = 1,
|
|
|
|
['1'] = 2,
|
|
|
|
['2'] = 4,
|
|
|
|
['3'] = 8,
|
|
|
|
['4'] = 16,
|
|
|
|
['5'] = 32,
|
|
|
|
['6'] = 64,
|
|
|
|
['7'] = 128,
|
|
|
|
['8'] = 256,
|
|
|
|
['9'] = 512,
|
|
|
|
['a'] = 1024,
|
|
|
|
['b'] = 2048,
|
|
|
|
['c'] = 4096,
|
|
|
|
['d'] = 8192,
|
|
|
|
['e'] = 16384,
|
|
|
|
['f'] = 32768,
|
|
|
|
}, {}
|
|
|
|
for k,v in pairs(to_colors) do
|
|
|
|
to_blit[v] = k
|
|
|
|
end
|
|
|
|
|
|
|
|
-- separates string into table based on divider
|
|
|
|
local explode = function(div, str, replstr, includeDiv)
|
|
|
|
if (div == '') then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
local pos, arr = 0, {}
|
|
|
|
for st, sp in function() return string.find(str, div, pos, false) end do
|
|
|
|
table.insert(arr, string.sub(replstr or str, pos, st - 1 + (includeDiv and #div or 0)))
|
|
|
|
pos = sp + 1
|
|
|
|
end
|
|
|
|
table.insert(arr, string.sub(replstr or str, pos))
|
|
|
|
return arr
|
|
|
|
end
|
|
|
|
|
|
|
|
-- determines the size of the terminal before rendering always
|
|
|
|
local determineScreenSize = function()
|
|
|
|
scr_x, scr_y = lddterm.baseTerm.getSize()
|
|
|
|
lddterm.screenWidth = scr_x
|
|
|
|
lddterm.screenHeight = scr_y
|
|
|
|
end
|
|
|
|
|
|
|
|
determineScreenSize()
|
|
|
|
|
|
|
|
-- takes two or more windows and checks if the first of them overlap the other(s)
|
|
|
|
lddterm.checkWindowOverlap = function(window, ...)
|
|
|
|
if #lddterm.windows < 2 then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
local list, win = {...}
|
|
|
|
for i = 1, #list do
|
|
|
|
win = list[i]
|
|
|
|
if win ~= window then
|
|
|
|
|
|
|
|
if (
|
|
|
|
window.x < win.x + win.width and
|
|
|
|
win.x < window.x + window.width and
|
|
|
|
window.y < win.y + win.height and
|
|
|
|
win.y < window.y + window.height
|
|
|
|
) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
local fixCursorPos = function()
|
|
|
|
local cx, cy
|
|
|
|
if lddterm.windows[lddterm.selectedWindow] then
|
|
|
|
if lddterm.cursorTransformation then
|
|
|
|
cx, cy = lddterm.cursorTransformation(
|
|
|
|
lddterm.windows[lddterm.selectedWindow].cursor[1],
|
|
|
|
lddterm.windows[lddterm.selectedWindow].cursor[2]
|
|
|
|
)
|
|
|
|
lddterm.baseTerm.setCursorPos(
|
|
|
|
cx + lddterm.windows[lddterm.selectedWindow].x - 1,
|
|
|
|
cy + lddterm.windows[lddterm.selectedWindow].y - 1
|
|
|
|
)
|
|
|
|
else
|
|
|
|
lddterm.baseTerm.setCursorPos(
|
|
|
|
-1 + lddterm.windows[lddterm.selectedWindow].cursor[1] + lddterm.windows[lddterm.selectedWindow].x,
|
|
|
|
lddterm.windows[lddterm.selectedWindow].cursor[2] + lddterm.windows[lddterm.selectedWindow].y - 1
|
|
|
|
)
|
|
|
|
end
|
2019-04-21 05:26:09 +00:00
|
|
|
lddterm.baseTerm.setCursorBlink(lddterm.windows[lddterm.selectedWindow].blink)
|
2019-04-20 01:46:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- renders the screen with optional transformation function
|
|
|
|
lddterm.render = function(transformation, drawFunction)
|
|
|
|
-- determine new screen size and change lddterm screen to fit
|
|
|
|
old_scr_x, old_scr_y = scr_x, scr_y
|
|
|
|
determineScreenSize()
|
|
|
|
if old_scr_x ~= scr_x or old_scr_y ~= scr_y then
|
|
|
|
lddterm.baseTerm.clear()
|
|
|
|
end
|
|
|
|
local image = lddterm.screenshot()
|
|
|
|
if type(transformation) == "function" then
|
|
|
|
image = transformation(image)
|
|
|
|
end
|
|
|
|
if drawFunction then
|
|
|
|
drawFunction(image, lddterm.baseTerm)
|
|
|
|
else
|
|
|
|
for y = 1, #image[1] do
|
|
|
|
lddterm.baseTerm.setCursorPos(1 + lddterm.adjustX, y + lddterm.adjustY)
|
|
|
|
lddterm.baseTerm.blit(image[1][y], image[2][y], image[3][y])
|
|
|
|
end
|
|
|
|
end
|
2019-04-23 21:01:40 +00:00
|
|
|
if doDrawWorkspaceIndicator then
|
|
|
|
drawWorkspaceIndicator()
|
|
|
|
end
|
2019-04-20 01:46:43 +00:00
|
|
|
fixCursorPos()
|
|
|
|
end
|
|
|
|
|
|
|
|
lddterm.newWindow = function(width, height, x, y, meta)
|
|
|
|
meta = meta or {}
|
|
|
|
local window = {
|
|
|
|
width = math.floor(width),
|
|
|
|
height = math.floor(height),
|
2019-04-21 05:26:09 +00:00
|
|
|
blink = true,
|
2019-04-20 01:46:43 +00:00
|
|
|
cursor = meta.cursor or {1, 1},
|
|
|
|
colors = meta.colors or {"0", "f"},
|
|
|
|
clearChar = meta.clearChar or " ",
|
|
|
|
visible = meta.visible or true,
|
|
|
|
x = math.floor(x) or 1,
|
|
|
|
y = math.floor(y) or 1,
|
|
|
|
buffer = {{},{},{}},
|
|
|
|
}
|
|
|
|
for y = 1, height do
|
|
|
|
window.buffer[1][y] = {}
|
|
|
|
window.buffer[2][y] = {}
|
|
|
|
window.buffer[3][y] = {}
|
|
|
|
for x = 1, width do
|
|
|
|
window.buffer[1][y][x] = window.clearChar
|
|
|
|
window.buffer[2][y][x] = window.colors[1]
|
|
|
|
window.buffer[3][y][x] = window.colors[2]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
window.handle = {}
|
|
|
|
window.handle.setCursorPos = function(x, y)
|
|
|
|
window.cursor = {x, y}
|
|
|
|
fixCursorPos()
|
|
|
|
end
|
|
|
|
window.handle.getCursorPos = function()
|
|
|
|
return window.cursor[1], window.cursor[2]
|
|
|
|
end
|
|
|
|
window.handle.setCursorBlink = function(blink)
|
2019-04-21 05:26:09 +00:00
|
|
|
window.blink = blink or false
|
2019-04-20 01:46:43 +00:00
|
|
|
end
|
|
|
|
window.handle.getCursorBlink = function()
|
2019-04-21 05:26:09 +00:00
|
|
|
return window.blink
|
2019-04-20 01:46:43 +00:00
|
|
|
end
|
|
|
|
window.handle.scroll = function(amount)
|
|
|
|
if amount > 0 then
|
|
|
|
for i = 1, amount do
|
|
|
|
for c = 1, 3 do
|
|
|
|
table.remove(window.buffer[c], 1)
|
|
|
|
window.buffer[c][window.height] = {}
|
|
|
|
for xx = 1, width do
|
|
|
|
window.buffer[c][window.height][xx] = (
|
|
|
|
c == 1 and window.clearChar or
|
|
|
|
c == 2 and window.colors[1] or
|
|
|
|
c == 3 and window.colors[2]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif amount < 0 then
|
|
|
|
for i = 1, -amount do
|
|
|
|
for c = 1, 3 do
|
|
|
|
window.buffer[c][window.height] = nil
|
|
|
|
table.insert(window.buffer[c], 1, {})
|
|
|
|
for xx = 1, width do
|
|
|
|
window.buffer[c][1][xx] = (
|
|
|
|
c == 1 and window.clearChar or
|
|
|
|
c == 2 and window.colors[1] or
|
|
|
|
c == 3 and window.colors[2]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if lddterm.alwaysRender then
|
|
|
|
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
window.handle.scrollX = function(amount)
|
|
|
|
if amount > 0 then
|
|
|
|
for i = 1, amount do
|
|
|
|
for c = 1, 3 do
|
|
|
|
for y = 1, window.height do
|
|
|
|
table.remove(window.buffer[c][y], 1)
|
|
|
|
window.buffer[c][y][window.width] = (
|
|
|
|
c == 1 and window.clearChar or
|
|
|
|
c == 2 and window.colors[1] or
|
|
|
|
c == 3 and window.colors[2]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif amount < 0 then
|
|
|
|
for i = 1, -amount do
|
|
|
|
for c = 1, 3 do
|
|
|
|
for y = 1, window.height do
|
|
|
|
window.buffer[c][y][window.width] = nil
|
|
|
|
table.insert(window.buffer[c][y], 1, (
|
|
|
|
c == 1 and window.clearChar or
|
|
|
|
c == 2 and window.colors[1] or
|
|
|
|
c == 3 and window.colors[2]
|
|
|
|
))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if lddterm.alwaysRender then
|
|
|
|
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
window.handle.write = function(text, x, y, ignoreAlwaysRender)
|
|
|
|
assert(text ~= nil, "expected string 'text'")
|
|
|
|
text = tostring(text)
|
|
|
|
local cx = math.floor(tonumber(x) or window.cursor[1])
|
|
|
|
local cy = math.floor(tonumber(y) or window.cursor[2])
|
|
|
|
text = text:sub(math.max(0, -cx - 1))
|
|
|
|
for i = 1, #text do
|
|
|
|
if cx >= 1 and cx <= window.width and cy >= 1 and cy <= window.height then
|
|
|
|
window.buffer[1][cy][cx] = text:sub(i,i)
|
|
|
|
window.buffer[2][cy][cx] = window.colors[1]
|
|
|
|
window.buffer[3][cy][cx] = window.colors[2]
|
|
|
|
end
|
|
|
|
cx = math.min(cx + 1, window.width + 1)
|
|
|
|
end
|
|
|
|
window.cursor = {cx, cy}
|
|
|
|
if lddterm.alwaysRender and not ignoreAlwaysRender then
|
|
|
|
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
window.handle.writeWrap = function(text, x, y, ignoreAlwaysRender)
|
|
|
|
local words = explode(" ", text, nil, true)
|
|
|
|
local cx, cy = x or window.cursor[1], y or window.cursor[2]
|
|
|
|
for i = 1, #words do
|
|
|
|
if cx + #words[i] > window.width + 1 then
|
|
|
|
cx = 1
|
|
|
|
if cy >= window.height then
|
|
|
|
window.handle.scroll(1)
|
|
|
|
cy = window.height
|
|
|
|
else
|
|
|
|
cy = cy + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
window.handle.write(words[i], cx, cy, true)
|
|
|
|
cx = cx + #words[i]
|
|
|
|
end
|
|
|
|
if lddterm.alwaysRender and not ignoreAlwaysRender then
|
|
|
|
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
window.handle.blit = function(char, textCol, backCol, x, y)
|
|
|
|
if type(char) == "number" then
|
|
|
|
char = tostring(char)
|
|
|
|
end
|
|
|
|
if type(textCol) == "number" then
|
|
|
|
textCol = tostring(textCol)
|
|
|
|
end
|
|
|
|
if type(backCol) == "number" then
|
|
|
|
backCol = tostring(backCol)
|
|
|
|
end
|
|
|
|
assert(char ~= nil, "expected string 'char'")
|
|
|
|
local cx = math.floor(tonumber(x) or window.cursor[1])
|
|
|
|
local cy = math.floor(tonumber(y) or window.cursor[2])
|
|
|
|
char = char:sub(math.max(0, -cx - 1))
|
|
|
|
for i = 1, #char do
|
|
|
|
if cx >= 1 and cx <= window.width and cy >= 1 and cy <= window.height then
|
|
|
|
window.buffer[1][cy][cx] = char:sub(i,i)
|
|
|
|
window.buffer[2][cy][cx] = textCol:sub(i,i)
|
|
|
|
window.buffer[3][cy][cx] = backCol:sub(i,i)
|
|
|
|
end
|
2019-04-23 18:35:15 +00:00
|
|
|
cx = cx + 1
|
2019-04-20 01:46:43 +00:00
|
|
|
end
|
|
|
|
window.cursor = {cx, cy}
|
|
|
|
if lddterm.alwaysRender and not ignoreAlwaysRender then
|
|
|
|
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
window.handle.print = function(text, x, y)
|
|
|
|
text = text and tostring(text)
|
|
|
|
window.handle.write(text, x, y, true)
|
|
|
|
window.cursor[1] = 1
|
|
|
|
if window.cursor[2] >= window.height then
|
|
|
|
window.handle.scroll(1)
|
|
|
|
else
|
|
|
|
window.cursor[2] = window.cursor[2] + 1
|
|
|
|
if lddterm.alwaysRender then
|
|
|
|
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
window.handle.clear = function(char, ignoreAlwaysRender)
|
|
|
|
local cx = 1
|
|
|
|
for y = 1, window.height do
|
|
|
|
for x = 1, window.width do
|
|
|
|
if char then
|
|
|
|
cx = (x % #char) + 1
|
|
|
|
end
|
|
|
|
window.buffer[1][y][x] = char and char:sub(cx, cx) or window.clearChar
|
|
|
|
window.buffer[2][y][x] = window.colors[1]
|
|
|
|
window.buffer[3][y][x] = window.colors[2]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if lddterm.alwaysRender and not ignoreAlwaysRender then
|
|
|
|
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
window.handle.clearLine = function(cy, char, ignoreAlwaysRender)
|
|
|
|
cy = math.floor(cy or window.cursor[2])
|
|
|
|
local cx = 1
|
|
|
|
for x = 1, window.width do
|
|
|
|
if char then
|
|
|
|
cx = (x % #char) + 1
|
|
|
|
end
|
|
|
|
window.buffer[1][cy or window.cursor[2]][x] = char and char:sub(cx, cx) or window.clearChar
|
|
|
|
window.buffer[2][cy or window.cursor[2]][x] = window.colors[1]
|
|
|
|
window.buffer[3][cy or window.cursor[2]][x] = window.colors[2]
|
|
|
|
end
|
|
|
|
if lddterm.alwaysRender and not ignoreAlwaysRender then
|
|
|
|
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
window.handle.clearColumn = function(cx, char, ignoreAlwaysRender)
|
|
|
|
cx = math.floor(cx)
|
|
|
|
char = char and char:sub(1,1)
|
|
|
|
for y = 1, window.height do
|
|
|
|
window.buffer[1][y][cx or window.cursor[1]] = char and char or window.clearChar
|
|
|
|
window.buffer[2][y][cx or window.cursor[1]] = window.colors[1]
|
|
|
|
window.buffer[3][y][cx or window.cursor[1]] = window.colors[2]
|
|
|
|
end
|
|
|
|
if lddterm.alwaysRender and not ignoreAlwaysRender then
|
|
|
|
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
window.handle.getSize = function()
|
|
|
|
return window.width, window.height
|
|
|
|
end
|
|
|
|
window.handle.isColor = function()
|
|
|
|
return lddterm.useColors
|
|
|
|
end
|
|
|
|
window.handle.isColour = window.handle.isColor
|
|
|
|
window.handle.setTextColor = function(color)
|
|
|
|
if to_blit[color] then
|
|
|
|
window.colors[1] = to_blit[color]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
window.handle.setTextColour = window.handle.setTextColor
|
|
|
|
window.handle.setBackgroundColor = function(color)
|
|
|
|
if to_blit[color] then
|
|
|
|
window.colors[2] = to_blit[color]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
window.handle.setBackgroundColour = window.handle.setBackgroundColor
|
|
|
|
window.handle.getTextColor = function()
|
|
|
|
return to_colors[window.colors[1]] or colors.white
|
|
|
|
end
|
|
|
|
window.handle.getTextColour = window.handle.getTextColor
|
|
|
|
window.handle.getBackgroundColor = function()
|
|
|
|
return to_colors[window.colors[2]] or colors.black
|
|
|
|
end
|
|
|
|
window.handle.getBackgroundColour = window.handle.getBackgroundColor
|
|
|
|
window.handle.reposition = function(x, y)
|
|
|
|
window.x = math.floor(x or window.x)
|
|
|
|
window.y = math.floor(y or window.y)
|
|
|
|
if lddterm.alwaysRender then
|
|
|
|
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
window.handle.setPaletteColor = function(...)
|
|
|
|
return lddterm.baseTerm.setPaletteColor(...)
|
|
|
|
end
|
|
|
|
window.handle.setPaletteColour = window.handle.setPaletteColor
|
|
|
|
window.handle.getPaletteColor = function(...)
|
|
|
|
return lddterm.baseTerm.getPaletteColor(...)
|
|
|
|
end
|
|
|
|
window.handle.getPaletteColour = window.handle.getPaletteColor
|
|
|
|
window.handle.getPosition = function()
|
|
|
|
return window.x, window.y
|
|
|
|
end
|
|
|
|
window.handle.restoreCursor = function()
|
|
|
|
lddterm.baseTerm.setCursorPos(
|
|
|
|
-1 + window.cursor[1] + window.x,
|
|
|
|
window.cursor[2] + window.y - 1
|
|
|
|
)
|
|
|
|
end
|
|
|
|
window.handle.setVisible = function(visible)
|
|
|
|
window.visible = visible or false
|
|
|
|
end
|
|
|
|
|
|
|
|
window.handle.redraw = lddterm.render
|
2019-04-23 18:35:15 +00:00
|
|
|
window.handle.current = window.handle
|
2019-04-20 01:46:43 +00:00
|
|
|
|
|
|
|
window.layer = #lddterm.windows + 1
|
|
|
|
lddterm.windows[window.layer] = window
|
|
|
|
|
|
|
|
return window, window.layer
|
|
|
|
end
|
|
|
|
|
|
|
|
lddterm.setLayer = function(window, _layer)
|
|
|
|
local layer = math.max(1, math.min(#lddterm.windows, _layer))
|
|
|
|
|
|
|
|
local win = window
|
|
|
|
table.remove(lddterm.windows, win.layer)
|
|
|
|
table.insert(lddterm.windows, layer, win)
|
|
|
|
|
|
|
|
if lddterm.alwaysRender then
|
|
|
|
lddterm.render(lddterm.transformation, lddterm.drawFunction)
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
local old_scr_x, old_scr_y
|
|
|
|
|
|
|
|
-- gets screenshot of whole lddterm desktop, OR a single window
|
|
|
|
lddterm.screenshot = function(window)
|
|
|
|
local output = {{},{},{}}
|
|
|
|
local line
|
|
|
|
if window then
|
|
|
|
for y = 1, #window.buffer do
|
|
|
|
line = {"","",""}
|
|
|
|
for x = 1, #window.buffer do
|
|
|
|
line = {
|
|
|
|
line[1] .. window.buffer[1][y][x],
|
|
|
|
line[2] .. window.buffer[2][y][x],
|
|
|
|
line[3] .. window.buffer[3][y][x]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
output[1][y] = line[1]
|
|
|
|
output[2][y] = line[2]
|
|
|
|
output[3][y] = line[3]
|
|
|
|
end
|
|
|
|
else
|
|
|
|
for y = 1, scr_y do
|
|
|
|
line = {"","",""}
|
|
|
|
for x = 1, scr_x do
|
|
|
|
|
2019-04-26 00:00:10 +00:00
|
|
|
c = " "
|
2019-04-20 01:46:43 +00:00
|
|
|
lt, lb = t, b
|
|
|
|
t, b = "0", "f"
|
2019-04-26 00:00:10 +00:00
|
|
|
for l, v in pairs(lddterm.windows) do
|
|
|
|
if lddterm.windows[l] then
|
|
|
|
if lddterm.windows[l].visible then
|
|
|
|
sx = 1 + x - lddterm.windows[l].x
|
|
|
|
sy = 1 + y - lddterm.windows[l].y
|
|
|
|
if lddterm.windows[l].buffer[1][sy] then
|
|
|
|
if lddterm.windows[l].buffer[1][sy][sx] then
|
|
|
|
c = lddterm.windows[l].buffer[1][sy][sx] or c
|
|
|
|
t = lddterm.windows[l].buffer[2][sy][sx] or t
|
|
|
|
b = lddterm.windows[l].buffer[3][sy][sx] or b
|
|
|
|
break
|
|
|
|
end
|
2019-04-20 01:46:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
line = {
|
|
|
|
line[1] .. c,
|
|
|
|
line[2] .. t,
|
|
|
|
line[3] .. b
|
|
|
|
}
|
|
|
|
end
|
|
|
|
output[1][y] = line[1]
|
|
|
|
output[2][y] = line[2]
|
|
|
|
output[3][y] = line[3]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return output
|
|
|
|
end
|
|
|
|
|
2019-04-21 05:26:09 +00:00
|
|
|
local newInstance = function(x, y, program, initialStart)
|
2019-04-20 01:46:43 +00:00
|
|
|
x, y = math.floor(x), math.floor(y)
|
2019-04-26 00:00:10 +00:00
|
|
|
if instances[y] then
|
|
|
|
if instances[y][x] then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
gridWidth, gridHeight, gridMinX, gridMinY = getMapSize()
|
|
|
|
for yy = gridMinY, y do
|
2019-04-20 01:46:43 +00:00
|
|
|
instances[yy] = instances[yy] or {}
|
|
|
|
end
|
2019-04-26 00:00:10 +00:00
|
|
|
instances[y] = instances[y] or {}
|
|
|
|
for xx = gridMinX, x do
|
2019-04-20 01:46:43 +00:00
|
|
|
instances[y][xx] = instances[y][xx] or false
|
|
|
|
end
|
|
|
|
local window = lddterm.newWindow(windowWidth, windowHeight, 1, 1)
|
|
|
|
instances[y][x] = {
|
|
|
|
x = x,
|
|
|
|
y = y,
|
2019-04-23 21:18:01 +00:00
|
|
|
active = initialStart,
|
2019-06-18 15:08:52 +00:00
|
|
|
program = program or config.defaultProgram,
|
2019-04-20 01:46:43 +00:00
|
|
|
co = coroutine.create(function()
|
|
|
|
term.redirect(window.handle)
|
2019-04-23 18:35:15 +00:00
|
|
|
local evt
|
2019-04-21 05:26:09 +00:00
|
|
|
while true do
|
2019-04-23 18:35:15 +00:00
|
|
|
|
2019-04-21 05:26:09 +00:00
|
|
|
if initialStart then
|
2019-06-18 15:08:52 +00:00
|
|
|
if not instances[y][x].program or type(instances[y][x].program) == "string" then
|
|
|
|
shell.run(instances[y][x].program)
|
|
|
|
elseif type(instances[y][x].program) == "function" then
|
|
|
|
instances[y][x].program()
|
2019-04-21 05:26:09 +00:00
|
|
|
end
|
|
|
|
end
|
2019-04-23 18:35:15 +00:00
|
|
|
|
2019-04-23 21:18:01 +00:00
|
|
|
instances[y][x].active = false
|
2019-04-21 05:26:09 +00:00
|
|
|
term.clear()
|
|
|
|
term.setCursorBlink(false)
|
2019-04-23 21:01:40 +00:00
|
|
|
cwrite("This workspace is inactive.", 0 + scr_y / 2)
|
|
|
|
cwrite("Press SPACE to start the workspace.", 1 + scr_y / 2)
|
2019-06-18 15:08:52 +00:00
|
|
|
instances[y][x].program = config.defaultProgram
|
2019-04-21 05:26:09 +00:00
|
|
|
repeat
|
2019-04-21 05:44:03 +00:00
|
|
|
evt = {os.pullEventRaw()}
|
|
|
|
until (evt[1] == "key" and evt[2] == keys.space) or evt[1] == "terminate"
|
2019-04-21 05:26:09 +00:00
|
|
|
sleep(0)
|
2019-04-21 05:44:03 +00:00
|
|
|
if evt[1] == "terminate" then
|
|
|
|
isRunning = false
|
|
|
|
return
|
|
|
|
end
|
2019-04-23 18:35:15 +00:00
|
|
|
|
2019-04-21 05:26:09 +00:00
|
|
|
term.setCursorPos(1,1)
|
|
|
|
term.clear()
|
|
|
|
term.setCursorBlink(true)
|
2019-04-23 18:35:15 +00:00
|
|
|
|
2019-04-23 21:18:01 +00:00
|
|
|
instances[y][x].active = true
|
|
|
|
|
2019-04-21 05:26:09 +00:00
|
|
|
if not initialStart then
|
2019-06-18 15:08:52 +00:00
|
|
|
if not instances[y][x].program or type(instances[y][x].program) == "string" then
|
|
|
|
shell.run(instances[y][x].program)
|
|
|
|
elseif type(instances[y][x].program) == "function" then
|
|
|
|
instances[y][x].program()
|
2019-04-21 05:26:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2019-04-20 01:46:43 +00:00
|
|
|
end),
|
|
|
|
window = window
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-04-23 18:35:15 +00:00
|
|
|
-- prevents wiseassed-ness
|
2019-04-26 00:00:10 +00:00
|
|
|
config.workspaceMoveSpeed = math.min(math.max(config.workspaceMoveSpeed, 0.001), 1)
|
2019-04-23 18:35:15 +00:00
|
|
|
|
2019-04-20 01:46:43 +00:00
|
|
|
local scrollWindows = function()
|
2019-04-23 18:35:15 +00:00
|
|
|
local changed = false
|
|
|
|
if realScroll[1] < scroll[1] then
|
2019-04-26 00:00:10 +00:00
|
|
|
realScroll[1] = math.min(realScroll[1] + config.workspaceMoveSpeed, scroll[1])
|
2019-04-23 18:35:15 +00:00
|
|
|
changed = true
|
|
|
|
elseif realScroll[1] > scroll[1] then
|
2019-04-26 00:00:10 +00:00
|
|
|
realScroll[1] = math.max(realScroll[1] - config.workspaceMoveSpeed, scroll[1])
|
2019-04-23 18:35:15 +00:00
|
|
|
changed = true
|
|
|
|
end
|
|
|
|
if realScroll[2] < scroll[2] then
|
2019-04-26 00:00:10 +00:00
|
|
|
realScroll[2] = math.min(realScroll[2] + config.workspaceMoveSpeed, scroll[2])
|
2019-04-23 18:35:15 +00:00
|
|
|
changed = true
|
|
|
|
elseif realScroll[2] > scroll[2] then
|
2019-04-26 00:00:10 +00:00
|
|
|
realScroll[2] = math.max(realScroll[2] - config.workspaceMoveSpeed, scroll[2])
|
2019-04-23 18:35:15 +00:00
|
|
|
changed = true
|
|
|
|
end
|
2019-04-26 00:00:10 +00:00
|
|
|
gridWidth, gridHeight, gridMinX, gridMinY = getMapSize()
|
|
|
|
for y = gridMinY, gridHeight do
|
2019-04-20 01:46:43 +00:00
|
|
|
if instances[y] then
|
2019-04-26 00:00:10 +00:00
|
|
|
for x = gridMinX, gridWidth do
|
2019-04-20 01:46:43 +00:00
|
|
|
if instances[y][x] then
|
2019-04-23 18:35:15 +00:00
|
|
|
instances[y][x].window.x = math.floor(1 + (instances[y][x].x + realScroll[1] - 1) * scr_x)
|
|
|
|
instances[y][x].window.y = math.floor(1 + (instances[y][x].y + realScroll[2] - 1) * scr_y)
|
2019-04-20 01:46:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-04-23 18:35:15 +00:00
|
|
|
return changed
|
2019-04-20 01:46:43 +00:00
|
|
|
end
|
|
|
|
|
2019-04-23 21:01:40 +00:00
|
|
|
local swapInstances = function(xmod, ymod)
|
2019-04-24 02:29:01 +00:00
|
|
|
instances[focus[2]][focus[1]].co, instances[focus[2] + ymod][focus[1] + xmod].co = instances[focus[2] + ymod][focus[1] + xmod].co, instances[focus[2]][focus[1]].co
|
|
|
|
instances[focus[2]][focus[1]].window, instances[focus[2] + ymod][focus[1] + xmod].window = instances[focus[2] + ymod][focus[1] + xmod].window, instances[focus[2]][focus[1]].window
|
|
|
|
instances[focus[2]][focus[1]].active, instances[focus[2] + ymod][focus[1] + xmod].active = instances[focus[2] + ymod][focus[1] + xmod].active, instances[focus[2]][focus[1]].active
|
2019-04-23 21:01:40 +00:00
|
|
|
end
|
|
|
|
|
2019-04-26 00:00:10 +00:00
|
|
|
local addWorkspace = function(xmod, ymod)
|
|
|
|
config.WSmap[focus[2] + ymod] = config.WSmap[focus[2] + ymod] or {}
|
|
|
|
if not config.WSmap[focus[2] + ymod][focus[1] + xmod] then
|
2019-06-18 15:08:52 +00:00
|
|
|
config.WSmap[focus[2] + ymod][focus[1] + xmod] = instances[focus[2] + ymod][focus[1] + xmod].program
|
2019-04-26 00:00:10 +00:00
|
|
|
newInstance(focus[1] + xmod, focus[2] + ymod, config.defaultProgram, false)
|
|
|
|
saveConfig()
|
|
|
|
gridWidth, gridHeight, gridMinX, gridMinY = getMapSize()
|
|
|
|
else
|
|
|
|
-- print("There's already a workspace there.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local removeWorkspace = function(xmod, ymod)
|
|
|
|
if config.WSmap[focus[2] + ymod][focus[1] + xmod] then
|
|
|
|
local good = false
|
|
|
|
for y = -1, 1 do
|
|
|
|
for x = -1, 1 do
|
|
|
|
if math.abs(x) + math.abs(y) == 1 then
|
|
|
|
if instances[focus[2] + y] then
|
|
|
|
if instances[focus[2] + y][focus[1] + x] then
|
|
|
|
good = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if good then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if good then
|
|
|
|
lddterm.windows[instances[focus[2] + ymod][focus[1] + xmod].window.layer] = nil
|
|
|
|
config.WSmap[focus[2] + ymod][focus[1] + xmod] = nil
|
|
|
|
instances[focus[2] + ymod][focus[1] + xmod] = nil
|
|
|
|
local isRowEmpty
|
|
|
|
local remList = {}
|
|
|
|
for y, v in pairs(config.WSmap) do
|
|
|
|
isRowEmpty = true
|
|
|
|
for x, vv in pairs(v) do
|
|
|
|
if vv then
|
|
|
|
isRowEmpty = false
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if isRowEmpty then
|
|
|
|
remList[#remList + 1] = y
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for i = 1, #remList do
|
|
|
|
config.WSmap[remList[i]] = nil
|
|
|
|
end
|
|
|
|
saveConfig()
|
|
|
|
gridWidth, gridHeight, gridMinX, gridMinY = getMapSize()
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- print("There's no such workspace.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-18 15:08:52 +00:00
|
|
|
local displayHelp = function()
|
|
|
|
cwrite("CTRL+SHIFT+ARROW to switch workspace. ", -2 + scr_y / 2)
|
|
|
|
cwrite("CTRL+SHIFT+TAB+ARROW to swap. ", -1 + scr_y / 2)
|
|
|
|
cwrite("CTRL+SHIFT+[WASD] to create a workspace ", 0 + scr_y / 2)
|
|
|
|
cwrite("up/left/down/right respectively. ", 1 + scr_y / 2)
|
|
|
|
cwrite("CTRL+SHIFT+Q to delete a workspace. ", 2 + scr_y / 2)
|
|
|
|
cwrite("Terminate an inactive workspace to exit.", 3 + scr_y / 2)
|
|
|
|
end
|
|
|
|
|
2019-04-20 01:46:43 +00:00
|
|
|
local inputEvt = {
|
|
|
|
key = true,
|
|
|
|
key_up = true,
|
|
|
|
char = true,
|
|
|
|
mouse_click = true,
|
|
|
|
mouse_scroll = true,
|
|
|
|
mouse_drag = true,
|
|
|
|
mouse_up = true,
|
2019-04-21 06:01:03 +00:00
|
|
|
paste = true,
|
|
|
|
terminate = true
|
2019-04-20 01:46:43 +00:00
|
|
|
}
|
|
|
|
|
2019-06-18 15:08:52 +00:00
|
|
|
local checkIfCanRun = function(evt, x, y)
|
|
|
|
return (
|
|
|
|
(not inputEvt[evt[1]]) and
|
|
|
|
instances[y][x].active or (
|
|
|
|
x == focus[1] and
|
|
|
|
y == focus[2]
|
|
|
|
) and (
|
|
|
|
(not instances[y][x].eventFilter) or
|
|
|
|
instances[y][x].eventFilter == evt[1] or
|
|
|
|
evt[1] == "terminate"
|
|
|
|
)
|
|
|
|
)
|
2019-04-26 00:00:10 +00:00
|
|
|
end
|
|
|
|
|
2019-04-20 01:46:43 +00:00
|
|
|
local main = function()
|
|
|
|
local enteringCommand
|
2019-04-21 05:26:09 +00:00
|
|
|
local justStarted = true
|
2019-04-23 21:01:40 +00:00
|
|
|
local tID, wID
|
2019-06-18 15:08:52 +00:00
|
|
|
local pCounter, program = 0
|
2019-04-23 21:26:41 +00:00
|
|
|
|
2019-04-26 00:00:10 +00:00
|
|
|
for y, v in pairs(config.WSmap) do
|
|
|
|
for x, vv in pairs(v) do
|
2019-06-18 15:08:52 +00:00
|
|
|
pCounter = pCounter + 1
|
2019-04-26 00:00:10 +00:00
|
|
|
if vv then
|
|
|
|
if not focus[1] then
|
|
|
|
focus = {x, y}
|
|
|
|
end
|
2019-06-18 15:08:52 +00:00
|
|
|
program = (argList[pCounter] and fs.exists(argList[pCounter])) and argList[pCounter] or config.defaultProgram
|
|
|
|
newInstance(x, y, program, x == focus[1] and y == focus[2])
|
2019-04-26 00:00:10 +00:00
|
|
|
end
|
2019-04-23 21:26:41 +00:00
|
|
|
end
|
|
|
|
end
|
2019-04-26 00:00:10 +00:00
|
|
|
|
2019-04-23 21:26:41 +00:00
|
|
|
scrollWindows()
|
|
|
|
|
|
|
|
term.clear()
|
2019-04-26 00:00:10 +00:00
|
|
|
if config.timesRan <= 0 then
|
|
|
|
displayHelp()
|
|
|
|
sleep(0.1)
|
|
|
|
os.pullEvent("key")
|
|
|
|
|
|
|
|
os.queueEvent("mouse_click", 0, 0, 0)
|
|
|
|
end
|
2019-04-23 21:26:41 +00:00
|
|
|
|
2019-04-26 00:00:10 +00:00
|
|
|
config.timesRan = config.timesRan + 1
|
|
|
|
saveConfig()
|
2019-06-18 15:08:52 +00:00
|
|
|
|
|
|
|
local previousTerm, cSuccess
|
2019-04-23 21:26:41 +00:00
|
|
|
|
2019-04-21 05:44:03 +00:00
|
|
|
while isRunning do
|
2019-04-26 00:00:10 +00:00
|
|
|
gridWidth, gridHeight, gridMinX, gridMinY = getMapSize()
|
2019-04-20 01:46:43 +00:00
|
|
|
local evt = {os.pullEventRaw()}
|
|
|
|
enteringCommand = false
|
|
|
|
if evt[1] == "key" then
|
|
|
|
keysDown[evt[2]] = true
|
|
|
|
elseif evt[1] == "key_up" then
|
|
|
|
keysDown[evt[2]] = nil
|
2019-04-23 21:01:40 +00:00
|
|
|
elseif evt[1] == "timer" then
|
|
|
|
if evt[2] == wID then
|
|
|
|
enteringCommand = true
|
|
|
|
doDrawWorkspaceIndicator = false
|
|
|
|
elseif evt[2] == tID then
|
|
|
|
enteringCommand = true
|
|
|
|
end
|
2019-04-20 01:46:43 +00:00
|
|
|
end
|
2019-04-23 18:35:15 +00:00
|
|
|
|
|
|
|
if scrollWindows() then
|
|
|
|
tID = os.startTimer(0.05)
|
|
|
|
end
|
|
|
|
|
2019-04-23 21:01:40 +00:00
|
|
|
if (keysDown[keys.leftCtrl] or keysDown[keys.rightCtrl]) and (keysDown[keys.leftShift] or keysDown[keys.rightShift]) then
|
2019-04-20 01:46:43 +00:00
|
|
|
if keysDown[keys.left] then
|
|
|
|
if instances[focus[2]][focus[1] - 1] then
|
2019-04-23 21:01:40 +00:00
|
|
|
if keysDown[swapKey] then
|
|
|
|
swapInstances(-1, 0)
|
|
|
|
end
|
2019-04-20 01:46:43 +00:00
|
|
|
focus[1] = focus[1] - 1
|
2019-04-23 18:35:15 +00:00
|
|
|
scroll[1] = scroll[1] + 1
|
|
|
|
keysDown[keys.left] = false
|
2019-04-20 01:46:43 +00:00
|
|
|
enteringCommand = true
|
2019-04-23 21:01:40 +00:00
|
|
|
doDrawWorkspaceIndicator = true
|
|
|
|
wID = os.startTimer(workspaceIndicatorDuration)
|
2019-04-20 01:46:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if keysDown[keys.right] then
|
|
|
|
if instances[focus[2]][focus[1] + 1] then
|
2019-04-23 21:01:40 +00:00
|
|
|
if keysDown[swapKey] then
|
|
|
|
swapInstances(1, 0)
|
|
|
|
end
|
2019-04-20 01:46:43 +00:00
|
|
|
focus[1] = focus[1] + 1
|
2019-04-23 18:35:15 +00:00
|
|
|
scroll[1] = scroll[1] - 1
|
|
|
|
keysDown[keys.right] = false
|
2019-04-20 01:46:43 +00:00
|
|
|
enteringCommand = true
|
2019-04-23 21:01:40 +00:00
|
|
|
doDrawWorkspaceIndicator = true
|
|
|
|
wID = os.startTimer(workspaceIndicatorDuration)
|
2019-04-20 01:46:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if keysDown[keys.up] then
|
|
|
|
if instances[focus[2] - 1] then
|
|
|
|
if instances[focus[2] - 1][focus[1]] then
|
2019-04-23 21:11:19 +00:00
|
|
|
if keysDown[swapKey] then
|
|
|
|
swapInstances(0, -1)
|
|
|
|
end
|
2019-04-20 01:46:43 +00:00
|
|
|
focus[2] = focus[2] - 1
|
2019-04-23 18:35:15 +00:00
|
|
|
scroll[2] = scroll[2] + 1
|
|
|
|
keysDown[keys.up] = false
|
2019-04-20 01:46:43 +00:00
|
|
|
enteringCommand = true
|
2019-04-23 21:01:40 +00:00
|
|
|
doDrawWorkspaceIndicator = true
|
|
|
|
wID = os.startTimer(workspaceIndicatorDuration)
|
2019-04-20 01:46:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if keysDown[keys.down] then
|
|
|
|
if instances[focus[2] + 1] then
|
|
|
|
if instances[focus[2] + 1][focus[1]] then
|
2019-04-23 21:11:19 +00:00
|
|
|
if keysDown[swapKey] then
|
|
|
|
swapInstances(0, 1)
|
|
|
|
end
|
2019-04-20 01:46:43 +00:00
|
|
|
focus[2] = focus[2] + 1
|
2019-04-23 18:35:15 +00:00
|
|
|
scroll[2] = scroll[2] - 1
|
|
|
|
keysDown[keys.down] = false
|
2019-04-20 01:46:43 +00:00
|
|
|
enteringCommand = true
|
2019-04-23 21:01:40 +00:00
|
|
|
doDrawWorkspaceIndicator = true
|
|
|
|
wID = os.startTimer(workspaceIndicatorDuration)
|
2019-04-20 01:46:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-04-26 00:00:10 +00:00
|
|
|
if keysDown[keys.w] then
|
|
|
|
addWorkspace(0, -1)
|
|
|
|
doDrawWorkspaceIndicator = true
|
|
|
|
wID = os.startTimer(workspaceIndicatorDuration)
|
|
|
|
keysDown[keys.w] = false
|
|
|
|
gridWidth, gridHeight, gridMinX, gridMinY = getMapSize()
|
|
|
|
end
|
|
|
|
if keysDown[keys.s] then
|
|
|
|
addWorkspace(0, 1)
|
|
|
|
doDrawWorkspaceIndicator = true
|
|
|
|
wID = os.startTimer(workspaceIndicatorDuration)
|
|
|
|
keysDown[keys.s] = false
|
|
|
|
gridWidth, gridHeight, gridMinX, gridMinY = getMapSize()
|
|
|
|
end
|
|
|
|
if keysDown[keys.a] then
|
|
|
|
addWorkspace(-1, 0)
|
|
|
|
doDrawWorkspaceIndicator = true
|
|
|
|
wID = os.startTimer(workspaceIndicatorDuration)
|
|
|
|
keysDown[keys.a] = false
|
|
|
|
gridWidth, gridHeight, gridMinX, gridMinY = getMapSize()
|
|
|
|
end
|
|
|
|
if keysDown[keys.d] then
|
|
|
|
addWorkspace(1, 0)
|
|
|
|
doDrawWorkspaceIndicator = true
|
|
|
|
wID = os.startTimer(workspaceIndicatorDuration)
|
|
|
|
keysDown[keys.d] = false
|
|
|
|
gridWidth, gridHeight, gridMinX, gridMinY = getMapSize()
|
|
|
|
end
|
|
|
|
if keysDown[keys.q] then
|
|
|
|
removeWorkspace(0, 0)
|
|
|
|
doDrawWorkspaceIndicator = true
|
|
|
|
wID = os.startTimer(workspaceIndicatorDuration)
|
|
|
|
keysDown[keys.q] = false
|
|
|
|
local good = false
|
|
|
|
for y = -1, 1 do
|
|
|
|
for x = -1, 1 do
|
|
|
|
if math.abs(x) + math.abs(y) == 1 then
|
|
|
|
if instances[focus[2] + y] then
|
|
|
|
if instances[focus[2] + y][focus[1] + x] then
|
|
|
|
focus = {
|
|
|
|
focus[1] + x,
|
|
|
|
focus[2] + y
|
|
|
|
}
|
|
|
|
scroll = {
|
|
|
|
scroll[1] - x,
|
|
|
|
scroll[2] - y
|
|
|
|
}
|
|
|
|
good = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if good then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
gridWidth, gridHeight, gridMinX, gridMinY = getMapSize()
|
|
|
|
end
|
2019-04-20 01:46:43 +00:00
|
|
|
end
|
2019-04-23 18:35:15 +00:00
|
|
|
|
2019-04-20 01:46:43 +00:00
|
|
|
if not enteringCommand then
|
2019-04-26 00:00:10 +00:00
|
|
|
for y = gridMinY, gridHeight do
|
2019-04-20 01:46:43 +00:00
|
|
|
if instances[y] then
|
2019-04-26 00:00:10 +00:00
|
|
|
for x = gridMinX, gridWidth do
|
2019-04-20 01:46:43 +00:00
|
|
|
if instances[y][x] then
|
2019-04-23 18:35:15 +00:00
|
|
|
|
2019-06-18 15:08:52 +00:00
|
|
|
if justStarted or checkIfCanRun(evt, x, y) then
|
2019-04-26 05:35:46 +00:00
|
|
|
previousTerm = term.redirect(instances[y][x].window.handle)
|
2019-06-18 15:08:52 +00:00
|
|
|
cSuccess, instances[y][x].eventFilter = coroutine.resume(instances[y][x].co, table.unpack(evt))
|
2019-04-21 05:26:09 +00:00
|
|
|
term.redirect(previousTerm)
|
2019-04-20 01:46:43 +00:00
|
|
|
end
|
2019-04-23 18:35:15 +00:00
|
|
|
|
2019-04-20 01:46:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-04-23 18:35:15 +00:00
|
|
|
|
2019-04-20 01:46:43 +00:00
|
|
|
lddterm.selectedWindow = instances[focus[2]][focus[1]].window.layer
|
|
|
|
lddterm.render()
|
2019-04-21 05:26:09 +00:00
|
|
|
justStarted = false
|
2019-04-23 18:35:15 +00:00
|
|
|
|
2019-04-20 01:46:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-18 15:08:52 +00:00
|
|
|
local function interpretArgs(tInput, tArgs)
|
|
|
|
local output = {}
|
|
|
|
local errors = {}
|
|
|
|
local usedEntries = {}
|
|
|
|
for aName, aType in pairs(tArgs) do
|
|
|
|
output[aName] = false
|
|
|
|
for i = 1, #tInput do
|
|
|
|
if not usedEntries[i] then
|
|
|
|
if tInput[i] == aName and not output[aName] then
|
|
|
|
if aType then
|
|
|
|
usedEntries[i] = true
|
|
|
|
if type(tInput[i+1]) == aType or type(tonumber(tInput[i+1])) == aType then
|
|
|
|
usedEntries[i+1] = true
|
|
|
|
if aType == "number" then
|
|
|
|
output[aName] = tonumber(tInput[i+1])
|
|
|
|
else
|
|
|
|
output[aName] = tInput[i+1]
|
|
|
|
end
|
|
|
|
else
|
|
|
|
output[aName] = nil
|
|
|
|
errors[1] = errors[1] and (errors[1] + 1) or 1
|
|
|
|
errors[aName] = "expected " .. aType .. ", got " .. type(tInput[i+1])
|
|
|
|
end
|
|
|
|
else
|
|
|
|
usedEntries[i] = true
|
|
|
|
output[aName] = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for i = 1, #tInput do
|
|
|
|
if not usedEntries[i] then
|
|
|
|
output[#output+1] = tInput[i]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return output, errors
|
|
|
|
end
|
|
|
|
|
|
|
|
local argData = {
|
|
|
|
["--help"] = false,
|
|
|
|
["-h"] = false,
|
|
|
|
["--config"] = false,
|
|
|
|
["-c"] = false
|
|
|
|
}
|
|
|
|
|
|
|
|
argList, argErrors = interpretArgs({...}, argData)
|
|
|
|
|
|
|
|
if argList["--help"] or argList["-h"] then
|
2019-04-26 00:00:10 +00:00
|
|
|
displayHelp()
|
|
|
|
write("\n")
|
|
|
|
return
|
2019-06-18 15:08:52 +00:00
|
|
|
elseif argList["--config"] or argList["-c"] then
|
2019-04-26 00:00:10 +00:00
|
|
|
shell.run("rom/programs/edit.lua", configPath)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if _G.currentlyRunningWorkspace then
|
|
|
|
print("Workspace is already running.")
|
|
|
|
return
|
|
|
|
else
|
|
|
|
_G.currentlyRunningWorkspace = true
|
|
|
|
end
|
|
|
|
|
2019-04-23 21:01:40 +00:00
|
|
|
local result, message = pcall(main)
|
2019-04-21 05:44:03 +00:00
|
|
|
|
|
|
|
_G.currentlyRunningWorkspace = false
|
|
|
|
|
|
|
|
term.clear()
|
|
|
|
term.setCursorPos(1,1)
|
2019-04-23 21:01:40 +00:00
|
|
|
if result then
|
|
|
|
print("Thanks for using Workspace!")
|
|
|
|
else
|
|
|
|
print("There was an error, and Workspace had to stop.")
|
|
|
|
print("The error goes as follows:\n")
|
|
|
|
print(message)
|
|
|
|
end
|