fix mwm wip

This commit is contained in:
kepler155c@gmail.com
2019-02-07 03:10:40 -05:00
parent b07343a530
commit 3f2f8afaad

View File

@@ -1,8 +1,10 @@
local injector = _G.requireInjector or load(http.get('https://raw.githubusercontent.com/kepler155c/opus/develop/sys/apis/injector.lua').readAll())() if not _G.requireInjector then
injector(_ENV) _ENV.LUA_PATH='https://raw.githubusercontent.com/kepler155c/opus/develop-1.8/sys/apis'
load(_G.http.get(_ENV.LUA_PATH .. '/injector.lua').readAll())()(_ENV)
end
local Canvas = require('ui.canvas') local Terminal = require('terminal')
local Util = require('util') local Util = require('util')
local colors = _G.colors local colors = _G.colors
local os = _G.os local os = _G.os
@@ -24,25 +26,29 @@ local processes = { }
local parentTerm = term.current() local parentTerm = term.current()
local sessionFile = args[1] or 'usr/config/mwm' local sessionFile = args[1] or 'usr/config/mwm'
local running local running
local monitor local parentMon
local defaultEnv = Util.shallowCopy(_ENV) local defaultEnv = Util.shallowCopy(_ENV)
defaultEnv.multishell = multishell defaultEnv.multishell = multishell
if args[3] then if args[3] then
monitor = _G.device[args[3]] parentMon = _G.device[args[3]]
elseif args[2] then elseif args[2] then
monitor = peripheral.wrap(args[2]) or syntax() parentMon = peripheral.wrap(args[2]) or syntax()
else else
monitor = peripheral.find('monitor') or syntax() parentMon = peripheral.find('monitor') or syntax()
end end
monitor.setTextScale(.5) parentMon.setTextScale(.5)
local monDim, termDim = { }, { }
monDim.width, monDim.height = parentMon.getSize()
termDim.width, termDim.height = parentTerm.getSize()
local monitor = Terminal.window(parentMon, 1, 1, monDim.width, monDim.height, false)
monitor.setBackgroundColor(colors.gray) monitor.setBackgroundColor(colors.gray)
monitor.clear() monitor.clear()
local monDim, termDim = { }, { } monitor.canvas:setVisible(true)
monDim.width, monDim.height = monitor.getSize()
termDim.width, termDim.height = parentTerm.getSize()
local function nextUID() local function nextUID()
UID = UID + 1 UID = UID + 1
@@ -96,11 +102,14 @@ function Process:new(args)
self:adjustDimensions() self:adjustDimensions()
self.container = window.create(monitor, self.x, self.y, self.width, self.height, false) self.container = Terminal.window(monitor, self.x, self.y, self.width, self.height, false)
self.window = window.create(self.container, 2, 3, args.width, args.height, true) self.window = window.create(self.container, 2, 3, args.width, args.height, true)
self.terminal = self.window self.terminal = self.window
Canvas.convertWindow(self.container, monitor, self.x, self.y)
self.container.canvas.parent = monitor.canvas
table.insert(monitor.canvas.layers, self.container.canvas)
self.container.canvas:setVisible(true)
self.co = coroutine.create(function() self.co = coroutine.create(function()
@@ -143,7 +152,6 @@ function Process:focus(focused)
end end
function Process:drawSizers(showSizers) function Process:drawSizers(showSizers)
local sizeChars = { local sizeChars = {
'\135', '\139', '\141', '\142' '\135', '\139', '\141', '\142'
} }
@@ -185,7 +193,6 @@ function Process:drawSizers(showSizers)
end end
function Process:adjustDimensions() function Process:adjustDimensions()
self.width = math.min(self.width, monDim.width) self.width = math.min(self.width, monDim.width)
self.height = math.min(self.height, monDim.height) self.height = math.min(self.height, monDim.height)
@@ -196,7 +203,6 @@ function Process:adjustDimensions()
end end
function Process:reposition() function Process:reposition()
self:adjustDimensions() self:adjustDimensions()
self.container.reposition(self.x, self.y, self.width, self.height) self.container.reposition(self.x, self.y, self.width, self.height)
self.container.setBackgroundColor(colors.black) self.container.setBackgroundColor(colors.black)
@@ -286,8 +292,8 @@ function multishell.setFocus(uid)
Util.removeByValue(processes, process) Util.removeByValue(processes, process)
table.insert(processes, process) table.insert(processes, process)
multishell.restack()
process.container.canvas:raise()
process:focus(true) process:focus(true)
process.container.canvas:dirty() process.container.canvas:dirty()
end end
@@ -338,9 +344,8 @@ function multishell.openTab(tabInfo)
local process = Process:new(tabInfo) local process = Process:new(tabInfo)
table.insert(processes, 1, process) table.insert(processes, 1, process)
multishell.restack()
process.container.setVisible(true) --process.container.canvas:setVisible(true)
local previousTerm = term.current() local previousTerm = term.current()
process:resume() process:resume()
@@ -361,7 +366,8 @@ end
function multishell.removeProcess(process) function multishell.removeProcess(process)
Util.removeByValue(processes, process) Util.removeByValue(processes, process)
multishell.restack() process.container.canvas:removeLayer()
multishell.saveSession(sessionFile) multishell.saveSession(sessionFile)
redraw() redraw()
end end
@@ -456,13 +462,10 @@ function multishell.start()
end end
end end
local didRedraw monitor.canvas:dirty()
for _,process in pairs(processes) do
if process.container.canvas:isDirty() then monitor.canvas:render(parentMon)
process.container.canvas:redraw(monitor) local didRedraw = true
didRedraw = true
end
end
local focused = processes[#processes] local focused = processes[#processes]
if didRedraw and focused then if didRedraw and focused then
@@ -491,7 +494,7 @@ local function addShell()
}, { __index = Process }) }, { __index = Process })
function process:focus(focused) function process:focus(focused)
self.window.setVisible(focused) --self.window.setVisible(focused)
if focused then if focused then
self.window.restoreCursor() self.window.restoreCursor()
else else
@@ -508,12 +511,10 @@ local function addShell()
function process:click() function process:click()
end end
process.container = window.create(monitor, process.x, process.y+1, process.width, process.height, true) process.container = Terminal.window(monitor, process.x, process.y+1, process.width, process.height, true)
process.window = window.create(parentTerm, 1, 1, termDim.width, termDim.height, true) process.window = window.create(parentTerm, 1, 1, termDim.width, termDim.height, true)
process.terminal = process.window process.terminal = process.window
Canvas.convertWindow(process.container, monitor, process.x, process.y)
process.co = coroutine.create(function() process.co = coroutine.create(function()
print('To run a program on the monitor, type "fg <program>"') print('To run a program on the monitor, type "fg <program>"')
print('To quit, type "exit"') print('To quit, type "exit"')