rename help files with .txt - overlay.lua creates a terminal compatible window on the overlay glasses - you can now run any program on the glasses overlay
This commit is contained in:
@@ -6,121 +6,120 @@ local ccemux = _G.ccemux
|
|||||||
local sides = { 'bottom', 'top', 'back', 'front', 'right', 'left' }
|
local sides = { 'bottom', 'top', 'back', 'front', 'right', 'left' }
|
||||||
|
|
||||||
local tab = UI.Tab {
|
local tab = UI.Tab {
|
||||||
title = 'CCEmuX',
|
title = 'CCEmuX',
|
||||||
description = 'CCEmuX peripherals',
|
description = 'CCEmuX peripherals',
|
||||||
form = UI.Form {
|
form = UI.Form {
|
||||||
x = 2, ex = -2, y = 2, ey = 5,
|
x = 2, ex = -2, y = 2, ey = 5,
|
||||||
values = {
|
values = {
|
||||||
side = 'bottom',
|
side = 'bottom',
|
||||||
type = 'wireless_modem',
|
type = 'wireless_modem',
|
||||||
},
|
},
|
||||||
manualControls = true,
|
manualControls = true,
|
||||||
side = UI.Chooser {
|
side = UI.Chooser {
|
||||||
formLabel = 'Side', formKey = 'side',
|
formLabel = 'Side', formKey = 'side',
|
||||||
width = 10,
|
width = 10,
|
||||||
},
|
},
|
||||||
ptype = UI.Chooser {
|
ptype = UI.Chooser {
|
||||||
formLabel = 'Type', formKey = 'type',
|
formLabel = 'Type', formKey = 'type',
|
||||||
width = 10,
|
width = 10,
|
||||||
choices = {
|
choices = {
|
||||||
{ name = 'Modem', value = 'wireless_modem' },
|
{ name = 'Modem', value = 'wireless_modem' },
|
||||||
{ name = 'Drive', value = 'disk_drive' },
|
{ name = 'Drive', value = 'disk_drive' },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
drive_id = UI.TextEntry {
|
drive_id = UI.TextEntry {
|
||||||
x = 19, y = 3,
|
x = 19, y = 3,
|
||||||
formKey = 'drive_id',
|
formKey = 'drive_id',
|
||||||
shadowText = 'id',
|
shadowText = 'id',
|
||||||
width = 5,
|
width = 5,
|
||||||
limit = 3,
|
limit = 3,
|
||||||
transform = 'number',
|
transform = 'number',
|
||||||
},
|
},
|
||||||
add = UI.Button {
|
add = UI.Button {
|
||||||
x = -6, y = 3, width = 5,
|
x = -6, y = 3, width = 5,
|
||||||
text = 'Add', event = 'form_ok',
|
text = 'Add', event = 'form_ok',
|
||||||
help = 'Add items to turtle to add to filter',
|
},
|
||||||
},
|
},
|
||||||
},
|
grid = UI.Grid {
|
||||||
grid = UI.Grid {
|
x = 2, ex = -2, y = 7, ey = -2,
|
||||||
x = 2, ex = -2, y = 7, ey = -2,
|
columns = {
|
||||||
columns = {
|
{ heading = 'Side', key = 'side', width = 8 },
|
||||||
{ heading = 'Side', key = 'side', width = 8 },
|
{ heading = 'Type', key = 'type' },
|
||||||
{ heading = 'Type', key = 'type' },
|
{ heading = 'ID', key = 'args', width = 4 },
|
||||||
{ heading = 'ID', key = 'args', width = 4 },
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function tab:updatePeripherals(config)
|
function tab:updatePeripherals(config)
|
||||||
self.grid.values = { }
|
self.grid.values = { }
|
||||||
for k,v in pairs(config) do
|
for k,v in pairs(config) do
|
||||||
table.insert(self.grid.values, {
|
table.insert(self.grid.values, {
|
||||||
side = k,
|
side = k,
|
||||||
type = v.type,
|
type = v.type,
|
||||||
args = v.args and v.args.id,
|
args = v.args and v.args.id,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
self.grid:update()
|
self.grid:update()
|
||||||
end
|
end
|
||||||
|
|
||||||
function tab:enable()
|
function tab:enable()
|
||||||
local config = Config.load('ccemux')
|
local config = Config.load('ccemux')
|
||||||
|
|
||||||
local choices = { }
|
local choices = { }
|
||||||
for _,k in pairs(sides) do
|
for _,k in pairs(sides) do
|
||||||
table.insert(choices, { name = k, value = k })
|
table.insert(choices, { name = k, value = k })
|
||||||
end
|
end
|
||||||
self.form.side.choices = choices
|
self.form.side.choices = choices
|
||||||
|
|
||||||
self:updatePeripherals(config)
|
self:updatePeripherals(config)
|
||||||
UI.Tab.enable(self)
|
UI.Tab.enable(self)
|
||||||
|
|
||||||
self.form.drive_id.enabled = false
|
self.form.drive_id.enabled = false
|
||||||
end
|
end
|
||||||
|
|
||||||
function tab:eventHandler(event)
|
function tab:eventHandler(event)
|
||||||
if event.type == 'form_complete' then
|
if event.type == 'form_complete' then
|
||||||
if event.values.type == 'disk_drive' and not event.values.drive_id then
|
if event.values.type == 'disk_drive' and not event.values.drive_id then
|
||||||
self:emit({ type = 'error_message', message = 'Invalid drive ID' })
|
self:emit({ type = 'error_message', message = 'Invalid drive ID' })
|
||||||
else
|
else
|
||||||
ccemux.detach(event.values.side)
|
ccemux.detach(event.values.side)
|
||||||
|
|
||||||
local config = Config.load('ccemux')
|
local config = Config.load('ccemux')
|
||||||
config[event.values.side] = {
|
config[event.values.side] = {
|
||||||
type = event.values.type
|
type = event.values.type
|
||||||
}
|
}
|
||||||
if event.values.type == 'disk_drive' then
|
if event.values.type == 'disk_drive' then
|
||||||
config[event.values.side].args = {
|
config[event.values.side].args = {
|
||||||
id = event.values.drive_id
|
id = event.values.drive_id
|
||||||
}
|
}
|
||||||
ccemux.attach(event.values.side, event.values.type, { id = event.values.drive_id })
|
ccemux.attach(event.values.side, event.values.type, { id = event.values.drive_id })
|
||||||
else
|
else
|
||||||
ccemux.attach(event.values.side, event.values.type)
|
ccemux.attach(event.values.side, event.values.type)
|
||||||
end
|
end
|
||||||
Config.update('ccemux', config)
|
Config.update('ccemux', config)
|
||||||
self:updatePeripherals(config)
|
self:updatePeripherals(config)
|
||||||
self.grid:draw()
|
self.grid:draw()
|
||||||
|
|
||||||
self:emit({ type = 'success_message', message = 'Attached' })
|
self:emit({ type = 'success_message', message = 'Attached' })
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif event.type == 'choice_change' then
|
elseif event.type == 'choice_change' then
|
||||||
if event.element == self.form.ptype then
|
if event.element == self.form.ptype then
|
||||||
self.form.drive_id.enabled = event.value == 'disk_drive'
|
self.form.drive_id.enabled = event.value == 'disk_drive'
|
||||||
self.form:draw()
|
self.form:draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif event.type == 'grid_select' then
|
elseif event.type == 'grid_select' then
|
||||||
local config = Config.load('ccemux')
|
local config = Config.load('ccemux')
|
||||||
config[event.selected.side] = nil
|
config[event.selected.side] = nil
|
||||||
Config.update('ccemux', config)
|
Config.update('ccemux', config)
|
||||||
self:updatePeripherals(config)
|
self:updatePeripherals(config)
|
||||||
self.grid:draw()
|
self.grid:draw()
|
||||||
|
|
||||||
self:emit({ type = 'success_message', message = 'Detached' })
|
self:emit({ type = 'success_message', message = 'Detached' })
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return tab
|
return tab
|
||||||
|
|||||||
@@ -13,4 +13,7 @@
|
|||||||
* and more...
|
* and more...
|
||||||
]],
|
]],
|
||||||
license = 'MIT',
|
license = 'MIT',
|
||||||
|
required = {
|
||||||
|
'core',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,26 +3,26 @@ local Event = require('opus.event')
|
|||||||
local UI = require('opus.ui')
|
local UI = require('opus.ui')
|
||||||
local Util = require('opus.util')
|
local Util = require('opus.util')
|
||||||
|
|
||||||
local peripheral = _G.peripheral
|
local device = _G.device
|
||||||
|
|
||||||
--[[ -- PeripheralsPage -- ]] --
|
--[[ -- PeripheralsPage -- ]] --
|
||||||
local peripheralsPage = UI.Page {
|
local peripheralsPage = UI.Page {
|
||||||
grid = UI.ScrollingGrid {
|
grid = UI.ScrollingGrid {
|
||||||
ey = -2,
|
ey = -2,
|
||||||
columns = {
|
columns = {
|
||||||
|
--{ heading = 'Name', key = 'name' },
|
||||||
{ heading = 'Type', key = 'type' },
|
{ heading = 'Type', key = 'type' },
|
||||||
{ heading = 'Side', key = 'side' },
|
{ heading = 'Side', key = 'side' },
|
||||||
},
|
},
|
||||||
sortColumn = 'type',
|
sortColumn = 'type',
|
||||||
autospace = true,
|
autospace = true,
|
||||||
enable = function(self)
|
enable = function(self)
|
||||||
local sides = peripheral.getNames()
|
|
||||||
|
|
||||||
Util.clear(self.values)
|
Util.clear(self.values)
|
||||||
for _,side in pairs(sides) do
|
for _,v in pairs(device) do
|
||||||
table.insert(self.values, {
|
table.insert(self.values, {
|
||||||
type = peripheral.getType(side),
|
type = v.type,
|
||||||
side = side
|
side = v.side,
|
||||||
|
name = v.name,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
self:update()
|
self:update()
|
||||||
@@ -75,49 +75,50 @@ local methodsPage = UI.Page {
|
|||||||
[ 'control-q' ] = 'back',
|
[ 'control-q' ] = 'back',
|
||||||
backspace = 'back',
|
backspace = 'back',
|
||||||
},
|
},
|
||||||
|
enable = function(self, p)
|
||||||
|
self.peripheral = p or self.peripheral
|
||||||
|
|
||||||
|
p = device[self.peripheral.name]
|
||||||
|
if p.getDocs then
|
||||||
|
-- plethora
|
||||||
|
self.grid.values = { }
|
||||||
|
for k,v in pairs(p.getDocs()) do
|
||||||
|
table.insert(self.grid.values, {
|
||||||
|
name = k,
|
||||||
|
doc = v,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
elseif not p.getAdvancedMethodsData then
|
||||||
|
-- computercraft
|
||||||
|
self.grid.values = { }
|
||||||
|
for k,v in pairs(p) do
|
||||||
|
if type(v) == 'function' then
|
||||||
|
table.insert(self.grid.values, {
|
||||||
|
name = k,
|
||||||
|
noext = true,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- open peripherals
|
||||||
|
self.grid.values = p.getAdvancedMethodsData()
|
||||||
|
for name,f in pairs(self.grid.values) do
|
||||||
|
f.name = name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
self.grid:update()
|
||||||
|
self.grid:setIndex(1)
|
||||||
|
|
||||||
|
self.doc:setText(self:getDocumentation())
|
||||||
|
|
||||||
|
self.statusBar:setStatus(self.peripheral.type)
|
||||||
|
UI.Page.enable(self)
|
||||||
|
|
||||||
|
self:setFocus(self.grid)
|
||||||
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
function methodsPage:enable(p)
|
|
||||||
self.peripheral = p or self.peripheral
|
|
||||||
|
|
||||||
p = peripheral.wrap(self.peripheral.side)
|
|
||||||
if p.getDocs then
|
|
||||||
-- plethora
|
|
||||||
self.grid.values = { }
|
|
||||||
for k,v in pairs(p.getDocs()) do
|
|
||||||
table.insert(self.grid.values, {
|
|
||||||
name = k,
|
|
||||||
doc = v,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
elseif not p.getAdvancedMethodsData then
|
|
||||||
-- computercraft
|
|
||||||
self.grid.values = { }
|
|
||||||
for name in pairs(p) do
|
|
||||||
table.insert(self.grid.values, {
|
|
||||||
name = name,
|
|
||||||
noext = true,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
else
|
|
||||||
-- open peripherals
|
|
||||||
self.grid.values = p.getAdvancedMethodsData()
|
|
||||||
for name,f in pairs(self.grid.values) do
|
|
||||||
f.name = name
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
self.grid:update()
|
|
||||||
self.grid:setIndex(1)
|
|
||||||
|
|
||||||
self.doc:setText(self:getDocumentation())
|
|
||||||
|
|
||||||
self.statusBar:setStatus(self.peripheral.type)
|
|
||||||
UI.Page.enable(self)
|
|
||||||
|
|
||||||
self:setFocus(self.grid)
|
|
||||||
end
|
|
||||||
|
|
||||||
function methodsPage:eventHandler(event)
|
function methodsPage:eventHandler(event)
|
||||||
if event.type == 'back' then
|
if event.type == 'back' then
|
||||||
UI:setPage(peripheralsPage)
|
UI:setPage(peripheralsPage)
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
local Util = require('opus.util')
|
local Util = require('opus.util')
|
||||||
|
|
||||||
|
local device = _G.device
|
||||||
local os = _G.os
|
local os = _G.os
|
||||||
local peripheral = _G.peripheral
|
local peripheral = _G.peripheral
|
||||||
local term = _G.term
|
local term = _G.term
|
||||||
|
|
||||||
local args = { ... }
|
local args = { ... }
|
||||||
local mon = args[1] and peripheral.wrap(args[1]) or
|
local mon = args[1] and device[args[1]] or peripheral.wrap(args[1]) or
|
||||||
peripheral.find('monitor') or
|
peripheral.find('monitor') or
|
||||||
error('Syntax: debug <monitor>')
|
error('Syntax: debug <monitor>')
|
||||||
|
|
||||||
|
|||||||
@@ -306,7 +306,7 @@ local page = UI.Page {
|
|||||||
x = 2, y = 2, ey = -4, ex = -2,
|
x = 2, y = 2, ey = -4, ex = -2,
|
||||||
columns = {
|
columns = {
|
||||||
{ key = 'name', heading = 'Name' },
|
{ key = 'name', heading = 'Name' },
|
||||||
{ key = 'dir', heading = 'Directory' },
|
{ key = 'dir', heading = 'Directory', textColor = 'lightGray' },
|
||||||
},
|
},
|
||||||
accelerators = {
|
accelerators = {
|
||||||
backspace = 'slide_hide',
|
backspace = 'slide_hide',
|
||||||
|
|||||||
108
neural/overlay.lua
Normal file
108
neural/overlay.lua
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
local Terminal = require('opus.terminal')
|
||||||
|
|
||||||
|
local colors = _G.colors
|
||||||
|
local device = _G.device
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Create a device for glasses
|
||||||
|
Usable as a redirect or UI target
|
||||||
|
|
||||||
|
Example usage:
|
||||||
|
Files --display=glasses
|
||||||
|
debugMonitor glasses
|
||||||
|
|
||||||
|
In a program:
|
||||||
|
local prev = term.redirect(device.glasses)
|
||||||
|
shell.run('shell')
|
||||||
|
term.redirect(prev)
|
||||||
|
|
||||||
|
Glasses do not use the CC font - so extended chars
|
||||||
|
do not display correctly.
|
||||||
|
]]
|
||||||
|
|
||||||
|
-- configurable
|
||||||
|
local w, h = 46, 19
|
||||||
|
local scale = .5
|
||||||
|
|
||||||
|
local glasses = device['plethora:glasses']
|
||||||
|
local canvas = glasses.canvas()
|
||||||
|
local _, cy = 1, 1
|
||||||
|
local _, gh = canvas:getSize()
|
||||||
|
local lines = { }
|
||||||
|
local map = {
|
||||||
|
['0'] = 0xF0F0F0FF,
|
||||||
|
['1'] = 0xF2B233FF,
|
||||||
|
['2'] = 0xE57FD8FF,
|
||||||
|
['3'] = 0x99B2F2FF,
|
||||||
|
['4'] = 0xDEDE6CFF,
|
||||||
|
['5'] = 0x7FCC19FF,
|
||||||
|
['6'] = 0xF2B2CCFF,
|
||||||
|
['7'] = 0x4C4C4CFF,
|
||||||
|
['8'] = 0x999999FF,
|
||||||
|
['9'] = 0x4C99B2FF,
|
||||||
|
['a'] = 0xB266E5FF,
|
||||||
|
['b'] = 0x3366CCFF,
|
||||||
|
['c'] = 0x7F664CFF,
|
||||||
|
['d'] = 0x57A64EFF,
|
||||||
|
['e'] = 0xCC4C4CFF,
|
||||||
|
['f'] = 0x191919FF, -- transparent
|
||||||
|
}
|
||||||
|
|
||||||
|
local xs, ys = 6 * scale, 9 * scale
|
||||||
|
|
||||||
|
-- Position bottom left
|
||||||
|
local group = canvas.addGroup({ x = 1, y = gh - (h * ys) - 10 })
|
||||||
|
|
||||||
|
for y = 1, h do
|
||||||
|
lines[y] = {
|
||||||
|
text = { },
|
||||||
|
bg = { }
|
||||||
|
}
|
||||||
|
for x = 1, w do
|
||||||
|
lines[y].bg[x] = group.addRectangle(x * xs, y * ys, xs, ys, 0xF0F0F04F)
|
||||||
|
lines[y].text[x] = group.addText({ x * xs, y * ys }, '', 0x7FCC19FF)
|
||||||
|
lines[y].text[x].setScale(scale)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
device.glasses = Terminal.window({
|
||||||
|
getSize = function()
|
||||||
|
return w, h
|
||||||
|
end,
|
||||||
|
isColor = function()
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
clear = function()
|
||||||
|
--canvas.clear()
|
||||||
|
end,
|
||||||
|
blit = function(text, fg, bg)
|
||||||
|
for x = 1, #text do
|
||||||
|
local ln = lines[cy]
|
||||||
|
ln.bg[x].setColor(map[bg:sub(x, x)])
|
||||||
|
ln.text[x].setColor(map[fg:sub(x, x)])
|
||||||
|
ln.text[x].setText(text:sub(x, x))
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
setCursorPos = function(_, y)
|
||||||
|
-- full lines are always blit
|
||||||
|
cy = y
|
||||||
|
end,
|
||||||
|
setBackgroundColor = function()
|
||||||
|
end,
|
||||||
|
setTextColor = function()
|
||||||
|
end,
|
||||||
|
setCursorBlink = function()
|
||||||
|
end,
|
||||||
|
getBackgroundColor = function()
|
||||||
|
return colors.black
|
||||||
|
end,
|
||||||
|
getTextColor = function()
|
||||||
|
return colors.white
|
||||||
|
end,
|
||||||
|
}, 1, 1, w, h, true)
|
||||||
|
|
||||||
|
function device.glasses.setTextScale() end
|
||||||
|
|
||||||
|
device.glasses.side = 'glasses'
|
||||||
|
device.glasses.type = 'glasses'
|
||||||
|
device.glasses.name = 'glasses'
|
||||||
Reference in New Issue
Block a user