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 tab = UI.Tab {
|
||||
title = 'CCEmuX',
|
||||
description = 'CCEmuX peripherals',
|
||||
form = UI.Form {
|
||||
x = 2, ex = -2, y = 2, ey = 5,
|
||||
values = {
|
||||
side = 'bottom',
|
||||
type = 'wireless_modem',
|
||||
},
|
||||
manualControls = true,
|
||||
side = UI.Chooser {
|
||||
formLabel = 'Side', formKey = 'side',
|
||||
width = 10,
|
||||
},
|
||||
ptype = UI.Chooser {
|
||||
formLabel = 'Type', formKey = 'type',
|
||||
width = 10,
|
||||
choices = {
|
||||
{ name = 'Modem', value = 'wireless_modem' },
|
||||
{ name = 'Drive', value = 'disk_drive' },
|
||||
},
|
||||
},
|
||||
drive_id = UI.TextEntry {
|
||||
x = 19, y = 3,
|
||||
formKey = 'drive_id',
|
||||
shadowText = 'id',
|
||||
width = 5,
|
||||
limit = 3,
|
||||
transform = 'number',
|
||||
},
|
||||
add = UI.Button {
|
||||
x = -6, y = 3, width = 5,
|
||||
text = 'Add', event = 'form_ok',
|
||||
help = 'Add items to turtle to add to filter',
|
||||
},
|
||||
},
|
||||
grid = UI.Grid {
|
||||
x = 2, ex = -2, y = 7, ey = -2,
|
||||
columns = {
|
||||
{ heading = 'Side', key = 'side', width = 8 },
|
||||
{ heading = 'Type', key = 'type' },
|
||||
{ heading = 'ID', key = 'args', width = 4 },
|
||||
},
|
||||
},
|
||||
title = 'CCEmuX',
|
||||
description = 'CCEmuX peripherals',
|
||||
form = UI.Form {
|
||||
x = 2, ex = -2, y = 2, ey = 5,
|
||||
values = {
|
||||
side = 'bottom',
|
||||
type = 'wireless_modem',
|
||||
},
|
||||
manualControls = true,
|
||||
side = UI.Chooser {
|
||||
formLabel = 'Side', formKey = 'side',
|
||||
width = 10,
|
||||
},
|
||||
ptype = UI.Chooser {
|
||||
formLabel = 'Type', formKey = 'type',
|
||||
width = 10,
|
||||
choices = {
|
||||
{ name = 'Modem', value = 'wireless_modem' },
|
||||
{ name = 'Drive', value = 'disk_drive' },
|
||||
},
|
||||
},
|
||||
drive_id = UI.TextEntry {
|
||||
x = 19, y = 3,
|
||||
formKey = 'drive_id',
|
||||
shadowText = 'id',
|
||||
width = 5,
|
||||
limit = 3,
|
||||
transform = 'number',
|
||||
},
|
||||
add = UI.Button {
|
||||
x = -6, y = 3, width = 5,
|
||||
text = 'Add', event = 'form_ok',
|
||||
},
|
||||
},
|
||||
grid = UI.Grid {
|
||||
x = 2, ex = -2, y = 7, ey = -2,
|
||||
columns = {
|
||||
{ heading = 'Side', key = 'side', width = 8 },
|
||||
{ heading = 'Type', key = 'type' },
|
||||
{ heading = 'ID', key = 'args', width = 4 },
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
function tab:updatePeripherals(config)
|
||||
self.grid.values = { }
|
||||
for k,v in pairs(config) do
|
||||
table.insert(self.grid.values, {
|
||||
side = k,
|
||||
type = v.type,
|
||||
args = v.args and v.args.id,
|
||||
})
|
||||
end
|
||||
self.grid:update()
|
||||
self.grid.values = { }
|
||||
for k,v in pairs(config) do
|
||||
table.insert(self.grid.values, {
|
||||
side = k,
|
||||
type = v.type,
|
||||
args = v.args and v.args.id,
|
||||
})
|
||||
end
|
||||
self.grid:update()
|
||||
end
|
||||
|
||||
function tab:enable()
|
||||
local config = Config.load('ccemux')
|
||||
local config = Config.load('ccemux')
|
||||
|
||||
local choices = { }
|
||||
for _,k in pairs(sides) do
|
||||
table.insert(choices, { name = k, value = k })
|
||||
end
|
||||
self.form.side.choices = choices
|
||||
local choices = { }
|
||||
for _,k in pairs(sides) do
|
||||
table.insert(choices, { name = k, value = k })
|
||||
end
|
||||
self.form.side.choices = choices
|
||||
|
||||
self:updatePeripherals(config)
|
||||
UI.Tab.enable(self)
|
||||
self:updatePeripherals(config)
|
||||
UI.Tab.enable(self)
|
||||
|
||||
self.form.drive_id.enabled = false
|
||||
self.form.drive_id.enabled = false
|
||||
end
|
||||
|
||||
function tab:eventHandler(event)
|
||||
if event.type == 'form_complete' then
|
||||
if event.values.type == 'disk_drive' and not event.values.drive_id then
|
||||
self:emit({ type = 'error_message', message = 'Invalid drive ID' })
|
||||
else
|
||||
ccemux.detach(event.values.side)
|
||||
if event.type == 'form_complete' then
|
||||
if event.values.type == 'disk_drive' and not event.values.drive_id then
|
||||
self:emit({ type = 'error_message', message = 'Invalid drive ID' })
|
||||
else
|
||||
ccemux.detach(event.values.side)
|
||||
|
||||
local config = Config.load('ccemux')
|
||||
config[event.values.side] = {
|
||||
type = event.values.type
|
||||
}
|
||||
if event.values.type == 'disk_drive' then
|
||||
config[event.values.side].args = {
|
||||
id = event.values.drive_id
|
||||
}
|
||||
ccemux.attach(event.values.side, event.values.type, { id = event.values.drive_id })
|
||||
else
|
||||
ccemux.attach(event.values.side, event.values.type)
|
||||
end
|
||||
Config.update('ccemux', config)
|
||||
self:updatePeripherals(config)
|
||||
self.grid:draw()
|
||||
local config = Config.load('ccemux')
|
||||
config[event.values.side] = {
|
||||
type = event.values.type
|
||||
}
|
||||
if event.values.type == 'disk_drive' then
|
||||
config[event.values.side].args = {
|
||||
id = event.values.drive_id
|
||||
}
|
||||
ccemux.attach(event.values.side, event.values.type, { id = event.values.drive_id })
|
||||
else
|
||||
ccemux.attach(event.values.side, event.values.type)
|
||||
end
|
||||
Config.update('ccemux', config)
|
||||
self:updatePeripherals(config)
|
||||
self.grid:draw()
|
||||
|
||||
self:emit({ type = 'success_message', message = 'Attached' })
|
||||
end
|
||||
self:emit({ type = 'success_message', message = 'Attached' })
|
||||
end
|
||||
|
||||
elseif event.type == 'choice_change' then
|
||||
if event.element == self.form.ptype then
|
||||
self.form.drive_id.enabled = event.value == 'disk_drive'
|
||||
self.form:draw()
|
||||
end
|
||||
elseif event.type == 'choice_change' then
|
||||
if event.element == self.form.ptype then
|
||||
self.form.drive_id.enabled = event.value == 'disk_drive'
|
||||
self.form:draw()
|
||||
end
|
||||
|
||||
elseif event.type == 'grid_select' then
|
||||
local config = Config.load('ccemux')
|
||||
config[event.selected.side] = nil
|
||||
Config.update('ccemux', config)
|
||||
self:updatePeripherals(config)
|
||||
self.grid:draw()
|
||||
elseif event.type == 'grid_select' then
|
||||
local config = Config.load('ccemux')
|
||||
config[event.selected.side] = nil
|
||||
Config.update('ccemux', config)
|
||||
self:updatePeripherals(config)
|
||||
self.grid:draw()
|
||||
|
||||
self:emit({ type = 'success_message', message = 'Detached' })
|
||||
self:emit({ type = 'success_message', message = 'Detached' })
|
||||
|
||||
return true
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return tab
|
||||
|
||||
@@ -13,4 +13,7 @@
|
||||
* and more...
|
||||
]],
|
||||
license = 'MIT',
|
||||
required = {
|
||||
'core',
|
||||
},
|
||||
}
|
||||
|
||||
@@ -3,26 +3,26 @@ local Event = require('opus.event')
|
||||
local UI = require('opus.ui')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local peripheral = _G.peripheral
|
||||
local device = _G.device
|
||||
|
||||
--[[ -- PeripheralsPage -- ]] --
|
||||
local peripheralsPage = UI.Page {
|
||||
grid = UI.ScrollingGrid {
|
||||
ey = -2,
|
||||
columns = {
|
||||
--{ heading = 'Name', key = 'name' },
|
||||
{ heading = 'Type', key = 'type' },
|
||||
{ heading = 'Side', key = 'side' },
|
||||
},
|
||||
sortColumn = 'type',
|
||||
autospace = true,
|
||||
enable = function(self)
|
||||
local sides = peripheral.getNames()
|
||||
|
||||
Util.clear(self.values)
|
||||
for _,side in pairs(sides) do
|
||||
for _,v in pairs(device) do
|
||||
table.insert(self.values, {
|
||||
type = peripheral.getType(side),
|
||||
side = side
|
||||
type = v.type,
|
||||
side = v.side,
|
||||
name = v.name,
|
||||
})
|
||||
end
|
||||
self:update()
|
||||
@@ -75,49 +75,50 @@ local methodsPage = UI.Page {
|
||||
[ 'control-q' ] = '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)
|
||||
if event.type == 'back' then
|
||||
UI:setPage(peripheralsPage)
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
local Util = require('opus.util')
|
||||
|
||||
local device = _G.device
|
||||
local os = _G.os
|
||||
local peripheral = _G.peripheral
|
||||
local term = _G.term
|
||||
|
||||
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
|
||||
error('Syntax: debug <monitor>')
|
||||
|
||||
|
||||
@@ -306,7 +306,7 @@ local page = UI.Page {
|
||||
x = 2, y = 2, ey = -4, ex = -2,
|
||||
columns = {
|
||||
{ key = 'name', heading = 'Name' },
|
||||
{ key = 'dir', heading = 'Directory' },
|
||||
{ key = 'dir', heading = 'Directory', textColor = 'lightGray' },
|
||||
},
|
||||
accelerators = {
|
||||
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