Ui enhancements 2.0 (#29)
* canvas overhaul * editor 2.0 * more tweaks * more editor work * completions + refactor * cleanup + editor additions * cleanup + undo overhaul * editor recent/peripherals/redo + cleanup * editor path issues * cleanup * changes for deprecated ui methods - recolor milo - make turtle scripts run again - mob rancher improvements * can now use named colors
This commit was merged in pull request #29.
This commit is contained in:
@@ -250,5 +250,3 @@ turtle.setStatus('Jamming')
|
||||
UI:pullEvents()
|
||||
turtle.setStatus('idle')
|
||||
page:play(false)
|
||||
|
||||
UI.term:reset()
|
||||
|
||||
174
ignore/passthrough.lua
Normal file
174
ignore/passthrough.lua
Normal file
@@ -0,0 +1,174 @@
|
||||
local _rep = string.rep
|
||||
local _sub = string.sub
|
||||
local colors = _G.colors
|
||||
|
||||
local palette = { }
|
||||
|
||||
for n = 1, 16 do
|
||||
palette[2 ^ (n - 1)] = _sub("0123456789abcdef", n, n)
|
||||
end
|
||||
|
||||
local swindow = { }
|
||||
|
||||
function swindow.createPassthrough(parent, wx, wy, width, height)
|
||||
local window = { }
|
||||
local cx, cy = 1, 1
|
||||
local blink = false
|
||||
local fg = colors.white
|
||||
local bg = colors.black
|
||||
|
||||
local function crop(text, x)
|
||||
local w = #text
|
||||
|
||||
if x < 1 then
|
||||
text = _sub(text, 2 - x)
|
||||
w = w + x - 1
|
||||
x = 1
|
||||
end
|
||||
|
||||
if x + w - 1 > width then
|
||||
text = _sub(text, 1, width - x + 1)
|
||||
end
|
||||
|
||||
return text
|
||||
end
|
||||
|
||||
local function blit(text, fg, bg)
|
||||
parent.setCursorPos(cx + wx - 1, cy + wy - 1)
|
||||
parent.blit(text, fg, bg)
|
||||
cx = cx + #text
|
||||
end
|
||||
|
||||
function window.write(text)
|
||||
if cy > 0 and cy <= height then
|
||||
text = crop(tostring(text), cx)
|
||||
if #text > 0 then
|
||||
--parent.setCursorPos(cx + wx - 1, cy + wy - 1)
|
||||
blit(text, _rep(palette[fg], #text), _rep(palette[bg], #text))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function window.blit(text, fg, bg)
|
||||
if cy > 0 and cy <= height then
|
||||
text = crop(tostring(text), cx)
|
||||
if #text > 0 then
|
||||
blit(text, crop(tostring(fg), cx), crop(tostring(bg), cx))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function window.clear()
|
||||
local filler = _rep(' ', width)
|
||||
for i = 1, height do
|
||||
parent.setCursorPos(wx, i + wy - 1)
|
||||
parent.write(filler)
|
||||
end
|
||||
end
|
||||
|
||||
function window.clearLine()
|
||||
if cy > 0 and cy <= height then
|
||||
local filler = _rep(' ', width)
|
||||
parent.setCursorPos(cx + wx - 1, cy + wy - 1)
|
||||
parent.write(filler)
|
||||
end
|
||||
end
|
||||
|
||||
function window.getCursorPos()
|
||||
return cx, cy
|
||||
end
|
||||
|
||||
function window.setCursorPos(x, y)
|
||||
cx = math.floor(x)
|
||||
cy = math.floor(y)
|
||||
parent.setCursorPos(cx + wx - 1, cy + wy - 1)
|
||||
end
|
||||
|
||||
function window.setCursorBlink(b)
|
||||
blink = b
|
||||
parent.setCursorBlink(b)
|
||||
end
|
||||
|
||||
function window.getCursorBlink()
|
||||
return blink
|
||||
end
|
||||
|
||||
window.isColor = parent.isColor
|
||||
window.isColour = parent.isColour
|
||||
window.setPaletteColour = parent.setPaletteColour
|
||||
window.setPaletteColor = parent.setPaletteColor
|
||||
window.getPaletteColour = parent.getPaletteColour
|
||||
window.getPaletteColor = parent.getPaletteColour
|
||||
window.setBackgroundColor = parent.setBackgroundColor
|
||||
window.setBackgroundColour = parent.setBackgroundColor
|
||||
window.getBackgroundColor = parent.getBackgroundColor
|
||||
window.getBackgroundColour = parent.getBackgroundColor
|
||||
window.setVisible = parent.setVisible
|
||||
window.redraw = function() end --parent.redraw
|
||||
|
||||
function window.getTextColor()
|
||||
return fg
|
||||
end
|
||||
window.getTextColour = window.getTextColor
|
||||
|
||||
function window.setTextColor(textColor)
|
||||
fg = textColor
|
||||
parent.setTextColor(fg)
|
||||
end
|
||||
window.setTextColour = window.setTextColor
|
||||
|
||||
function window.restoreCursor()
|
||||
parent.setCursorPos(cx + wx - 1, cy + wy - 1)
|
||||
parent.setTextColor(fg)
|
||||
parent.setCursorBlink(blink)
|
||||
end
|
||||
|
||||
function window.getSize()
|
||||
return width, height
|
||||
end
|
||||
|
||||
function window.scroll( n )
|
||||
if n ~= 0 then
|
||||
local lines = { }
|
||||
for i = 1, height do
|
||||
lines[i] = { parent.getLine(wy + i - 1) }
|
||||
end
|
||||
|
||||
for newY = 1, height do
|
||||
local y = newY + n
|
||||
parent.setCursorPos(wx, wy + newY - 1)
|
||||
if y >= 1 and y <= height then
|
||||
parent.blit(table.unpack(lines[y]))
|
||||
else
|
||||
parent.blit(
|
||||
_rep(' ', width),
|
||||
_rep(palette[fg], width),
|
||||
_rep(palette[bg], width))
|
||||
end
|
||||
end
|
||||
parent.setCursorPos(cx + wx - 1, cy + wy - 1)
|
||||
end
|
||||
end
|
||||
|
||||
function window.getLine(y)
|
||||
local t, tc, bc = parent.getLine(y + cy - 1)
|
||||
return t:sub(1, width), tc:sub(1, width), bc:sub(1, width)
|
||||
end
|
||||
|
||||
function window.getPosition()
|
||||
return wx, wy
|
||||
end
|
||||
|
||||
function window.reposition(nNewX, nNewY, nNewWidth, nNewHeight, newParent)
|
||||
wx = nNewX
|
||||
wy = nNewY
|
||||
width = nNewWidth
|
||||
height = nNewHeight
|
||||
|
||||
window.restoreCursor()
|
||||
end
|
||||
|
||||
return window
|
||||
end
|
||||
|
||||
return swindow
|
||||
@@ -4,42 +4,21 @@ local Util = require('opus.util')
|
||||
|
||||
local colors = _G.colors
|
||||
local os = _G.os
|
||||
local peripheral = _G.peripheral
|
||||
local printError = _G.printError
|
||||
local shell = _ENV.shell
|
||||
local term = _G.term
|
||||
local window = _G.window
|
||||
|
||||
local function syntax()
|
||||
printError('Syntax:')
|
||||
error('mwm [--config=filename] [monitor]')
|
||||
end
|
||||
|
||||
local args = Util.parse(...)
|
||||
local UID = 0
|
||||
local multishell = { }
|
||||
local processes = { }
|
||||
local parentTerm = term.current()
|
||||
local sessionFile = args.config or 'usr/config/mwm'
|
||||
local monName = args[1]
|
||||
local sessionFile = 'usr/config/twm'
|
||||
local running
|
||||
local parentMon
|
||||
local parentMon = term.current()
|
||||
|
||||
local defaultEnv = Util.shallowCopy(_ENV)
|
||||
defaultEnv.multishell = multishell
|
||||
|
||||
if monName == 'terminal' then
|
||||
parentMon = term.current()
|
||||
elseif monName then
|
||||
parentMon = peripheral.wrap(monName) or syntax()
|
||||
else
|
||||
parentMon = peripheral.find('monitor') or syntax()
|
||||
end
|
||||
|
||||
if parentMon.setTextScale then
|
||||
parentMon.setTextScale(.5)
|
||||
end
|
||||
|
||||
local monDim, termDim = { }, { }
|
||||
monDim.width, monDim.height = parentMon.getSize()
|
||||
termDim.width, termDim.height = parentTerm.getSize()
|
||||
@@ -73,13 +52,10 @@ local function write(win, x, y, text)
|
||||
end
|
||||
|
||||
local function redraw()
|
||||
--monitor.clear()
|
||||
monitor.canvas:dirty()
|
||||
--monitor.setBackgroundColor(colors.gray)
|
||||
monitor.canvas:clear(colors.gray)
|
||||
for k, process in ipairs(processes) do
|
||||
for _, process in ipairs(processes) do
|
||||
process.container.canvas:dirty()
|
||||
process:focus(k == #processes)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -112,7 +88,8 @@ function Process:new(args)
|
||||
height = args.height + 1,
|
||||
path = args.path,
|
||||
args = args.args or { },
|
||||
title = args.title or 'shell',
|
||||
title = args.title or 'shell',
|
||||
timestamp = os.clock(),
|
||||
isMoving = false,
|
||||
isResizing = false,
|
||||
}, { __index = Process })
|
||||
@@ -155,20 +132,12 @@ function Process:new(args)
|
||||
end
|
||||
|
||||
function Process:focus(focused)
|
||||
if focused then
|
||||
self.container.setBackgroundColor(colors.yellow)
|
||||
else
|
||||
self.container.setBackgroundColor(colors.lightGray)
|
||||
end
|
||||
self.container.setBackgroundColor(focused and colors.yellow or colors.lightGray)
|
||||
self.container.setTextColor(colors.black)
|
||||
write(self.container, 1, 1, string.rep(' ', self.width))
|
||||
write(self.container, 2, 1, self.title)
|
||||
write(self.container, self.width - 1, 1, '*')
|
||||
write(self.container, self.width - 3, 1, '\029')
|
||||
|
||||
if focused then
|
||||
self.window.restoreCursor()
|
||||
end
|
||||
end
|
||||
|
||||
function Process:drawSizers()
|
||||
@@ -188,17 +157,18 @@ function Process:adjustDimensions()
|
||||
self.y = math.min(self.y, monDim.height - self.height + 1)
|
||||
end
|
||||
|
||||
function Process:reposition()
|
||||
function Process:reposition(resizing)
|
||||
self:adjustDimensions()
|
||||
self.container.reposition(self.x, self.y, self.width, self.height)
|
||||
self.container.setBackgroundColor(colors.black)
|
||||
self.container.clear()
|
||||
self.window.reposition(1, 2, self.width, self.height - 1)
|
||||
if self.window ~= self.terminal then
|
||||
if self.terminal.reposition then -- ??
|
||||
self.terminal.reposition(1, 1, self.width, self.height - 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
if resizing then
|
||||
self:focus(self == processes[#processes])
|
||||
end
|
||||
redraw()
|
||||
end
|
||||
|
||||
@@ -225,7 +195,7 @@ function Process:resize(x, y)
|
||||
self.height = y - self.isResizing.y + self.isResizing.h
|
||||
self.width = x - self.isResizing.x + self.isResizing.w
|
||||
|
||||
self:reposition()
|
||||
self:reposition(true)
|
||||
self:resume('term_resize')
|
||||
self:drawSizers()
|
||||
multishell.saveSession(sessionFile)
|
||||
@@ -278,7 +248,8 @@ function multishell.setFocus(uid)
|
||||
|
||||
process.container.canvas:raise()
|
||||
process:focus(true)
|
||||
process.container.canvas:dirty()
|
||||
process.container.canvas:dirty()
|
||||
process.window.restoreCursor()
|
||||
end
|
||||
return true
|
||||
end
|
||||
@@ -423,14 +394,15 @@ function multishell.start()
|
||||
elseif focused.isMoving then
|
||||
focused.x = event[3] - focused.isMoving.x + focused.isMoving.ox
|
||||
focused.y = event[4] - focused.isMoving.y + focused.isMoving.oy
|
||||
focused:reposition()
|
||||
focused:reposition(false)
|
||||
end
|
||||
end
|
||||
|
||||
elseif event[1] == 'char' or
|
||||
event[1] == 'key' or
|
||||
event[1] == 'key_up' or
|
||||
event[1] == 'paste' then
|
||||
event[1] == 'paste' or
|
||||
event[1] == 'mouse_scroll' then
|
||||
|
||||
local focused = processes[#processes]
|
||||
if focused then
|
||||
|
||||
Reference in New Issue
Block a user