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:
kepler155c@gmail.com
2020-05-02 22:22:30 -06:00
parent 8a9878b8e5
commit 9bf017fe27
13 changed files with 258 additions and 146 deletions

View File

@@ -38,7 +38,6 @@ local tab = UI.Tab {
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 {

View File

@@ -13,4 +13,7 @@
* and more... * and more...
]], ]],
license = 'MIT', license = 'MIT',
required = {
'core',
},
} }

View File

@@ -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,12 +75,10 @@ local methodsPage = UI.Page {
[ 'control-q' ] = 'back', [ 'control-q' ] = 'back',
backspace = 'back', backspace = 'back',
}, },
} enable = function(self, p)
function methodsPage:enable(p)
self.peripheral = p or self.peripheral self.peripheral = p or self.peripheral
p = peripheral.wrap(self.peripheral.side) p = device[self.peripheral.name]
if p.getDocs then if p.getDocs then
-- plethora -- plethora
self.grid.values = { } self.grid.values = { }
@@ -93,12 +91,14 @@ function methodsPage:enable(p)
elseif not p.getAdvancedMethodsData then elseif not p.getAdvancedMethodsData then
-- computercraft -- computercraft
self.grid.values = { } self.grid.values = { }
for name in pairs(p) do for k,v in pairs(p) do
if type(v) == 'function' then
table.insert(self.grid.values, { table.insert(self.grid.values, {
name = name, name = k,
noext = true, noext = true,
}) })
end end
end
else else
-- open peripherals -- open peripherals
self.grid.values = p.getAdvancedMethodsData() self.grid.values = p.getAdvancedMethodsData()
@@ -116,7 +116,8 @@ function methodsPage:enable(p)
UI.Page.enable(self) UI.Page.enable(self)
self:setFocus(self.grid) self:setFocus(self.grid)
end end,
}
function methodsPage:eventHandler(event) function methodsPage:eventHandler(event)
if event.type == 'back' then if event.type == 'back' then

View File

@@ -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>')

View File

@@ -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
View 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'