Compare commits
13 Commits
main
...
ui-enhance
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d17162b49d | ||
|
|
949c485539 | ||
|
|
3246579ab1 | ||
|
|
6b429a26e4 | ||
|
|
ef6cde3013 | ||
|
|
569dd5572d | ||
|
|
3321866ba3 | ||
|
|
1cbe87033d | ||
|
|
0a7ec352cc | ||
|
|
f655cc5965 | ||
|
|
6bb4149113 | ||
|
|
e2aac13e8f | ||
|
|
cdea6e4aed |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,2 @@
|
||||
/etc/fstab
|
||||
/etc/recipes2.db
|
||||
/.vscode
|
||||
|
||||
16
README.md
16
README.md
@@ -1,18 +1,2 @@
|
||||
# opus-apps
|
||||
Applications for Opus OS
|
||||
|
||||
## Installing an application
|
||||
To install an application, follow these steps
|
||||
1. Start your OpusOS Computer
|
||||
2. Go to the System tab on the main menu
|
||||
3. Find the packages app and open it
|
||||
4. Select the package you want
|
||||
5. Select the package and press the `+` button
|
||||
6. Your application should get installed!
|
||||
|
||||
## Updating your applications
|
||||
To update your applications, follow these steps
|
||||
1. Start your OpusOS Computer
|
||||
2. Go to the System tab on the main menu
|
||||
3. Find the packages app and open it
|
||||
4. Press the `Update All` button
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
title = 'busted',
|
||||
repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/moonscript',
|
||||
description = [[WIP]],
|
||||
license = 'MIT',
|
||||
required = {
|
||||
'penlight',
|
||||
},
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
return {
|
||||
-- Returns the monotonic time the system has been up, in secconds.
|
||||
monotime = function()
|
||||
return os.clock()
|
||||
end,
|
||||
|
||||
-- Sleep for n seconds.
|
||||
sleep = function(n)
|
||||
os.sleep(n)
|
||||
end,
|
||||
|
||||
-- Returns the current system time, 1970 (UTC), in secconds.
|
||||
gettime = function()
|
||||
return os.epoch('utc') / 1000
|
||||
end,
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
return {
|
||||
isatty = function()
|
||||
return false
|
||||
end,
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
packages/busted/busted urlfs https://raw.githubusercontent.com/Olivine-Labs/busted/master/bin/busted
|
||||
rom/modules/main/busted gitfs Olivine-Labs/busted/master/busted
|
||||
rom/modules/main/mediator.lua urlfs https://raw.githubusercontent.com/Olivine-Labs/mediator_lua/master/src/mediator.lua
|
||||
rom/modules/main/cliargs gitfs amireh/lua_cliargs/master/src/cliargs
|
||||
rom/modules/main/luassert gitfs Olivine-Labs/luassert/master/src
|
||||
rom/modules/main/say.lua urlfs https://raw.githubusercontent.com/Olivine-Labs/say/master/src/init.lua
|
||||
rom/modules/main/term.lua linkfs packages/busted/depend/term.lua
|
||||
rom/modules/main/system.lua linkfs packages/busted/depend/system.lua
|
||||
@@ -21,4 +21,11 @@ Restorable history
|
||||
Partial CCKernel2 support
|
||||
Full compatibility with CraftOS shell.lua]],
|
||||
license = 'MIT',
|
||||
install = [[
|
||||
require('opus.alternate').set('shell', 'packages/cash/cash.lua')
|
||||
require('opus.util').writeFile('.cashrc', 'set TERMINATE_QUIT=yes')
|
||||
]],
|
||||
uninstall = [[
|
||||
require('opus.alternate').remove('shell', 'packages/cash/cash.lua')
|
||||
]],
|
||||
}
|
||||
|
||||
@@ -1,20 +1,16 @@
|
||||
local ccemux = _G.ccemux
|
||||
local fs = _G.fs
|
||||
local textutils = _G.textutils
|
||||
local peripheral = _G.peripheral
|
||||
|
||||
if ccemux then
|
||||
-- add a System setup tab
|
||||
fs.mount('sys/apps/system/ccemux.lua', 'linkfs', 'packages/ccemux/system/ccemux.lua')
|
||||
|
||||
_G.kernel.hook('clipboard_copy', function(_, args)
|
||||
local data = args[1]
|
||||
if type(data) == 'table' then
|
||||
local s, m = pcall(textutils.serialize, data)
|
||||
data = s and m or tostring(data)
|
||||
end
|
||||
local Config = require('opus.config')
|
||||
|
||||
if data then
|
||||
ccemux.setClipboard(data)
|
||||
for k,v in pairs(Config.load('ccemux')) do
|
||||
if not peripheral.getType(k) then
|
||||
ccemux.attach(k, v.type, v.args)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
local ccemux
|
||||
ccemux = _G.ccemux
|
||||
local fs
|
||||
fs = _G.fs
|
||||
local peripheral
|
||||
peripheral = _G.peripheral
|
||||
local unserialize
|
||||
unserialize = _G.textutils.unserialize
|
||||
local CONFIG = 'usr/config/ccemux'
|
||||
if ccemux and fs.exists(CONFIG) then
|
||||
local f = fs.open(CONFIG, 'r')
|
||||
local c = unserialize(f.readAll())
|
||||
f.close()
|
||||
for k, v in pairs(c) do
|
||||
if not peripheral.getType(k) then
|
||||
ccemux.attach(k, v.type, v.args)
|
||||
print(k)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,16 +0,0 @@
|
||||
import ccemux from _G
|
||||
import fs from _G
|
||||
import peripheral from _G
|
||||
import unserialize from _G.textutils
|
||||
|
||||
CONFIG = 'usr/config/ccemux'
|
||||
|
||||
if ccemux and fs.exists CONFIG
|
||||
f = fs.open(CONFIG, 'r')
|
||||
c = unserialize(f.readAll())
|
||||
f.close()
|
||||
|
||||
for k,v in pairs c
|
||||
if not peripheral.getType(k)
|
||||
ccemux.attach(k, v.type, v.args)
|
||||
print k
|
||||
@@ -1,13 +1,12 @@
|
||||
local Config = require('opus.config')
|
||||
local UI = require('opus.ui')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local ccemux = _G.ccemux
|
||||
|
||||
local sides = { 'bottom', 'top', 'back', 'front', 'right', 'left' }
|
||||
|
||||
local tab = UI.Tab {
|
||||
title = 'CCEmuX',
|
||||
tabTitle = 'CCEmuX',
|
||||
description = 'CCEmuX peripherals',
|
||||
form = UI.Form {
|
||||
x = 2, ex = -2, y = 2, ey = 5,
|
||||
@@ -39,6 +38,7 @@ local tab = UI.Tab {
|
||||
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 {
|
||||
@@ -46,7 +46,6 @@ local tab = UI.Tab {
|
||||
columns = {
|
||||
{ heading = 'Side', key = 'side', width = 8 },
|
||||
{ heading = 'Type', key = 'type' },
|
||||
{ heading = 'ID', key = 'args', width = 4 },
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -57,29 +56,13 @@ function tab:updatePeripherals(config)
|
||||
table.insert(self.grid.values, {
|
||||
side = k,
|
||||
type = v.type,
|
||||
args = v.args and v.args.id,
|
||||
args = v.args,
|
||||
})
|
||||
end
|
||||
self.grid:update()
|
||||
end
|
||||
|
||||
function tab.bootCheck()
|
||||
local startupFile = 'packages/ccemux/bin/emustartup.lua'
|
||||
|
||||
local c = Util.readTable('.startup.boot')
|
||||
if c then
|
||||
for _,v in pairs(c.preload) do
|
||||
if v == startupFile then
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
table.insert(c.preload, startupFile)
|
||||
Util.writeTable('.startup.boot', c)
|
||||
end
|
||||
|
||||
function tab:enable()
|
||||
self:bootCheck()
|
||||
local config = Config.load('ccemux')
|
||||
|
||||
local choices = { }
|
||||
@@ -100,6 +83,7 @@ function tab:eventHandler(event)
|
||||
self:emit({ type = 'error_message', message = 'Invalid drive ID' })
|
||||
else
|
||||
ccemux.detach(event.values.side)
|
||||
ccemux.attach(event.values.side, event.values.type)
|
||||
|
||||
local config = Config.load('ccemux')
|
||||
config[event.values.side] = {
|
||||
@@ -109,9 +93,6 @@ function tab:eventHandler(event)
|
||||
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)
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
title = 'Collections',
|
||||
repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/collections',
|
||||
description = [[Collections (rework)
|
||||
See: https://github.com/imliam/Lua-Collections
|
||||
|
||||
Collections are like tables on steroids. They are designed to act as a fluent wrapper when working with structured data, offering the developer convenience for common tasks.]],
|
||||
license = 'MIT',
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1 +0,0 @@
|
||||
packages/collections/tests/tests.lua urlfs https://raw.githubusercontent.com/imliam/Lua-Collections/master/tests.lua
|
||||
File diff suppressed because it is too large
Load Diff
@@ -13,7 +13,4 @@
|
||||
* and more...
|
||||
]],
|
||||
license = 'MIT',
|
||||
required = {
|
||||
'core',
|
||||
},
|
||||
}
|
||||
|
||||
@@ -27,6 +27,9 @@ local function unregisterApp(key)
|
||||
end
|
||||
end
|
||||
|
||||
local sandboxEnv = Util.shallowCopy(_ENV)
|
||||
setmetatable(sandboxEnv, { __index = _G })
|
||||
|
||||
multishell.setTitle(multishell.getCurrent(), 'App Store')
|
||||
UI:configure('Appstore', ...)
|
||||
|
||||
@@ -57,7 +60,7 @@ local function downloadApp(app)
|
||||
end
|
||||
|
||||
local function runApp(app, checkExists, ...)
|
||||
local env = shell.makeEnv(_ENV)
|
||||
|
||||
local path, fn
|
||||
local args = { ... }
|
||||
|
||||
@@ -78,13 +81,14 @@ local function runApp(app, checkExists, ...)
|
||||
error('Failed to download')
|
||||
end
|
||||
|
||||
_G.setfenv(fn, env)
|
||||
_G.setfenv(fn, sandboxEnv)
|
||||
fn(table.unpack(args))
|
||||
end
|
||||
end
|
||||
|
||||
multishell.openTab(_ENV, {
|
||||
multishell.openTab({
|
||||
title = app.name,
|
||||
env = sandboxEnv,
|
||||
path = path,
|
||||
fn = fn,
|
||||
focused = true,
|
||||
|
||||
@@ -3,26 +3,26 @@ local Event = require('opus.event')
|
||||
local UI = require('opus.ui')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local device = _G.device
|
||||
local peripheral = _G.peripheral
|
||||
|
||||
--[[ -- 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 _,v in pairs(device) do
|
||||
for _,side in pairs(sides) do
|
||||
table.insert(self.values, {
|
||||
type = v.type,
|
||||
side = v.side,
|
||||
name = v.name,
|
||||
type = peripheral.getType(side),
|
||||
side = side
|
||||
})
|
||||
end
|
||||
self:update()
|
||||
@@ -75,50 +75,49 @@ 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)
|
||||
@@ -132,7 +131,7 @@ end
|
||||
function methodsPage:getDocumentation()
|
||||
local method = self.grid:getSelected()
|
||||
|
||||
if not method or method.noext then -- computercraft docs
|
||||
if method.noext then -- computercraft docs
|
||||
return 'No documentation'
|
||||
end
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ function page:enable()
|
||||
self.eject.value = config.eject
|
||||
self.automatic.value = config.automatic
|
||||
|
||||
self.dir:move(math.floor((self.width / 2) - 3) + 1, self.dir.y)
|
||||
self.dir.x = math.floor((self.width / 2) - 3) + 1
|
||||
|
||||
UI.Page.enable(self)
|
||||
end
|
||||
@@ -218,7 +218,7 @@ function page:copy()
|
||||
self.progress:sync()
|
||||
|
||||
self.progress.value = 0
|
||||
-- self.progress:clear()
|
||||
self.progress:clear()
|
||||
|
||||
self:scan()
|
||||
|
||||
|
||||
@@ -30,12 +30,23 @@ local page = UI.Page {
|
||||
getDisplayValues = function(_, row)
|
||||
row = Util.shallowCopy(row)
|
||||
|
||||
local function tovalue(s)
|
||||
if type(s) == 'table' then
|
||||
return 'table'
|
||||
end
|
||||
return s
|
||||
end
|
||||
|
||||
for k,v in pairs(row) do
|
||||
row[k] = type(v) == 'table' and 'table' or v
|
||||
row[k] = tovalue(v)
|
||||
end
|
||||
|
||||
return row
|
||||
end,
|
||||
draw = function(self)
|
||||
self:adjustWidth()
|
||||
UI.Grid.draw(self)
|
||||
end,
|
||||
},
|
||||
accelerators = {
|
||||
f = 'filter',
|
||||
@@ -60,7 +71,7 @@ local page = UI.Page {
|
||||
self.menuBar:draw()
|
||||
|
||||
elseif event.type == 'grid_select' then
|
||||
multishell.openTab(_ENV, {
|
||||
multishell.openTab({
|
||||
path = 'sys/apps/Lua.lua',
|
||||
args = { event.selected },
|
||||
focused = true,
|
||||
@@ -88,25 +99,30 @@ local page = UI.Page {
|
||||
end,
|
||||
}
|
||||
|
||||
local updated = false
|
||||
local timerId = os.startTimer(1)
|
||||
|
||||
Event.addRoutine(function()
|
||||
while true do
|
||||
local _, id = os.pullEvent('timer')
|
||||
if id == timerId then
|
||||
while #page.grid.values > 100 do
|
||||
table.remove(page.grid.values)
|
||||
if updated then
|
||||
while #page.grid.values > 100 do -- page.grid.height do
|
||||
table.remove(page.grid.values, 100) -- #page.grid.values)
|
||||
end
|
||||
updated = false
|
||||
page.grid:update()
|
||||
page.grid:draw()
|
||||
page:sync()
|
||||
end
|
||||
timerId = nil
|
||||
page.grid:update()
|
||||
page.grid:draw()
|
||||
page:sync()
|
||||
timerId = os.startTimer(1)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
local hookFunction = function(event, e)
|
||||
if not page.filtered[event] and not page.paused and not (event == 'timer' and e[1] == timerId) then
|
||||
updated = true
|
||||
table.insert(page.grid.values, 1, {
|
||||
event = event,
|
||||
p1 = e[1],
|
||||
@@ -115,7 +131,6 @@ local hookFunction = function(event, e)
|
||||
p4 = e[4],
|
||||
p5 = e[5],
|
||||
})
|
||||
timerId = timerId or os.startTimer(.1)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ local Socket = require('opus.socket')
|
||||
local UI = require('opus.ui')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local colors = _G.colors
|
||||
local fs = _G.fs
|
||||
local multishell = _ENV.multishell
|
||||
local network = _G.network
|
||||
@@ -30,7 +31,7 @@ local socket, turtle, page
|
||||
|
||||
page = UI.Page {
|
||||
coords = UI.Window {
|
||||
backgroundColor = 'black',
|
||||
backgroundColor = colors.black,
|
||||
height = 3,
|
||||
marginTop = 1, marginLeft = 1,
|
||||
draw = function(self)
|
||||
@@ -49,149 +50,156 @@ page = UI.Page {
|
||||
},
|
||||
tabs = UI.Tabs {
|
||||
x = 1, y = 4, ey = -2,
|
||||
UI.Tab {
|
||||
title = 'Run',
|
||||
scripts = UI.ScrollingGrid {
|
||||
backgroundColor = 'primary',
|
||||
columns = {
|
||||
{ heading = '', key = 'label' },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'label',
|
||||
autospace = true,
|
||||
draw = function(self)
|
||||
Util.clear(self.values)
|
||||
local files = fs.list(SCRIPTS_PATH)
|
||||
for _,path in pairs(files) do
|
||||
table.insert(self.values, { label = path, path = fs.combine(SCRIPTS_PATH, path) })
|
||||
end
|
||||
self:update()
|
||||
UI.ScrollingGrid.draw(self)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
page:runScript(event.selected.label)
|
||||
else
|
||||
return UI.ScrollingGrid.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
scripts = UI.ScrollingGrid {
|
||||
tabTitle = 'Run',
|
||||
backgroundColor = colors.cyan,
|
||||
columns = {
|
||||
{ heading = '', key = 'label' },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'label',
|
||||
autospace = true,
|
||||
draw = function(self)
|
||||
Util.clear(self.values)
|
||||
local files = fs.list(SCRIPTS_PATH)
|
||||
for _,path in pairs(files) do
|
||||
table.insert(self.values, { label = path, path = fs.combine(SCRIPTS_PATH, path) })
|
||||
end
|
||||
self:update()
|
||||
UI.ScrollingGrid.draw(self)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
page:runScript(event.selected.label)
|
||||
else
|
||||
return UI.ScrollingGrid.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
},
|
||||
UI.Tab {
|
||||
title = 'Select',
|
||||
turtles = UI.ScrollingGrid {
|
||||
backgroundColor = 'primary',
|
||||
columns = {
|
||||
{ heading = 'label', key = 'label' },
|
||||
{ heading = 'Dist', key = 'distance' },
|
||||
{ heading = 'Status', key = 'status' },
|
||||
{ heading = 'Fuel', key = 'fuel' },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'label',
|
||||
autospace = true,
|
||||
getDisplayValues = function(_, row)
|
||||
row = Util.shallowCopy(row)
|
||||
if row.fuel then
|
||||
row.fuel = Util.toBytes(row.fuel)
|
||||
turtles = UI.ScrollingGrid {
|
||||
tabTitle = 'Select',
|
||||
backgroundColor = colors.cyan,
|
||||
columns = {
|
||||
{ heading = 'label', key = 'label' },
|
||||
{ heading = 'Dist', key = 'distance' },
|
||||
{ heading = 'Status', key = 'status' },
|
||||
{ heading = 'Fuel', key = 'fuel' },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'label',
|
||||
autospace = true,
|
||||
getDisplayValues = function(_, row)
|
||||
row = Util.shallowCopy(row)
|
||||
if row.fuel then
|
||||
row.fuel = Util.toBytes(row.fuel)
|
||||
end
|
||||
if row.distance then
|
||||
row.distance = Util.round(row.distance, 1)
|
||||
end
|
||||
return row
|
||||
end,
|
||||
draw = function(self)
|
||||
Util.clear(self.values)
|
||||
for _,v in pairs(network) do
|
||||
if v.fuel then
|
||||
table.insert(self.values, v)
|
||||
end
|
||||
if row.distance then
|
||||
row.distance = Util.round(row.distance, 1)
|
||||
end
|
||||
self:update()
|
||||
UI.ScrollingGrid.draw(self)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
turtle = event.selected
|
||||
config.id = event.selected.id
|
||||
Config.update('Turtles', config)
|
||||
multishell.setTitle(multishell.getCurrent(), turtle.label)
|
||||
if socket then
|
||||
socket:close()
|
||||
socket = nil
|
||||
end
|
||||
return row
|
||||
end,
|
||||
draw = function(self)
|
||||
Util.clear(self.values)
|
||||
for _,v in pairs(network) do
|
||||
if v.fuel then
|
||||
else
|
||||
return UI.ScrollingGrid.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
},
|
||||
inventory = UI.ScrollingGrid {
|
||||
backgroundColor = colors.cyan,
|
||||
tabTitle = 'Inv',
|
||||
columns = {
|
||||
{ heading = '', key = 'index', width = 2 },
|
||||
{ heading = '', key = 'count', width = 2 },
|
||||
{ heading = 'Inventory', key = 'key' },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'index',
|
||||
getRowTextColor = function(self, row, selected)
|
||||
if turtle and row.selected then
|
||||
return colors.yellow
|
||||
end
|
||||
return UI.ScrollingGrid.getRowTextColor(self, row, selected)
|
||||
end,
|
||||
draw = function(self)
|
||||
local t = turtle
|
||||
Util.clear(self.values)
|
||||
if t then
|
||||
for k,v in pairs(t.inv or { }) do -- new method (less data)
|
||||
local index, count = k:match('(%d+),(%d+)')
|
||||
v = {
|
||||
index = tonumber(index),
|
||||
key = v,
|
||||
count = tonumber(count),
|
||||
}
|
||||
table.insert(self.values, v)
|
||||
end
|
||||
|
||||
for _,v in pairs(t.inventory or { }) do
|
||||
if v.count > 0 then
|
||||
table.insert(self.values, v)
|
||||
end
|
||||
end
|
||||
self:update()
|
||||
UI.ScrollingGrid.draw(self)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
turtle = event.selected
|
||||
config.id = event.selected.id
|
||||
Config.update('Turtles', config)
|
||||
multishell.setTitle(multishell.getCurrent(), turtle.label)
|
||||
if socket then
|
||||
socket:close()
|
||||
socket = nil
|
||||
end
|
||||
else
|
||||
return UI.ScrollingGrid.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
},
|
||||
},
|
||||
UI.Tab {
|
||||
title = 'Inv',
|
||||
inventory = UI.ScrollingGrid {
|
||||
backgroundColor = 'primary',
|
||||
columns = {
|
||||
{ heading = '', key = 'index', width = 2 },
|
||||
{ heading = '', key = 'count', width = 2 },
|
||||
{ heading = 'Inventory', key = 'key' },
|
||||
},
|
||||
disableHeader = true,
|
||||
sortColumn = 'index',
|
||||
getRowTextColor = function(self, row, selected)
|
||||
if turtle and row.selected then
|
||||
return 'yellow'
|
||||
end
|
||||
return UI.ScrollingGrid.getRowTextColor(self, row, selected)
|
||||
end,
|
||||
draw = function(self)
|
||||
local t = turtle
|
||||
Util.clear(self.values)
|
||||
if t then
|
||||
for k,v in pairs(t.inv or { }) do -- new method (less data)
|
||||
local index, count = k:match('(%d+),(%d+)')
|
||||
v = {
|
||||
index = tonumber(index),
|
||||
key = v,
|
||||
count = tonumber(count),
|
||||
}
|
||||
table.insert(self.values, v)
|
||||
end
|
||||
|
||||
for _,v in pairs(t.inventory or { }) do
|
||||
if v.count > 0 then
|
||||
table.insert(self.values, v)
|
||||
end
|
||||
for _,v in pairs(self.values) do
|
||||
if v.index == t.slotIndex then
|
||||
v.selected = true
|
||||
end
|
||||
|
||||
for _,v in pairs(self.values) do
|
||||
if v.index == t.slotIndex then
|
||||
v.selected = true
|
||||
end
|
||||
if v.key then
|
||||
v.key = itemDB:getName(v.key)
|
||||
end
|
||||
if v.key then
|
||||
v.key = itemDB:getName(v.key)
|
||||
end
|
||||
end
|
||||
self:adjustWidth()
|
||||
self:update()
|
||||
UI.ScrollingGrid.draw(self)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
local fn = string.format('turtle.select(%d)', event.selected.index)
|
||||
page:runFunction(fn)
|
||||
else
|
||||
return UI.ScrollingGrid.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
},
|
||||
end
|
||||
self:adjustWidth()
|
||||
self:update()
|
||||
UI.ScrollingGrid.draw(self)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
local fn = string.format('turtle.select(%d)', event.selected.index)
|
||||
page:runFunction(fn)
|
||||
else
|
||||
return UI.ScrollingGrid.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
},
|
||||
UI.Tab {
|
||||
title = 'Action',
|
||||
backgroundColor = 'primary',
|
||||
--[[
|
||||
policy = UI.ScrollingGrid {
|
||||
tabTitle = 'Mod',
|
||||
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
|
||||
columns = {
|
||||
{ heading = 'label', key = 'label' },
|
||||
},
|
||||
values = policies,
|
||||
disableHeader = true,
|
||||
sortColumn = 'label',
|
||||
autospace = true,
|
||||
},
|
||||
]]
|
||||
action = UI.Window {
|
||||
tabTitle = 'Action',
|
||||
backgroundColor = colors.cyan,
|
||||
moveUp = UI.Button {
|
||||
x = 5, y = 2,
|
||||
text = 'up',
|
||||
@@ -223,43 +231,10 @@ page = UI.Page {
|
||||
fn = 'turtle.turnRight',
|
||||
},
|
||||
info = UI.TextArea {
|
||||
x = 15, y = 1,
|
||||
x = 15, y = 2,
|
||||
inactive = true,
|
||||
},
|
||||
showBlocks = function(self)
|
||||
local script = [[
|
||||
local function inspect(direction)
|
||||
local s,b = turtle['inspect' .. (direction or '')]()
|
||||
if not s then
|
||||
return 'minecraft:air:0'
|
||||
end
|
||||
return string.format('%s:%d', b.name, b.metadata)
|
||||
end
|
||||
|
||||
local bu, bf, bd = inspect('Up'), inspect(), inspect('Down')
|
||||
return string.format('%s\n%s\n%s', bu, bf, bd)
|
||||
]]
|
||||
|
||||
local s, m = page:runFunction(script, true)
|
||||
self.info:setText(s or m)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'button_press' then
|
||||
if event.button.fn then
|
||||
page:runFunction(event.button.fn, event.button.nowrap)
|
||||
self:showBlocks()
|
||||
end
|
||||
return true
|
||||
end
|
||||
return UI.Tab.eventHandler(self, event)
|
||||
end,
|
||||
}
|
||||
},
|
||||
enable = function(self)
|
||||
if config.tab then
|
||||
self:selectTab(Util.find(self, 'title', config.tab))
|
||||
end
|
||||
UI.Tabs.enable(self)
|
||||
end
|
||||
},
|
||||
statusBar = UI.StatusBar {
|
||||
values = { },
|
||||
@@ -356,6 +331,24 @@ function page:runScript(scriptName)
|
||||
end
|
||||
end
|
||||
|
||||
function page:showBlocks()
|
||||
local script = [[
|
||||
local function inspect(direction)
|
||||
local s,b = turtle['inspect' .. (direction or '')]()
|
||||
if not s then
|
||||
return 'minecraft:air:0'
|
||||
end
|
||||
return string.format('%s:%d', b.name, b.metadata)
|
||||
end
|
||||
|
||||
local bu, bf, bd = inspect('Up'), inspect(), inspect('Down')
|
||||
return string.format('%s\n%s\n%s', bu, bf, bd)
|
||||
]]
|
||||
|
||||
local s, m = self:runFunction(script, true)
|
||||
self.tabs.action.info:setText(s or m)
|
||||
end
|
||||
|
||||
function page:eventHandler(event)
|
||||
if event.type == 'quit' then
|
||||
UI:quit()
|
||||
@@ -364,6 +357,13 @@ function page:eventHandler(event)
|
||||
config.tab = event.button.text
|
||||
Config.update('Turtles', config)
|
||||
|
||||
elseif event.type == 'button_press' then
|
||||
if event.button.fn then
|
||||
self:runFunction(event.button.fn, event.button.nowrap)
|
||||
self:showBlocks()
|
||||
elseif event.button.script then
|
||||
self:runScript(event.button.script)
|
||||
end
|
||||
else
|
||||
return UI.Page.eventHandler(self, event)
|
||||
end
|
||||
@@ -393,5 +393,9 @@ Event.onInterval(1, function()
|
||||
end
|
||||
end)
|
||||
|
||||
if config.tab then
|
||||
page.tabs.tabBar:selectTab(config.tab)
|
||||
end
|
||||
|
||||
UI:setPage(page)
|
||||
UI:start()
|
||||
|
||||
@@ -6,49 +6,3 @@ end
|
||||
|
||||
_ENV.shell.setCompletionFunction("packages/common/edit.lua", c)
|
||||
_ENV.shell.setCompletionFunction("packages/common/hexedit.lua", c)
|
||||
|
||||
_ENV.shell.registerHandler(function(env, command, args)
|
||||
if command:match('^!') then
|
||||
return {
|
||||
title = 'lua',
|
||||
path = table.concat({ command:match('^!(.+)'), table.unpack(args) }, ' '),
|
||||
args = args,
|
||||
load = function(s)
|
||||
return function()
|
||||
local fn, m
|
||||
local wrapped
|
||||
|
||||
fn = load('return (' ..s.. ')', 'lua', nil, env)
|
||||
|
||||
if fn then
|
||||
fn = load('return {' ..s.. '}', 'lua', nil, env)
|
||||
wrapped = true
|
||||
end
|
||||
|
||||
if fn then
|
||||
fn, m = pcall(fn)
|
||||
if #m <= 1 and wrapped then
|
||||
m = m[1]
|
||||
end
|
||||
else
|
||||
fn, m = load(s, 'lua', nil, env)
|
||||
if fn then
|
||||
fn, m = pcall(fn)
|
||||
end
|
||||
end
|
||||
|
||||
if fn then
|
||||
if m or wrapped then
|
||||
require('opus.util').print(m or 'nil')
|
||||
else
|
||||
print()
|
||||
end
|
||||
else
|
||||
_G.printError(m)
|
||||
end
|
||||
end
|
||||
end,
|
||||
env = env,
|
||||
}
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
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 = not args[1] and term.current() or
|
||||
device[args[1]] or
|
||||
peripheral.wrap(args[1]) or
|
||||
local mon = args[1] and peripheral.wrap(args[1]) or
|
||||
peripheral.find('monitor') or
|
||||
error('Syntax: debug <monitor>')
|
||||
|
||||
mon.clear()
|
||||
if mon.setTextScale then
|
||||
mon.setTextScale(.5)
|
||||
end
|
||||
mon.setTextScale(.5)
|
||||
mon.setCursorPos(1, 1)
|
||||
|
||||
local oldDebug = _G._syslog
|
||||
@@ -24,16 +19,13 @@ _G._syslog = function(...)
|
||||
local oldTerm = term.redirect(mon)
|
||||
Util.print(...)
|
||||
term.redirect(oldTerm)
|
||||
oldDebug(...)
|
||||
end
|
||||
|
||||
repeat
|
||||
local e, side = os.pullEventRaw('monitor_touch')
|
||||
if e == 'monitor_touch' and side == mon.side then
|
||||
mon.clear()
|
||||
if mon.setTextScale then
|
||||
mon.setTextScale(.5)
|
||||
end
|
||||
mon.setTextScale(.5)
|
||||
mon.setCursorPos(1, 1)
|
||||
end
|
||||
until e == 'terminate'
|
||||
|
||||
202
common/edit.lua
202
common/edit.lua
@@ -1,15 +1,15 @@
|
||||
local Array = require('opus.array')
|
||||
local Config = require('opus.config')
|
||||
local fuzzy = require('opus.fuzzy')
|
||||
local UI = require('opus.ui')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local device = _G.device
|
||||
local fs = _G.fs
|
||||
local keys = _G.keys
|
||||
local multishell = _ENV.multishell
|
||||
local os = _G.os
|
||||
local shell = _ENV.shell
|
||||
local term = _G.term.current()
|
||||
local term = _G.term
|
||||
local textutils = _G.textutils
|
||||
|
||||
local _format = string.format
|
||||
@@ -202,6 +202,7 @@ local page = UI.Page {
|
||||
label = 'Find',
|
||||
search = UI.TextEntry {
|
||||
x = 7, ex = -3,
|
||||
limit = 512,
|
||||
accelerators = {
|
||||
[ 'enter' ] = 'accept',
|
||||
},
|
||||
@@ -231,6 +232,7 @@ local page = UI.Page {
|
||||
label = 'Save',
|
||||
filename = UI.TextEntry {
|
||||
x = 7, ex = -3,
|
||||
limit = 512,
|
||||
accelerators = {
|
||||
[ 'enter' ] = 'accept',
|
||||
},
|
||||
@@ -304,7 +306,7 @@ local page = UI.Page {
|
||||
x = 2, y = 2, ey = -4, ex = -2,
|
||||
columns = {
|
||||
{ key = 'name', heading = 'Name' },
|
||||
{ key = 'dir', heading = 'Directory', textColor = 'lightGray' },
|
||||
{ key = 'dir', heading = 'Directory' },
|
||||
},
|
||||
accelerators = {
|
||||
backspace = 'slide_hide',
|
||||
@@ -318,7 +320,7 @@ local page = UI.Page {
|
||||
show = function(self)
|
||||
local t = { }
|
||||
for _,v in pairs(config.recent or { }) do
|
||||
_insert(t, { name = fs.getName(v), dir = fs.getDir(v), path = v })
|
||||
table.insert(t, { name = fs.getName(v), dir = fs.getDir(v), path = v })
|
||||
end
|
||||
self.grid:setValues(t)
|
||||
self.grid:setIndex(1)
|
||||
@@ -334,23 +336,102 @@ local page = UI.Page {
|
||||
return UI.SlideOut.eventHandler(self, event)
|
||||
end,
|
||||
},
|
||||
quick_open = UI.QuickSelect {
|
||||
modal = true,
|
||||
enable = function() end,
|
||||
quick_open = UI.SlideOut {
|
||||
filter_entry = UI.TextEntry {
|
||||
x = 2, y = 2, ex = -2,
|
||||
limit = 256,
|
||||
shadowText = 'File name',
|
||||
accelerators = {
|
||||
[ 'enter' ] = 'accept',
|
||||
[ 'up' ] = 'grid_up',
|
||||
[ 'down' ] = 'grid_down',
|
||||
},
|
||||
},
|
||||
grid = UI.ScrollingGrid {
|
||||
x = 2, y = 3, ex = -2, ey = -4,
|
||||
disableHeader = true,
|
||||
columns = {
|
||||
{ key = 'name' },
|
||||
{ key = 'dir', textColor = 'lightGray' },
|
||||
},
|
||||
accelerators = {
|
||||
grid_select = 'accept',
|
||||
},
|
||||
},
|
||||
cancel = UI.Button {
|
||||
x = -9, y = -2,
|
||||
text = 'Cancel',
|
||||
event = 'slide_hide',
|
||||
},
|
||||
apply_filter = function(self, filter)
|
||||
local t = { }
|
||||
if filter then
|
||||
filter = filter:lower()
|
||||
self.grid.sortColumn = 'score'
|
||||
self.grid.inverseSort = true
|
||||
|
||||
for _,v in pairs(self.listing) do
|
||||
v.score = fuzzy(v.lname, filter)
|
||||
if v.score then
|
||||
_insert(t, v)
|
||||
end
|
||||
end
|
||||
else
|
||||
self.grid.sortColumn = 'lname'
|
||||
self.grid.inverseSort = false
|
||||
t = self.listing
|
||||
end
|
||||
|
||||
self.grid:setValues(t)
|
||||
self.grid:setIndex(1)
|
||||
end,
|
||||
show = function(self)
|
||||
UI.QuickSelect.enable(self)
|
||||
self:focusFirst()
|
||||
self:draw()
|
||||
local listing = { }
|
||||
local function recurse(dir)
|
||||
local files = fs.list(dir)
|
||||
for _,f in ipairs(files) do
|
||||
local fullName = fs.combine(dir, f)
|
||||
if fs.native.isDir(fullName) then -- skip virtual dirs
|
||||
if f ~= '.git' then recurse(fullName) end
|
||||
else
|
||||
_insert(listing, {
|
||||
name = f,
|
||||
dir = dir,
|
||||
lname = f:lower(),
|
||||
fullName = fullName,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
recurse('')
|
||||
self.listing = listing
|
||||
self:apply_filter()
|
||||
self.filter_entry:reset()
|
||||
UI.SlideOut.show(self)
|
||||
self:addTransition('expandUp', { easing = 'outBounce', ticks = 12 })
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'select_cancel' then
|
||||
self:disable()
|
||||
elseif event.type == 'select_file' then
|
||||
self:disable()
|
||||
actions.process('open', event.file)
|
||||
if event.type == 'grid_up' then
|
||||
self.grid:emit({ type = 'scroll_up' })
|
||||
|
||||
elseif event.type == 'grid_down' then
|
||||
self.grid:emit({ type = 'scroll_down' })
|
||||
|
||||
elseif event.type == 'accept' then
|
||||
local sel = self.grid:getSelected()
|
||||
if sel then
|
||||
actions.process('open', sel.fullName)
|
||||
self:hide()
|
||||
end
|
||||
|
||||
elseif event.type == 'text_change' then
|
||||
self:apply_filter(event.text)
|
||||
self.grid:draw()
|
||||
|
||||
else
|
||||
return UI.SlideOut.eventHandler(self, event)
|
||||
end
|
||||
return UI.QuickSelect.eventHandler(self, event)
|
||||
return true
|
||||
end,
|
||||
},
|
||||
completions = UI.SlideOut {
|
||||
@@ -375,9 +456,10 @@ local page = UI.Page {
|
||||
event = 'slide_hide',
|
||||
},
|
||||
show = function(self, values)
|
||||
local m = Util.reduce(values, function(m, v)
|
||||
return #v.text > m and #v.text or m
|
||||
end, 12)
|
||||
local m = 12
|
||||
for _, v in pairs(values) do
|
||||
m = #v.text > m and #v.text or m
|
||||
end
|
||||
m = m + 3
|
||||
m = m > self.parent.width and self.parent.width or m
|
||||
self.ox = -m
|
||||
@@ -413,9 +495,7 @@ local page = UI.Page {
|
||||
scan = function(self)
|
||||
self.values = { }
|
||||
for k, v in pairs(device) do
|
||||
if type(v.side) == 'string' then
|
||||
_insert(self.values, { name = k, complete = 'peripheral.wrap("' .. v.side .. '")' })
|
||||
end
|
||||
table.insert(self.values, { name = k, complete = 'peripheral.wrap("' .. v.side .. '")' })
|
||||
end
|
||||
end,
|
||||
postInit = function(self)
|
||||
@@ -442,7 +522,7 @@ local page = UI.Page {
|
||||
for k, v in pairs(dev) do
|
||||
if type(v) == 'function' then
|
||||
local m = docs and docs[k] and docs[k]:match('^function%((.+)%).+')
|
||||
_insert(t, { method = k, complete = k .. '(' .. (m or '') .. ')' })
|
||||
table.insert(t, { method = k, complete = k .. '(' .. (m or '') .. ')' })
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -491,14 +571,10 @@ local page = UI.Page {
|
||||
UI.Window.resize(self)
|
||||
|
||||
w, h = self.width, self.height
|
||||
actions.set_cursor()
|
||||
actions.set_cursor(x, y)
|
||||
actions.dirty_all()
|
||||
actions.redraw()
|
||||
end,
|
||||
setCursorPos = function(self, cx, cy)
|
||||
self.cursorBlink = cy >= 1 and cy <= self.height
|
||||
UI.Window.setCursorPos(self, cx, cy)
|
||||
end,
|
||||
draw = function()
|
||||
actions.redraw()
|
||||
end,
|
||||
@@ -571,9 +647,9 @@ local function getFileInfo(path)
|
||||
config.recent = config.recent or { }
|
||||
|
||||
Array.removeByValue(config.recent, path)
|
||||
_insert(config.recent, 1, path)
|
||||
table.insert(config.recent, 1, path)
|
||||
while #config.recent > 10 do
|
||||
_remove(config.recent)
|
||||
table.remove(config.recent)
|
||||
end
|
||||
|
||||
Config.update('editor', config)
|
||||
@@ -639,7 +715,7 @@ local function redraw()
|
||||
if dirty.y > 0 then
|
||||
for dy = 1, h do
|
||||
local sLine = tLines[dy + scrollY]
|
||||
if sLine and #sLine > 0 then
|
||||
if sLine ~= nil then
|
||||
if dy + scrollY >= dirty.y and dy + scrollY <= dirty.ey then
|
||||
page.editor:clearLine(dy)
|
||||
writeHighlighted(sLine, dy + scrollY, dy)
|
||||
@@ -686,7 +762,7 @@ actions = {
|
||||
local last = _remove(undo.chain)
|
||||
if last then
|
||||
undo.active = true
|
||||
_insert(undo.redo, { })
|
||||
table.insert(undo.redo, { })
|
||||
for i = #last, 1, -1 do
|
||||
local u = last[i]
|
||||
actions[u.action](_unpack(u.args))
|
||||
@@ -700,14 +776,14 @@ actions = {
|
||||
undo_add = function(entry)
|
||||
if undo.active then
|
||||
local last = undo.redo[#undo.redo]
|
||||
_insert(last, entry)
|
||||
table.insert(last, entry)
|
||||
else
|
||||
if not undo.redo_active then
|
||||
undo.redo = { }
|
||||
end
|
||||
local last = undo.chain[#undo.chain]
|
||||
if last and undo.continue then
|
||||
_insert(last, entry)
|
||||
table.insert(last, entry)
|
||||
else
|
||||
_insert(undo.chain, { entry })
|
||||
end
|
||||
@@ -827,7 +903,7 @@ actions = {
|
||||
if not force and undo.chain[#undo.chain] ~= lastSave then
|
||||
page.unsaved:show('file_new')
|
||||
else
|
||||
actions.open('/untitled.lua')
|
||||
actions.open('/untitled.txt')
|
||||
end
|
||||
end,
|
||||
|
||||
@@ -901,7 +977,11 @@ actions = {
|
||||
if fs.isReadOnly(filename) then
|
||||
actions.error("access denied")
|
||||
else
|
||||
local s, m = pcall(Util.writeFile, filename, table.concat(tLines, '\n'))
|
||||
local s, m = pcall(function()
|
||||
if not Util.writeLines(filename, tLines) then
|
||||
error("Failed to open " .. filename)
|
||||
end
|
||||
end)
|
||||
|
||||
if s then
|
||||
lastSave = undo.chain[#undo.chain]
|
||||
@@ -932,40 +1012,29 @@ actions = {
|
||||
actions.error('open available with multishell')
|
||||
return
|
||||
end
|
||||
local routine = {
|
||||
focused = true,
|
||||
title = fs.getName(fileInfo.path),
|
||||
onExit = function(_, result)
|
||||
-- display results of process before closing window
|
||||
if result then -- clean exit
|
||||
-- any errors will be picked up by multishells
|
||||
-- error handling
|
||||
print('Press enter to exit')
|
||||
while true do
|
||||
local e, code = os.pullEventRaw('key')
|
||||
if e == 'terminate' or e == 'key' and code == keys.enter then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
}
|
||||
if undo.chain[#undo.chain] == lastSave then
|
||||
routine.path = 'sys/apps/shell.lua'
|
||||
routine.args = { fileInfo.path }
|
||||
local nTask = shell.openTab(fileInfo.path)
|
||||
if nTask then
|
||||
shell.switchTab(nTask)
|
||||
else
|
||||
actions.error("error starting Task")
|
||||
end
|
||||
else
|
||||
local fn, msg = load(_concat(tLines, '\n'), fileInfo.path)
|
||||
if not fn then
|
||||
if fn then
|
||||
multishell.openTab({
|
||||
fn = fn,
|
||||
focused = true,
|
||||
title = fs.getName(fileInfo.path),
|
||||
})
|
||||
else
|
||||
local ln = msg:match(':(%d+):')
|
||||
if ln and tonumber(ln) then
|
||||
actions.go_to(1, tonumber(ln))
|
||||
end
|
||||
actions.error(msg)
|
||||
return
|
||||
end
|
||||
routine.fn = fn
|
||||
end
|
||||
multishell.openTab(_ENV, routine)
|
||||
end,
|
||||
|
||||
status = function()
|
||||
@@ -1462,23 +1531,16 @@ actions = {
|
||||
end,
|
||||
}
|
||||
|
||||
local args, options = Util.parse( ... )
|
||||
local args = { ... }
|
||||
local filename = args[1] and shell.resolve(args[1])
|
||||
if not (actions.load(filename) or actions.load(config.filename) or actions.load('untitled.lua')) then
|
||||
if not (actions.load(filename) or actions.load(config.filename) or actions.load('untitled.txt')) then
|
||||
error('Error opening file')
|
||||
end
|
||||
|
||||
if tonumber(options.line) then
|
||||
scrollY = math.max(0, tonumber(options.line) - math.floor(h / 2))
|
||||
actions.go_to(1, tonumber(options.line))
|
||||
actions.set_cursor()
|
||||
actions.dirty_all()
|
||||
end
|
||||
|
||||
UI:setPage(page)
|
||||
local s, m = pcall(function() UI:start() end)
|
||||
if not s then
|
||||
actions.save('/crash.txt')
|
||||
print('Editor has crashed. File saved as /crash.txt')
|
||||
error(m, -1)
|
||||
error(m)
|
||||
end
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
category = "Apps",
|
||||
requires = "advancedComputer",
|
||||
iconExt = "\030 \031 \128\030d\159\030 \031d\140\030d\031 \155\030 \0315\140\0305\031 \155\030 \128\010\030 \031d\136\145\0315\136\145\031d\153\031 \128\0315\153\010\030 \031 \128\031d\130\140\134\0315\140\134\031 \128",
|
||||
run = "fileui --exec=hexedit.lua --title=hexedit",
|
||||
run = "fileui --exec=hexedit.lua",
|
||||
},
|
||||
[ "fb1c39e9f4f3c2628ad173ab401a6e4e4baf783d" ] = {
|
||||
title = "Sounds",
|
||||
@@ -78,9 +78,4 @@
|
||||
category = "Apps",
|
||||
run = "write",
|
||||
},
|
||||
[ "c543ece81605c7d202121c62080a0db4020fc2c75bfac35d101d7f3e93c93949" ] = {
|
||||
category = "Apps",
|
||||
run = "ascii",
|
||||
title = "Ascii",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
packages/common/ascii.lua urlfs https://pastebin.com/raw/U3KcNyJd
|
||||
packages/common/ascii.lua urlfs http://pastebin.com/raw/u3kcnyjd
|
||||
packages/common/hexedit.lua urlfs https://pastebin.com/raw/Ds9ajsp4
|
||||
packages/common/colors.lua urlfs https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/ignore/colors.lua
|
||||
packages/common/cowsay.lua urlfs https://pastebin.com/raw/n00VQJsw
|
||||
packages/common/calc.lua urlfs https://pastebin.com/raw/nAinUn1h
|
||||
packages/common/write.lua urlfs https://pastebin.com/raw/RSyhCjqv
|
||||
# pretty output
|
||||
rom/modules/main/inspect.lua urlfs https://raw.githubusercontent.com/kikito/inspect.lua/master/inspect.lua
|
||||
packages/common/write.lua urlfs https://pastebin.com/raw/RSyhCjqv
|
||||
@@ -1,3 +1,4 @@
|
||||
_G.requireInjector(_ENV)
|
||||
local config = require('opus.config').load('gps')
|
||||
if config.home then
|
||||
if turtle.enableGPS() then
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
local turtle = _G.turtle
|
||||
|
||||
turtle.run(function()
|
||||
_G.requireInjector(_ENV)
|
||||
|
||||
local GPS = require('opus.gps')
|
||||
|
||||
if not turtle.enableGPS() then
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
_G.requireInjector(_ENV)
|
||||
local Config = require('opus.config')
|
||||
local pt = turtle.enableGPS()
|
||||
if pt then
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
local function summon(id)
|
||||
|
||||
_G.requireInjector(_ENV)
|
||||
|
||||
local GPS = require('opus.gps')
|
||||
local Point = require('opus.point')
|
||||
local Socket = require('opus.socket')
|
||||
|
||||
@@ -89,7 +89,7 @@ local function hijackTurtle(remoteId)
|
||||
local socket, msg = Socket.connect(remoteId, 188)
|
||||
|
||||
if not socket then
|
||||
error(msg, 0)
|
||||
error(msg)
|
||||
end
|
||||
|
||||
socket:write('turtle')
|
||||
@@ -101,7 +101,7 @@ local function hijackTurtle(remoteId)
|
||||
socket:write({ method, ... })
|
||||
local resp = socket:read()
|
||||
if not resp then
|
||||
error('T/O: ' .. method, 0)
|
||||
error('timed out: ' .. method)
|
||||
end
|
||||
return table.unpack(resp)
|
||||
end
|
||||
@@ -308,7 +308,7 @@ local containerText = {
|
||||
}
|
||||
|
||||
local containTab = UI.Tab {
|
||||
title = 'Contain',
|
||||
tabTitle = 'Contain',
|
||||
button = UI.Button {
|
||||
x = 2, y = 2,
|
||||
text = 'Set corner',
|
||||
@@ -321,7 +321,7 @@ local containTab = UI.Tab {
|
||||
}
|
||||
|
||||
local blocksTab = UI.Tab {
|
||||
title = 'Blocks',
|
||||
tabTitle = 'Blocks',
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 1,
|
||||
columns = {
|
||||
@@ -333,7 +333,7 @@ local blocksTab = UI.Tab {
|
||||
}
|
||||
|
||||
local turtlesTab = UI.Tab {
|
||||
title = 'Turtles',
|
||||
tabTitle = 'Turtles',
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 1,
|
||||
values = pool,
|
||||
|
||||
@@ -23,7 +23,7 @@ local colours = _G.colors
|
||||
|
||||
local args, options = Util.parse(...)
|
||||
|
||||
local oldTerm, showInput, skipLast, lastDelay, curInput = Util.shallowCopy(_G.device.terminal), false, false, 2, ""
|
||||
local oldTerm, showInput, skipLast, lastDelay, curInput = Util.shallowCopy(multishell.term), false, false, 2, ""
|
||||
local curBlink, oldBlink, tTerm, buffer, colourNum, xPos, yPos, oldXPos, oldYPos, tCol, bCol, xSize, ySize = false, false, {}, {}, {}, 1, 1, 1, 1, colours.white, colours.black, oldTerm.getSize()
|
||||
local greys, buttons = {["0"] = true, ["7"] = true, ["8"] = true, ["f"] = true}, {"l", "r", "m"}
|
||||
local charW, charH, chars
|
||||
@@ -60,8 +60,8 @@ if options.help then
|
||||
end
|
||||
|
||||
if options.daemon then
|
||||
_G.device.keyboard.addHotkey('control-P', function()
|
||||
multishell.openTab(_ENV, {
|
||||
device.keyboard.addHotkey('control-P', function()
|
||||
multishell.openTab({
|
||||
path = 'sys/apps/shell.lua',
|
||||
args = { arg[0], '--noResize', '--rawOutput', 'recorder.gif' },
|
||||
})
|
||||
@@ -141,7 +141,7 @@ end
|
||||
|
||||
-- Build a terminal that records stuff:
|
||||
|
||||
local recTerm = _G.device.terminal
|
||||
local recTerm = multishell.term
|
||||
|
||||
for key, func in pairs(oldTerm) do
|
||||
if type(func) == 'function' then
|
||||
@@ -153,7 +153,7 @@ for key, func in pairs(oldTerm) do
|
||||
end
|
||||
callCount = callCount + 1
|
||||
curCalls[callCount] = { key, ... }
|
||||
return table.unpack(result)
|
||||
return unpack(result)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -196,7 +196,7 @@ end
|
||||
_G.device.keyboard.removeHotkey('control-p')
|
||||
|
||||
for k,fn in pairs(oldTerm) do
|
||||
_G.device.terminal[k] = fn
|
||||
multishell.term[k] = fn
|
||||
end
|
||||
|
||||
multishell.unhideTab(tabId)
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
title = 'Compress',
|
||||
repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/compress',
|
||||
description = [[untar / gunzip]],
|
||||
license = 'MIT',
|
||||
}
|
||||
@@ -1,530 +0,0 @@
|
||||
--[[
|
||||
see: https://github.com/davidm/lua-compress-deflatelua/
|
||||
for licensing / details
|
||||
--]]
|
||||
|
||||
local M = {_TYPE='module', _NAME='compress.deflatelua', _VERSION='0.3.20111128'}
|
||||
|
||||
local assert = assert
|
||||
local error = error
|
||||
local ipairs = ipairs
|
||||
local pairs = pairs
|
||||
local tostring = tostring
|
||||
local type = type
|
||||
local setmetatable = setmetatable
|
||||
local io = io
|
||||
local math = math
|
||||
local table_sort = table.sort
|
||||
local math_max = math.max
|
||||
local string_char = string.char
|
||||
local band = bit32.band
|
||||
local lshift = bit32.lshift
|
||||
local rshift = bit32.rshift
|
||||
|
||||
local function runtime_error(s, level)
|
||||
level = level or 1
|
||||
error(s, level+1)
|
||||
end
|
||||
|
||||
|
||||
local function make_outstate(outbs)
|
||||
local outstate = {}
|
||||
outstate.outbs = outbs
|
||||
outstate.window = {}
|
||||
outstate.window_pos = 1
|
||||
return outstate
|
||||
end
|
||||
|
||||
|
||||
local function output(outstate, byte)
|
||||
local window_pos = outstate.window_pos
|
||||
outstate.outbs(byte)
|
||||
outstate.window[window_pos] = byte
|
||||
outstate.window_pos = window_pos % 32768 + 1 -- 32K
|
||||
end
|
||||
|
||||
|
||||
local function noeof(val)
|
||||
return assert(val, 'unexpected end of file')
|
||||
end
|
||||
|
||||
|
||||
local function hasbit(bits, bit)
|
||||
return bits % (bit + bit) >= bit
|
||||
end
|
||||
|
||||
|
||||
local function memoize(f)
|
||||
local mt = {}
|
||||
local t = setmetatable({}, mt)
|
||||
function mt:__index(k)
|
||||
local v = f(k)
|
||||
t[k] = v
|
||||
return v
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
|
||||
-- small optimization (lookup table for powers of 2)
|
||||
local pow2 = memoize(function(n) return 2^n end)
|
||||
|
||||
--local tbits = memoize(
|
||||
-- function(bits)
|
||||
-- return memoize( function(bit) return getbit(bits, bit) end )
|
||||
-- end )
|
||||
|
||||
|
||||
-- weak metatable marking objects as bitstream type
|
||||
local is_bitstream = setmetatable({}, {__mode='k'})
|
||||
|
||||
local function bytestream_from_file(fh)
|
||||
local o = {}
|
||||
function o.read()
|
||||
local sb = fh:read(1)
|
||||
if sb then return sb:byte() end
|
||||
end
|
||||
return o
|
||||
end
|
||||
|
||||
|
||||
local function bytestream_from_string(s)
|
||||
local i = 1
|
||||
local o = {}
|
||||
function o.read()
|
||||
local by
|
||||
if i <= #s then
|
||||
by = s:byte(i)
|
||||
i = i + 1
|
||||
end
|
||||
return by
|
||||
end
|
||||
return o
|
||||
end
|
||||
|
||||
|
||||
local function bytestream_from_function(f)
|
||||
local o = {}
|
||||
function o.read()
|
||||
return f()
|
||||
end
|
||||
return o
|
||||
end
|
||||
|
||||
|
||||
local function bitstream_from_bytestream(bys)
|
||||
local buf_byte = 0
|
||||
local buf_nbit = 0
|
||||
local o = {}
|
||||
|
||||
function o.nbits_left_in_byte()
|
||||
return buf_nbit
|
||||
end
|
||||
|
||||
function o:read(nbits)
|
||||
nbits = nbits or 1
|
||||
while buf_nbit < nbits do
|
||||
local byte = bys:read()
|
||||
if not byte then return end -- note: more calls also return nil
|
||||
buf_byte = buf_byte + lshift(byte, buf_nbit)
|
||||
buf_nbit = buf_nbit + 8
|
||||
end
|
||||
local bits
|
||||
if nbits == 0 then
|
||||
bits = 0
|
||||
elseif nbits == 32 then
|
||||
bits = buf_byte
|
||||
buf_byte = 0
|
||||
else
|
||||
bits = band(buf_byte, rshift(0xffffffff, 32 - nbits))
|
||||
buf_byte = rshift(buf_byte, nbits)
|
||||
end
|
||||
buf_nbit = buf_nbit - nbits
|
||||
return bits
|
||||
end
|
||||
|
||||
|
||||
is_bitstream[o] = true
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
|
||||
local function get_bitstream(o)
|
||||
local bs
|
||||
if is_bitstream[o] then
|
||||
return o
|
||||
elseif io.type(o) == 'file' then
|
||||
bs = bitstream_from_bytestream(bytestream_from_file(o))
|
||||
elseif type(o) == 'string' then
|
||||
bs = bitstream_from_bytestream(bytestream_from_string(o))
|
||||
elseif type(o) == 'function' then
|
||||
bs = bitstream_from_bytestream(bytestream_from_function(o))
|
||||
else
|
||||
runtime_error 'unrecognized type'
|
||||
end
|
||||
return bs
|
||||
end
|
||||
|
||||
|
||||
local function get_obytestream(o)
|
||||
local bs
|
||||
if io.type(o) == 'file' then
|
||||
bs = function(sbyte) o:write(string_char(sbyte)) end
|
||||
elseif type(o) == 'function' then
|
||||
bs = o
|
||||
else
|
||||
runtime_error('unrecognized type: ' .. tostring(o))
|
||||
end
|
||||
return bs
|
||||
end
|
||||
|
||||
|
||||
local function HuffmanTable(init, is_full)
|
||||
local t = {}
|
||||
if is_full then
|
||||
for val,nbits in pairs(init) do
|
||||
if nbits ~= 0 then
|
||||
t[#t+1] = {val=val, nbits=nbits}
|
||||
end
|
||||
end
|
||||
else
|
||||
for i=1,#init-2,2 do
|
||||
local firstval, nbits, nextval = init[i], init[i+1], init[i+2]
|
||||
if nbits ~= 0 then
|
||||
for val=firstval,nextval-1 do
|
||||
t[#t+1] = {val=val, nbits=nbits}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
table_sort(t, function(a,b)
|
||||
return a.nbits == b.nbits and a.val < b.val or a.nbits < b.nbits
|
||||
end)
|
||||
|
||||
-- assign codes
|
||||
local code = 1 -- leading 1 marker
|
||||
local nbits = 0
|
||||
for _,s in ipairs(t) do
|
||||
if s.nbits ~= nbits then
|
||||
code = code * pow2[s.nbits - nbits]
|
||||
nbits = s.nbits
|
||||
end
|
||||
s.code = code
|
||||
code = code + 1
|
||||
end
|
||||
|
||||
local minbits = math.huge
|
||||
local look = {}
|
||||
for _,s in ipairs(t) do
|
||||
minbits = math.min(minbits, s.nbits)
|
||||
look[s.code] = s.val
|
||||
end
|
||||
|
||||
local msb = function(bits, nbits)
|
||||
local res = 0
|
||||
for _=1,nbits do
|
||||
res = lshift(res, 1) + band(bits, 1)
|
||||
bits = rshift(bits, 1)
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
local tfirstcode = memoize(
|
||||
function(bits) return pow2[minbits] + msb(bits, minbits) end)
|
||||
|
||||
function t:read(bs)
|
||||
local code = 1 -- leading 1 marker
|
||||
local nbits = 0
|
||||
while 1 do
|
||||
if nbits == 0 then -- small optimization (optional)
|
||||
code = tfirstcode[noeof(bs:read(minbits))]
|
||||
nbits = nbits + minbits
|
||||
else
|
||||
local b = noeof(bs:read())
|
||||
nbits = nbits + 1
|
||||
code = code * 2 + b -- MSB first
|
||||
end
|
||||
local val = look[code]
|
||||
if val then
|
||||
return val
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
|
||||
local function parse_gzip_header(bs)
|
||||
-- local FLG_FTEXT = 2^0
|
||||
local FLG_FHCRC = 2^1
|
||||
local FLG_FEXTRA = 2^2
|
||||
local FLG_FNAME = 2^3
|
||||
local FLG_FCOMMENT = 2^4
|
||||
|
||||
local id1 = bs:read(8)
|
||||
local id2 = bs:read(8)
|
||||
if id1 ~= 31 or id2 ~= 139 then
|
||||
runtime_error 'not in gzip format'
|
||||
end
|
||||
bs:read(8) -- compression method
|
||||
local flg = bs:read(8) -- FLaGs
|
||||
local mtime = bs:read(32) -- Modification TIME
|
||||
local xfl = bs:read(8) -- eXtra FLags
|
||||
local os = bs:read(8) -- Operating System
|
||||
|
||||
if not os then runtime_error 'invalid header' end
|
||||
|
||||
if hasbit(flg, FLG_FEXTRA) then
|
||||
local xlen = bs:read(16)
|
||||
local extra = 0
|
||||
for i=1,xlen do
|
||||
extra = bs:read(8)
|
||||
end
|
||||
if not extra then runtime_error 'invalid header' end
|
||||
end
|
||||
|
||||
local function parse_zstring(bs)
|
||||
repeat
|
||||
local by = bs:read(8)
|
||||
if not by then runtime_error 'invalid header' end
|
||||
until by == 0
|
||||
end
|
||||
|
||||
if hasbit(flg, FLG_FNAME) then
|
||||
parse_zstring(bs)
|
||||
end
|
||||
|
||||
if hasbit(flg, FLG_FCOMMENT) then
|
||||
parse_zstring(bs)
|
||||
end
|
||||
|
||||
if hasbit(flg, FLG_FHCRC) then
|
||||
local crc16 = bs:read(16)
|
||||
if not crc16 then runtime_error 'invalid header' end
|
||||
-- IMPROVE: check CRC. where is an example .gz file that
|
||||
-- has this set?
|
||||
end
|
||||
end
|
||||
|
||||
local function parse_zlib_header(bs)
|
||||
local cm = bs:read(4) -- Compression Method
|
||||
local cinfo = bs:read(4) -- Compression info
|
||||
local fcheck = bs:read(5) -- FLaGs: FCHECK (check bits for CMF and FLG)
|
||||
local fdict = bs:read(1) -- FLaGs: FDICT (present dictionary)
|
||||
local flevel = bs:read(2) -- FLaGs: FLEVEL (compression level)
|
||||
local cmf = cinfo * 16 + cm -- CMF (Compresion Method and flags)
|
||||
local flg = fcheck + fdict * 32 + flevel * 64 -- FLaGs
|
||||
|
||||
if cm ~= 8 then -- not "deflate"
|
||||
runtime_error("unrecognized zlib compression method: " + cm)
|
||||
end
|
||||
if cinfo > 7 then
|
||||
runtime_error("invalid zlib window size: cinfo=" + cinfo)
|
||||
end
|
||||
local window_size = 2^(cinfo + 8)
|
||||
|
||||
if (cmf*256 + flg) % 31 ~= 0 then
|
||||
runtime_error("invalid zlib header (bad fcheck sum)")
|
||||
end
|
||||
|
||||
if fdict == 1 then
|
||||
runtime_error("FIX:TODO - FDICT not currently implemented")
|
||||
local dictid_ = bs:read(32)
|
||||
end
|
||||
|
||||
return window_size
|
||||
end
|
||||
|
||||
local function parse_huffmantables(bs)
|
||||
local hlit = bs:read(5) -- # of literal/length codes - 257
|
||||
local hdist = bs:read(5) -- # of distance codes - 1
|
||||
local hclen = noeof(bs:read(4)) -- # of code length codes - 4
|
||||
|
||||
local ncodelen_codes = hclen + 4
|
||||
local codelen_init = {}
|
||||
local codelen_vals = {
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}
|
||||
for i=1,ncodelen_codes do
|
||||
local nbits = bs:read(3)
|
||||
local val = codelen_vals[i]
|
||||
codelen_init[val] = nbits
|
||||
end
|
||||
local codelentable = HuffmanTable(codelen_init, true)
|
||||
|
||||
local function decode(ncodes)
|
||||
local init = {}
|
||||
local nbits
|
||||
local val = 0
|
||||
while val < ncodes do
|
||||
local codelen = codelentable:read(bs)
|
||||
--FIX:check nil?
|
||||
local nrepeat
|
||||
if codelen <= 15 then
|
||||
nrepeat = 1
|
||||
nbits = codelen
|
||||
elseif codelen == 16 then
|
||||
nrepeat = 3 + noeof(bs:read(2))
|
||||
-- nbits unchanged
|
||||
elseif codelen == 17 then
|
||||
nrepeat = 3 + noeof(bs:read(3))
|
||||
nbits = 0
|
||||
elseif codelen == 18 then
|
||||
nrepeat = 11 + noeof(bs:read(7))
|
||||
nbits = 0
|
||||
else
|
||||
error 'ASSERT'
|
||||
end
|
||||
for i=1,nrepeat do
|
||||
init[val] = nbits
|
||||
val = val + 1
|
||||
end
|
||||
end
|
||||
local huffmantable = HuffmanTable(init, true)
|
||||
return huffmantable
|
||||
end
|
||||
|
||||
local nlit_codes = hlit + 257
|
||||
local ndist_codes = hdist + 1
|
||||
|
||||
local littable = decode(nlit_codes)
|
||||
local disttable = decode(ndist_codes)
|
||||
|
||||
return littable, disttable
|
||||
end
|
||||
|
||||
|
||||
local tdecode_len_base
|
||||
local tdecode_len_nextrabits
|
||||
local tdecode_dist_base
|
||||
local tdecode_dist_nextrabits
|
||||
local function parse_compressed_item(bs, outstate, littable, disttable)
|
||||
local val = littable:read(bs)
|
||||
if val < 256 then -- literal
|
||||
output(outstate, val)
|
||||
elseif val == 256 then -- end of block
|
||||
return true
|
||||
else
|
||||
if not tdecode_len_base then
|
||||
local t = {[257]=3}
|
||||
local skip = 1
|
||||
for i=258,285,4 do
|
||||
for j=i,i+3 do t[j] = t[j-1] + skip end
|
||||
if i ~= 258 then skip = skip * 2 end
|
||||
end
|
||||
t[285] = 258
|
||||
tdecode_len_base = t
|
||||
end
|
||||
if not tdecode_len_nextrabits then
|
||||
local t = {}
|
||||
|
||||
for i=257,285 do
|
||||
local j = math_max(i - 261, 0)
|
||||
t[i] = rshift(j, 2)
|
||||
end
|
||||
|
||||
t[285] = 0
|
||||
tdecode_len_nextrabits = t
|
||||
end
|
||||
local len_base = tdecode_len_base[val]
|
||||
local nextrabits = tdecode_len_nextrabits[val]
|
||||
local extrabits = bs:read(nextrabits)
|
||||
local len = len_base + extrabits
|
||||
|
||||
if not tdecode_dist_base then
|
||||
local t = {[0]=1}
|
||||
local skip = 1
|
||||
for i=1,29,2 do
|
||||
for j=i,i+1 do t[j] = t[j-1] + skip end
|
||||
if i ~= 1 then skip = skip * 2 end
|
||||
end
|
||||
tdecode_dist_base = t
|
||||
end
|
||||
if not tdecode_dist_nextrabits then
|
||||
local t = {}
|
||||
|
||||
for i=0,29 do
|
||||
local j = math_max(i - 2, 0)
|
||||
t[i] = rshift(j, 1)
|
||||
end
|
||||
|
||||
tdecode_dist_nextrabits = t
|
||||
end
|
||||
local dist_val = disttable:read(bs)
|
||||
local dist_base = tdecode_dist_base[dist_val]
|
||||
local dist_nextrabits = tdecode_dist_nextrabits[dist_val]
|
||||
local dist_extrabits = bs:read(dist_nextrabits)
|
||||
local dist = dist_base + dist_extrabits
|
||||
|
||||
for i=1,len do
|
||||
local pos = (outstate.window_pos - 1 - dist) % 32768 + 1 -- 32K
|
||||
output(outstate, assert(outstate.window[pos], 'invalid distance'))
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
local function parse_block(bs, outstate, throttle)
|
||||
local bfinal = bs:read(1)
|
||||
local btype = bs:read(2)
|
||||
|
||||
local BTYPE_NO_COMPRESSION = 0
|
||||
local BTYPE_FIXED_HUFFMAN = 1
|
||||
local BTYPE_DYNAMIC_HUFFMAN = 2
|
||||
local BTYPE_RESERVED_ = 3
|
||||
|
||||
if btype == BTYPE_NO_COMPRESSION then
|
||||
bs:read(bs:nbits_left_in_byte())
|
||||
local len = bs:read(16)
|
||||
local nlen_ = noeof(bs:read(16))
|
||||
|
||||
for _=1,len do
|
||||
local by = noeof(bs:read(8))
|
||||
output(outstate, by)
|
||||
end
|
||||
elseif btype == BTYPE_FIXED_HUFFMAN or btype == BTYPE_DYNAMIC_HUFFMAN then
|
||||
local littable, disttable
|
||||
if btype == BTYPE_DYNAMIC_HUFFMAN then
|
||||
littable, disttable = parse_huffmantables(bs)
|
||||
else
|
||||
littable = HuffmanTable {0,8, 144,9, 256,7, 280,8, 288,nil}
|
||||
disttable = HuffmanTable {0,5, 32,nil}
|
||||
end
|
||||
|
||||
repeat
|
||||
local is_done = parse_compressed_item(
|
||||
bs, outstate, littable, disttable)
|
||||
throttle()
|
||||
until is_done
|
||||
else
|
||||
runtime_error 'unrecognized compression type'
|
||||
end
|
||||
|
||||
return bfinal ~= 0
|
||||
end
|
||||
|
||||
function M.inflate(t)
|
||||
local bs = get_bitstream(t.input)
|
||||
local outbs = get_obytestream(t.output)
|
||||
local outstate = make_outstate(outbs)
|
||||
|
||||
repeat
|
||||
local is_final = parse_block(bs, outstate, t.throttle)
|
||||
until is_final
|
||||
end
|
||||
local inflate = M.inflate
|
||||
|
||||
function M.gunzip(t)
|
||||
local bs = get_bitstream(t.input)
|
||||
local outbs = get_obytestream(t.output)
|
||||
|
||||
parse_gzip_header(bs)
|
||||
|
||||
inflate{input=bs, output=outbs, throttle=t.throttle or function() end}
|
||||
|
||||
bs:read(bs:nbits_left_in_byte())
|
||||
end
|
||||
|
||||
return M
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,29 +0,0 @@
|
||||
local LZW = require('opus.compress.lzw')
|
||||
local Tar = require('opus.compress.tar')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local shell = _ENV.shell
|
||||
|
||||
local args = { ... }
|
||||
|
||||
if not args[2] then
|
||||
error('Syntax: tar OUTFILE DIR')
|
||||
end
|
||||
|
||||
local file = shell.resolve(args[1])
|
||||
local dir = shell.resolve(args[2])
|
||||
|
||||
local filetype = 'tar'
|
||||
if file:match('(.+)%.tar$') then
|
||||
filetype = 'tar'
|
||||
elseif file:match('(.+)%.lzw$') then
|
||||
filetype = 'lzw'
|
||||
end
|
||||
|
||||
if filetype == 'tar' then
|
||||
Tar.tar(file, dir)
|
||||
|
||||
elseif filetype == 'lzw' then
|
||||
local c = Tar.tar_string(dir)
|
||||
Util.writeFile(file, LZW.compress(c), 'wb')
|
||||
end
|
||||
@@ -1,54 +0,0 @@
|
||||
local DEFLATE = require('compress.deflatelua')
|
||||
local LZW = require('opus.compress.lzw')
|
||||
local Tar = require('opus.compress.tar')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local io = _G.io
|
||||
local shell = _ENV.shell
|
||||
|
||||
local args = { ... }
|
||||
|
||||
if not args[2] then
|
||||
error('Syntax: tar FILE DESTDIR')
|
||||
end
|
||||
|
||||
local inFile = shell.resolve(args[1])
|
||||
local outDir = shell.resolve(args[2])
|
||||
|
||||
if inFile:match('(.+)%.[gG][zZ]$') then
|
||||
-- uncompress a file created with: tar czf ...
|
||||
local fh = io.open(inFile, 'rb') or error('Error opening ' .. inFile)
|
||||
|
||||
local t = { }
|
||||
local function writer(b)
|
||||
table.insert(t, b)
|
||||
end
|
||||
|
||||
DEFLATE.gunzip {input=fh, output=writer, disable_crc=true}
|
||||
|
||||
fh:close()
|
||||
|
||||
local s, m = Tar.untar_string(string.char(table.unpack(t)), outDir, true)
|
||||
|
||||
if not s then
|
||||
error(m)
|
||||
end
|
||||
|
||||
elseif inFile:match('(.+)%.tar%.lzw$') then
|
||||
local c = Util.readFile(inFile, 'rb')
|
||||
if not c then
|
||||
error('Unable to open ' .. inFile)
|
||||
end
|
||||
|
||||
local s, m = Tar.untar_string(LZW.decompress(c), outDir, true)
|
||||
|
||||
if not s then
|
||||
error(m)
|
||||
end
|
||||
|
||||
else
|
||||
local s, m = Tar.untar(inFile, outDir, true)
|
||||
if not s then
|
||||
error(m)
|
||||
end
|
||||
end
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
title = 'Lua Debugger',
|
||||
repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/debugger',
|
||||
description = [[Lua interactive debugger]],
|
||||
license = 'MIT',
|
||||
}
|
||||
@@ -1,229 +0,0 @@
|
||||
-- this code is loaded into the code being debugged
|
||||
-- some portions from https://github.com/slembcke/debugger.lua
|
||||
|
||||
local fs = _G.fs
|
||||
|
||||
local dbg = {
|
||||
hooks = { },
|
||||
waits = { },
|
||||
breakpoints = nil,
|
||||
}
|
||||
|
||||
local function breakpointHook(depth, lineNo)
|
||||
if dbg.breakpoints then
|
||||
local info
|
||||
for _,v in ipairs(dbg.breakpoints) do
|
||||
if v.line == lineNo then
|
||||
if not info then
|
||||
info = debug.getinfo(depth)
|
||||
end
|
||||
if (v.file == info.short_src or v.bfile == info.short_src) then
|
||||
return not v.disabled
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function functionHook(fn)
|
||||
return function()
|
||||
return debug.getinfo(3).func == fn
|
||||
end
|
||||
end
|
||||
|
||||
local function stepHook()
|
||||
return function()
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function stackSizeHook(n)
|
||||
local i = 2
|
||||
while true do
|
||||
local info = debug.getinfo(i)
|
||||
if not info then
|
||||
break
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
return function(depth, lineNo)
|
||||
return not debug.getinfo(i - n)
|
||||
or breakpointHook(depth + 1, lineNo)
|
||||
end
|
||||
end
|
||||
|
||||
local function stepOutHook()
|
||||
return stackSizeHook(1)
|
||||
end
|
||||
|
||||
local function stepOverHook()
|
||||
return stackSizeHook(0)
|
||||
end
|
||||
|
||||
-- Create a table of all the locally accessible variables.
|
||||
local function local_bindings(offset, stack_inspect_offset)
|
||||
offset = offset + 1 + stack_inspect_offset -- add this function to the offset
|
||||
local func = debug.getinfo(offset).func
|
||||
local bindings = { }
|
||||
|
||||
-- Retrieve the upvalues
|
||||
do local i = 1; while true do
|
||||
local name, value = debug.getupvalue(func, i)
|
||||
if not name then break end
|
||||
bindings[name] = { type = 'U', raw = value }
|
||||
i = i + 1
|
||||
end end
|
||||
|
||||
-- Retrieve the locals (overwriting any upvalues)
|
||||
do local i = 1; while true do
|
||||
local name, value = debug.getlocal(offset, i)
|
||||
if not name then break end
|
||||
bindings[name] = { type = 'L', raw = value }
|
||||
i = i + 1
|
||||
end end
|
||||
|
||||
-- Retrieve the varargs (works in Lua 5.2 and LuaJIT)
|
||||
local varargs = { }
|
||||
do local i = 1; while true do
|
||||
local name, value = debug.getlocal(offset, -i)
|
||||
if not name then break end
|
||||
varargs[i] = value
|
||||
i = i + 1
|
||||
end end
|
||||
if #varargs > 0 then
|
||||
bindings["..."] = { type = 'V', value = varargs }
|
||||
end
|
||||
|
||||
local t = { }
|
||||
for k,v in pairs(bindings) do
|
||||
if k ~= '(*temporary)' then
|
||||
v.name = k
|
||||
v.value = tostring(v.raw)
|
||||
--if type(v.raw) == 'table' and not next(v.raw) then
|
||||
-- v.value = 'table: (empty)'
|
||||
--end
|
||||
table.insert(t, v)
|
||||
end
|
||||
end
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
local function get_trace(offset, stack_inspect_offset)
|
||||
local function format_loc(file, line) return file..":"..line end
|
||||
local function format_stack_frame_info(info)
|
||||
local filename = info.source:match("@(.*)")
|
||||
local source = filename and fs.getName(filename) or info.short_src
|
||||
local namewhat = (info.namewhat == "" and "chunk at" or info.namewhat)
|
||||
local name = (info.name and "'"..info.name.."'" or format_loc(source, info.linedefined))
|
||||
return format_loc(source, info.currentline).." in "..namewhat.." "..name
|
||||
end
|
||||
|
||||
offset = offset + 1 -- add this function to the offset
|
||||
local t = { }
|
||||
local i = 0
|
||||
while true do
|
||||
local info = debug.getinfo(offset + i)
|
||||
if not info then break end
|
||||
t[i] = {
|
||||
index = i,
|
||||
current = (i == stack_inspect_offset),
|
||||
desc = format_stack_frame_info(info),
|
||||
info = info,
|
||||
}
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
local function hook(_, lineNo)
|
||||
local h = dbg.hooks[coroutine.running()]
|
||||
|
||||
if h and h.eval(3, lineNo) then
|
||||
local inspectOffset = 0
|
||||
|
||||
repeat
|
||||
local done = true
|
||||
|
||||
local snapshot = {
|
||||
info = debug.getinfo(2 + inspectOffset),
|
||||
locals = local_bindings(2, inspectOffset),
|
||||
stack = get_trace(2, inspectOffset),
|
||||
}
|
||||
inspectOffset = 0 -- reset
|
||||
|
||||
table.insert(dbg.waits, h)
|
||||
while dbg.waits[1] ~= h do
|
||||
os.sleep(.1)
|
||||
end
|
||||
local cmd, param = dbg.read(snapshot)
|
||||
|
||||
table.remove(dbg.waits, 1)
|
||||
|
||||
if cmd == 's' then
|
||||
h.eval = stepHook()
|
||||
elseif cmd == 'n' then
|
||||
h.eval = stepOverHook()
|
||||
elseif cmd == 'f' then
|
||||
h.eval = stepOutHook()
|
||||
elseif cmd == 'c' then
|
||||
h.eval = breakpointHook
|
||||
elseif cmd == 'i' then
|
||||
-- get snapshot of stack at this offset
|
||||
inspectOffset = param
|
||||
done = false
|
||||
else
|
||||
done = false
|
||||
end
|
||||
until done
|
||||
end
|
||||
end
|
||||
|
||||
function dbg.call(fn, ...)
|
||||
local args = { ... }
|
||||
return xpcall(
|
||||
function()
|
||||
return fn(table.unpack(args))
|
||||
end,
|
||||
function(err)
|
||||
dbg.hooks[coroutine.running()].eval = stepHook()
|
||||
|
||||
-- An error has occurred
|
||||
return err
|
||||
end)
|
||||
end
|
||||
|
||||
dbg.stopIn = function(fn)
|
||||
dbg.hooks[coroutine.running()].eval = functionHook(fn)
|
||||
end
|
||||
|
||||
_ENV.coroutine = setmetatable({
|
||||
create = function(fn)
|
||||
local co = _G.coroutine.create(function(...)
|
||||
local r = { dbg.call(fn, ...) }
|
||||
|
||||
dbg.hooks[coroutine.running()] = nil
|
||||
if not r[1] then
|
||||
error(r[2], -1)
|
||||
end
|
||||
|
||||
return table.unpack(r, 2)
|
||||
end)
|
||||
|
||||
dbg.hooks[co] = {
|
||||
co = co,
|
||||
eval = breakpointHook,
|
||||
}
|
||||
debug.sethook(co, hook, 'l')
|
||||
return co
|
||||
end
|
||||
}, { __index = coroutine })
|
||||
|
||||
dbg.hooks[coroutine.running()] = {
|
||||
co = coroutine.running(),
|
||||
eval = function() return false end,
|
||||
}
|
||||
|
||||
debug.sethook(hook, 'l')
|
||||
return dbg
|
||||
@@ -1,4 +0,0 @@
|
||||
local completion = require('cc.shell.completion')
|
||||
|
||||
_ENV.shell.setCompletionFunction("packages/debugger/debug.lua",
|
||||
completion.build(completion.program))
|
||||
@@ -1,590 +0,0 @@
|
||||
local class = require('opus.class')
|
||||
local Config = require('opus.config')
|
||||
local Event = require('opus.event')
|
||||
local UI = require('opus.ui')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local fs = _G.fs
|
||||
local getfenv = _G.getfenv
|
||||
local kernel = _G.kernel
|
||||
local multishell = _ENV.multishell
|
||||
local shell = _ENV.shell
|
||||
|
||||
local args = { ... }
|
||||
local filename = shell.resolveProgram(table.remove(args, 1))
|
||||
|
||||
if not filename then
|
||||
error('file not found')
|
||||
end
|
||||
|
||||
UI:disableEffects()
|
||||
|
||||
local config = Config.load('debugger')
|
||||
if not config[filename] then
|
||||
config[filename] = { }
|
||||
end
|
||||
|
||||
local breakpoints = config[filename]
|
||||
local currentFile
|
||||
local debugFile, debugLine
|
||||
|
||||
local debugger = kernel.getCurrent()
|
||||
local client
|
||||
|
||||
local function startClient()
|
||||
local env = kernel.makeEnv(_ENV, fs.getDir(filename))
|
||||
currentFile = nil
|
||||
|
||||
local clientId = multishell.openTab(nil, {
|
||||
env = env,
|
||||
title = fs.getName(filename):match('([^%.]+)'),
|
||||
args = args,
|
||||
fn = function()
|
||||
local dbg = require('debugger')
|
||||
local fn, msg = loadfile(filename, env)
|
||||
|
||||
if not fn then
|
||||
error(msg, -1)
|
||||
end
|
||||
|
||||
dbg.read = function(snapshot)
|
||||
os.sleep(0) -- not sure why, but we need a sleep before :resume
|
||||
-- directly resuming debugger routine to prevent
|
||||
-- serialization of the snapshot
|
||||
dbg.debugger:resume('debuggerX', 'break', snapshot)
|
||||
local e, cmd, param
|
||||
repeat
|
||||
e, cmd, param = os.pullEvent('debugger')
|
||||
until e == 'debugger'
|
||||
return cmd, param
|
||||
end
|
||||
|
||||
_ENV.arg = { table.unpack(args) }
|
||||
_ENV.arg[0] = filename
|
||||
-- breakpoint table is shared across processes
|
||||
dbg.breakpoints = breakpoints
|
||||
dbg.debugger = debugger
|
||||
dbg.stopIn(fn)
|
||||
local s, m = dbg.call(fn, table.unpack(args))
|
||||
|
||||
dbg.debugger:resume('debuggerX', 'disconnect')
|
||||
|
||||
if not s then
|
||||
error(m, -1)
|
||||
end
|
||||
print('Process ended normally')
|
||||
print('Press enter to exit')
|
||||
while true do
|
||||
local e, code = os.pullEventRaw('key')
|
||||
if e == 'terminate' or e == 'key' and code == _G.keys.enter then
|
||||
break
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
client = kernel.find(clientId)
|
||||
end
|
||||
|
||||
local romFiles = {
|
||||
files = { },
|
||||
load = function(self)
|
||||
local function recurse(dir)
|
||||
local files = fs.list(dir)
|
||||
for _,f in ipairs(files) do
|
||||
local fullName = fs.combine(dir, f)
|
||||
if fs.isDir(fullName) then
|
||||
recurse(fullName)
|
||||
else
|
||||
self.files[f] = fullName
|
||||
end
|
||||
end
|
||||
end
|
||||
recurse('rom/apis')
|
||||
self.reversed = Util.transpose(self.files)
|
||||
end,
|
||||
get = function(self, file)
|
||||
return self.files[file]
|
||||
end,
|
||||
lookup = function(self, file)
|
||||
return self.reversed[file]
|
||||
end,
|
||||
}
|
||||
romFiles:load()
|
||||
|
||||
local function loadSource(file)
|
||||
currentFile = romFiles:get(file) or file:match('@?(.*)')
|
||||
local src = { }
|
||||
local lines = Util.readLines(currentFile) or type(file) == 'string' and Util.split(file)
|
||||
|
||||
if lines then
|
||||
for i = 1, #lines do
|
||||
table.insert(src, { line = i, source = lines[i] })
|
||||
end
|
||||
end
|
||||
|
||||
return src
|
||||
end
|
||||
|
||||
local function message(...)
|
||||
client:resume('debugger', ...)
|
||||
end
|
||||
|
||||
UI.InverseButton = class(UI.Button)
|
||||
UI.InverseButton.defaults = {
|
||||
UIElement = 'InverseButton',
|
||||
backgroundColor = 'primary',
|
||||
backgroundFocusColor = 'gray',
|
||||
textFocusColor = 'primary',
|
||||
textColor = 'gray',
|
||||
}
|
||||
|
||||
local page = UI.Page {
|
||||
backgroundColor = 'gray',
|
||||
|
||||
container = UI.Window {
|
||||
y = 1, ey = '50%',
|
||||
tabs = UI.Tabs {
|
||||
ey = -2,
|
||||
barBackgroundColor = 'tertiary',
|
||||
locals = UI.Tab {
|
||||
title = 'Locals',
|
||||
index = 1,
|
||||
grid = UI.ScrollingGrid {
|
||||
disableHeader = true,
|
||||
unfocusedBackgroundSelectedColor = 'black',
|
||||
columns = {
|
||||
{ heading = 'localname', key = 'name' },
|
||||
{ heading = 'Value', key = 'value', textColor = 'yellow' },
|
||||
},
|
||||
autospace = true,
|
||||
accelerators = {
|
||||
grid_select = 'show_variable',
|
||||
},
|
||||
getRowTextColor = function(self, row, selected)
|
||||
return row.type == 'U' and 'cyan'
|
||||
or row.type == 'V' and 'lime'
|
||||
or UI.Grid.getRowTextColor(self, row, selected)
|
||||
end,
|
||||
},
|
||||
},
|
||||
|
||||
stack = UI.Tab {
|
||||
title = 'Stack',
|
||||
index = 3,
|
||||
grid = UI.ScrollingGrid {
|
||||
disableHeader = true,
|
||||
sortColumn = 'index',
|
||||
unfocusedBackgroundSelectedColor = 'black',
|
||||
columns = {
|
||||
{ key = 'index', width = 2 },
|
||||
{ heading = 'heading', key = 'desc' },
|
||||
},
|
||||
getRowTextColor = function(self, row, selected)
|
||||
return row.current and 'yellow'
|
||||
or UI.Grid.getRowTextColor(self, row, selected)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
message('i', event.selected.index)
|
||||
else
|
||||
return UI.Grid.eventHandler(self, event)
|
||||
end
|
||||
end,
|
||||
},
|
||||
},
|
||||
|
||||
env = UI.Tab {
|
||||
title = 'Env',
|
||||
index = 4,
|
||||
grid = UI.ScrollingGrid {
|
||||
disableHeader = true,
|
||||
autospace = true,
|
||||
unfocusedBackgroundSelectedColor = 'black',
|
||||
columns = {
|
||||
{ heading = 'Key', key = 'name' },
|
||||
{ heading = 'Value', key = 'value', textColor = 'yellow' },
|
||||
},
|
||||
accelerators = {
|
||||
grid_select = 'show_variable',
|
||||
},
|
||||
sortCompare = function() end,
|
||||
},
|
||||
},
|
||||
|
||||
breaks = UI.Tab {
|
||||
title = 'Breakpoints',
|
||||
index = 2,
|
||||
UI.MenuBar {
|
||||
buttons = {
|
||||
{ text = 'Toggle', event = 'toggle' },
|
||||
{ text = 'Remove', event = 'remove' },
|
||||
{ text = 'Clear', event = 'clear' },
|
||||
},
|
||||
},
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2,
|
||||
values = breakpoints,
|
||||
autospace = true,
|
||||
columns = {
|
||||
{ heading = 'Line', key = 'line', width = 5 },
|
||||
{ heading = 'Name', key = 'short' },
|
||||
{ heading = 'Path', key = 'path', textColor = 'lightGray' },
|
||||
},
|
||||
getDisplayValues = function(_, row)
|
||||
return {
|
||||
line = row.line,
|
||||
short = fs.getName(row.file),
|
||||
path = fs.getDir(row.file),
|
||||
}
|
||||
end,
|
||||
getRowTextColor = function(self, row, selected)
|
||||
return row.disabled and 'lightGray'
|
||||
or UI.Grid.getRowTextColor(self, row, selected)
|
||||
end,
|
||||
},
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'clear' then
|
||||
Util.clear(self.grid.values)
|
||||
self:emit({ type = 'update_breakpoints' })
|
||||
|
||||
elseif event.type == 'toggle' then
|
||||
local bp = self.grid:getSelected()
|
||||
if bp then
|
||||
bp.disabled = not bp.disabled
|
||||
self:emit({ type = 'update_breakpoints' })
|
||||
end
|
||||
|
||||
elseif event.type == 'grid_select' then
|
||||
self:emit({
|
||||
type = 'open_file',
|
||||
file = event.selected.file,
|
||||
line = event.selected.line,
|
||||
})
|
||||
|
||||
elseif event.type == 'remove' then
|
||||
local bp = self.grid:getSelected()
|
||||
if bp then
|
||||
Util.removeByValue(self.grid.values, bp)
|
||||
self:emit({ type = 'update_breakpoints' })
|
||||
end
|
||||
|
||||
end
|
||||
return UI.Tab.eventHandler(self, event)
|
||||
end,
|
||||
},
|
||||
},
|
||||
|
||||
UI.MenuBar {
|
||||
y = -1,
|
||||
backgroundColor = 'primary',
|
||||
buttonClass = 'InverseButton',
|
||||
buttons = {
|
||||
{ text = 'Continue', event = 'cmd', cmd = 'c' },
|
||||
{ text = 'Step', event = 'cmd', cmd = 's' },
|
||||
{ text = 'Over', event = 'cmd', cmd = 'n' },
|
||||
{ text = 'Out', event = 'cmd', cmd = 'f' },
|
||||
{ text = 'Restart', event = 'restart', width = 9, ex = -1 },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
source = UI.ScrollingGrid {
|
||||
y = '50%', ey = -2,
|
||||
disableHeader = true,
|
||||
backgroundColor = 'gray',
|
||||
backgroundSelectedColor = 'lightGray',
|
||||
unfocusedBackgroundSelectedColor = 'lightGray',
|
||||
columns = {
|
||||
{ key = 'marker', width = 1 },
|
||||
{ key = 'line', textColor = 'cyan', width = 4 },
|
||||
{ heading = 'heading', key = 'source' },
|
||||
},
|
||||
accelerators = {
|
||||
t = 'toggle_enabled'
|
||||
},
|
||||
getDisplayValues = function(_, row)
|
||||
for _,v in pairs(breakpoints) do
|
||||
if v.file == currentFile and v.line == row.line then
|
||||
return {
|
||||
marker = v.disabled and 'x' or '!',
|
||||
line = row.line,
|
||||
source = row.source,
|
||||
}
|
||||
end
|
||||
end
|
||||
return row
|
||||
end,
|
||||
getRowTextColor = function(self, row, selected)
|
||||
return row.line == debugLine and currentFile == debugFile and 'yellow'
|
||||
or UI.Grid.getRowTextColor(self, row, selected)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
self:emit({
|
||||
type = 'toggle_breakpoint',
|
||||
file = currentFile,
|
||||
line = event.selected.line,
|
||||
})
|
||||
elseif event.type == 'toggle_enabled' then
|
||||
local line = self:getSelected() and self:getSelected().line
|
||||
if line then
|
||||
for _,v in pairs(breakpoints) do
|
||||
if v.file == currentFile and v.line == line then
|
||||
v.disabled = not v.disabled
|
||||
self:emit({ type = 'update_breakpoints' })
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return UI.Grid.eventHandler(self, event)
|
||||
end,
|
||||
},
|
||||
statusBar = UI.StatusBar {
|
||||
ex = -12, y = -1,
|
||||
backgroundColor = 'gray',
|
||||
textColor = 'orange',
|
||||
},
|
||||
UI.FlatButton {
|
||||
y = -1, x = -5,
|
||||
textColor = 'orange',
|
||||
event = 'open',
|
||||
text = 'Open',
|
||||
},
|
||||
UI.FlatButton {
|
||||
y = -1, x = -10,
|
||||
textColor = 'orange',
|
||||
event = 'edit_file',
|
||||
text = 'Edit',
|
||||
},
|
||||
|
||||
quick_open = UI.QuickSelect {
|
||||
y = '50%',
|
||||
modal = true,
|
||||
enable = function() end,
|
||||
getFiles = function()
|
||||
local paths = { }
|
||||
for _,v in pairs(Util.split(client.env.package.path, '(.-);')) do
|
||||
v = v:match('(.+)%?') or ''
|
||||
if v:sub(1, 1) ~= '/' then
|
||||
v = fs.combine(fs.getDir(filename), v)
|
||||
end
|
||||
if fs.exists(v) and fs.isDir(v) then
|
||||
paths[fs.combine(v, '')] = true
|
||||
end
|
||||
end
|
||||
|
||||
local t = { }
|
||||
for k in pairs(paths) do
|
||||
local function recurse(dir)
|
||||
local files = fs.list(dir)
|
||||
for _,f in ipairs(files) do
|
||||
local fullName = fs.combine(dir, f)
|
||||
if fs.isDir(fullName) then
|
||||
-- skip virtual dirs
|
||||
if f ~= '.git' and fs.native.isDir(fullName) then
|
||||
recurse(fullName)
|
||||
end
|
||||
elseif fullName:match('(.+)%.lua$') then
|
||||
table.insert(t, {
|
||||
name = f,
|
||||
dir = dir,
|
||||
lname = f:lower(),
|
||||
fullName = fullName,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
recurse(k)
|
||||
end
|
||||
return t
|
||||
end,
|
||||
show = function(self)
|
||||
UI.QuickSelect.enable(self)
|
||||
self:focusFirst()
|
||||
self:draw()
|
||||
self:addTransition('expandUp', { easing = 'outBounce', ticks = 12 })
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'select_cancel' then
|
||||
self:disable()
|
||||
elseif event.type == 'select_file' then
|
||||
self.parent:openFile(event.file)
|
||||
self:disable()
|
||||
end
|
||||
return UI.QuickSelect.eventHandler(self, event)
|
||||
end,
|
||||
},
|
||||
|
||||
textDisplay = UI.SlideOut {
|
||||
ey = '50%',
|
||||
textArea = UI.TextArea {
|
||||
ey = -2,
|
||||
},
|
||||
UI.Button {
|
||||
x = '50%', y = -1,
|
||||
text = 'Ok',
|
||||
event = 'slide_hide',
|
||||
}
|
||||
},
|
||||
|
||||
openFile = function(self, file, line)
|
||||
if file ~= currentFile then
|
||||
local src = loadSource(file)
|
||||
self.source:setValues(src)
|
||||
end
|
||||
if line then
|
||||
self.source:setIndex(#self.source.values)
|
||||
self.source:setIndex(math.max(1, line - 4))
|
||||
end
|
||||
self.source:setIndex(line or 1)
|
||||
|
||||
if currentFile == debugFile then
|
||||
self.statusBar:setStatus(
|
||||
string.format('%s : %d', fs.getName(file), debugLine))
|
||||
else
|
||||
self.statusBar:setStatus(fs.getName(file))
|
||||
end
|
||||
self:draw()
|
||||
end,
|
||||
|
||||
editFile = function(self, file)
|
||||
if fs.exists(file) then
|
||||
local line = self.source:getSelected().line
|
||||
multishell.openTab(_ENV, {
|
||||
path = 'sys/apps/shell.lua',
|
||||
args = { ('edit --line=%d %s'):format(line , '/' .. file) },
|
||||
focused = true,
|
||||
})
|
||||
end
|
||||
end,
|
||||
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'cmd' then
|
||||
self.statusBar:setStatus('Running...')
|
||||
self:sync()
|
||||
message(event.element.cmd)
|
||||
|
||||
elseif event.type == 'restart' then
|
||||
if kernel.find(client.uid) then
|
||||
client:resume('terminate')
|
||||
end
|
||||
startClient()
|
||||
|
||||
elseif event.type == 'open' then
|
||||
self.quick_open:show()
|
||||
|
||||
elseif event.type == 'edit_file' then
|
||||
self:editFile(currentFile)
|
||||
|
||||
elseif event.type == 'open_file' then
|
||||
self:openFile(event.file, event.line)
|
||||
|
||||
elseif event.type == 'update_breakpoints' then
|
||||
self.container.tabs.breaks.grid:update()
|
||||
self.container.tabs.breaks.grid:draw()
|
||||
self.source:draw()
|
||||
Config.update('debugger', config)
|
||||
|
||||
elseif event.type == 'toggle_breakpoint' then
|
||||
for k,v in pairs(breakpoints) do
|
||||
if v.file == event.file and v.line == event.line then
|
||||
table.remove(breakpoints, k)
|
||||
self:emit({ type = 'update_breakpoints' })
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(breakpoints, {
|
||||
file = event.file,
|
||||
line = event.line,
|
||||
bfile = romFiles:lookup(event.file),
|
||||
})
|
||||
|
||||
self:emit({ type = 'update_breakpoints' })
|
||||
|
||||
elseif event.type == 'show_variable' then
|
||||
if type(event.selected.raw) == 'table' then
|
||||
if event.selected.children then
|
||||
event.selected.children = nil
|
||||
else
|
||||
event.selected.children = { }
|
||||
local t = event.selected.raw
|
||||
for k,v in pairs(t) do
|
||||
local depth = event.selected.depth or 0
|
||||
table.insert(event.selected.children, {
|
||||
name = (' '):rep(depth + 2) .. tostring(k),
|
||||
value = tostring(v),
|
||||
raw = v,
|
||||
depth = depth + 2
|
||||
})
|
||||
end
|
||||
table.sort(event.selected.children, function(a, b) return a.name < b.name end)
|
||||
end
|
||||
local t = { }
|
||||
local function insert(values)
|
||||
for _,v in pairs(values) do
|
||||
table.insert(t, v)
|
||||
if v.children then
|
||||
insert(v.children)
|
||||
end
|
||||
end
|
||||
end
|
||||
insert(event.element.orig)
|
||||
event.element:setValues(t)
|
||||
event.element:draw()
|
||||
else
|
||||
self.textDisplay.textArea:setValue(event.selected.value)
|
||||
self.textDisplay:show()
|
||||
end
|
||||
end
|
||||
return UI.Page.eventHandler(self, event)
|
||||
end,
|
||||
enable = function(self)
|
||||
UI.Page.enable(self)
|
||||
startClient()
|
||||
end,
|
||||
}
|
||||
|
||||
Event.on('debuggerX', function(_, cmd, data)
|
||||
if cmd == 'disconnect' then
|
||||
page.statusBar:setStatus('Finished')
|
||||
page:sync()
|
||||
|
||||
elseif cmd == 'break' then
|
||||
kernel.raise(debugger.uid)
|
||||
|
||||
-- local tab
|
||||
table.sort(data.locals, function(a, b) return a.name < b.name end)
|
||||
page.container.tabs.locals.grid:setValues(data.locals)
|
||||
page.container.tabs.locals.grid.orig = Util.shallowCopy(data.locals)
|
||||
|
||||
-- env tab
|
||||
local t = { }
|
||||
for k,v in pairs(getfenv(data.info.func)) do
|
||||
table.insert(t, { name = k, value = tostring(v), raw = v })
|
||||
end
|
||||
table.sort(t, function(a, b) return a.name < b.name end)
|
||||
page.container.tabs.env.grid:setValues(t)
|
||||
page.container.tabs.env.grid.orig = Util.shallowCopy(t)
|
||||
|
||||
debugLine = data.info.currentline
|
||||
debugFile = data.info.source:match('@?(.*)')
|
||||
|
||||
-- source tab
|
||||
page:openFile(debugFile, debugLine)
|
||||
|
||||
-- stack
|
||||
page.container.tabs.stack.grid:setValues(data.stack)
|
||||
|
||||
page:draw()
|
||||
page:sync()
|
||||
end
|
||||
end)
|
||||
|
||||
UI:setPage(page)
|
||||
UI:start()
|
||||
|
||||
if kernel.find(client.uid) then
|
||||
client:resume('terminate')
|
||||
end
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
[ "1a03bd2fd107c453f3183e30b9716f82200671e8270fbbefbe602f5a48705527" ] = {
|
||||
run = "fileui --exec=debug.lua --title=debug",
|
||||
title = "Debug",
|
||||
category = "Apps",
|
||||
iconExt = "\30\50\31\50\128\31\102\152\144\30\102\31\50\159\155\30\50\128\10\30\50\31\102\130\152\30\101\31\53\143\143\30\102\31\50\155\30\50\31\102\129\10\30\50\31\102\130\31\50\128\31\101\134\137\31\50\128\31\102\129",
|
||||
},
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
An interactive debugger for lua
|
||||
|
||||
debug must be enabled!
|
||||
|
||||
Run from a shell prompt
|
||||
> debug FILE [ARGS]
|
||||
@@ -246,35 +246,43 @@ local function server(mode)
|
||||
computers[computerId] = nil
|
||||
page.grid.values = positions
|
||||
page.grid:update()
|
||||
page.grid:draw()
|
||||
page.grid:sync()
|
||||
end
|
||||
end
|
||||
|
||||
Event.on('modem_message', function(_, side, channel, computerId, message, distance)
|
||||
local modem = modems[side]
|
||||
if distance and modem then
|
||||
if distance and modems[side] then
|
||||
if mode == 'gps' and channel == GPS.CHANNEL_GPS and message == "PING" then
|
||||
modem.transmit(computerId, GPS.CHANNEL_GPS, { modem.x, modem.y, modem.z })
|
||||
getPosition(computerId, modem, distance)
|
||||
for _, modem in pairs(modems) do
|
||||
modem.transmit(computerId, GPS.CHANNEL_GPS, { modem.x, modem.y, modem.z })
|
||||
end
|
||||
getPosition(computerId, modems[side], distance)
|
||||
end
|
||||
|
||||
if mode == 'snmp' and channel == 999 then
|
||||
getPosition(computerId, modem, distance, message)
|
||||
getPosition(computerId, modems[side], distance, message)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Event.onInterval(1, function()
|
||||
local resync = false
|
||||
for _, detail in pairs(positions) do
|
||||
if os.clock() - detail.lastChanged > 10 then
|
||||
detail.changed = false
|
||||
resync = true
|
||||
end
|
||||
if os.clock() - detail.timestamp > 60 and detail.alive then
|
||||
detail.alive = false
|
||||
detail.hbeat = false
|
||||
resync = true
|
||||
end
|
||||
end
|
||||
page:draw()
|
||||
page:sync()
|
||||
if resync then
|
||||
page:draw()
|
||||
page:sync()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -296,7 +304,6 @@ elseif args[1] == 'snmp' then
|
||||
table.insert(page.grid.columns,
|
||||
{ heading = 'Label', key = 'label', textColor = colors.cyan }
|
||||
)
|
||||
page.grid.sortColumn = 'label'
|
||||
page.grid:adjustWidth()
|
||||
server('snmp')
|
||||
|
||||
|
||||
15
ignore/chars.lua
Normal file
15
ignore/chars.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
local w, h = term.getSize()
|
||||
|
||||
term.clear()
|
||||
term.setCursorPos(1, 1)
|
||||
|
||||
local t = { }
|
||||
for i = 1, 8 do
|
||||
table.insert(t, '---')
|
||||
end
|
||||
|
||||
for i = 1, 255 do
|
||||
table.insert(t, string.format('%d %c', i, i))
|
||||
end
|
||||
|
||||
textutils.pagedTabulate(t)
|
||||
196
ignore/glasses.lua
Normal file
196
ignore/glasses.lua
Normal file
@@ -0,0 +1,196 @@
|
||||
local class = require('opus.class')
|
||||
local UI = require('opus.ui')
|
||||
local Event = require('opus.event')
|
||||
local Peripheral = require('opus.peripheral')
|
||||
|
||||
--[[-- Glasses device --]]--
|
||||
local Glasses = class()
|
||||
function Glasses:init(args)
|
||||
|
||||
local defaults = {
|
||||
backgroundColor = colors.black,
|
||||
textColor = colors.white,
|
||||
textScale = .5,
|
||||
backgroundOpacity = .5,
|
||||
multiplier = 2.6665,
|
||||
-- multiplier = 2.333,
|
||||
}
|
||||
defaults.width, defaults.height = term.getSize()
|
||||
|
||||
UI:setProperties(defaults, args)
|
||||
UI:setProperties(self, defaults)
|
||||
|
||||
self.bridge = Peripheral.get({
|
||||
type = 'openperipheral_bridge',
|
||||
method = 'addBox',
|
||||
})
|
||||
self.bridge.clear()
|
||||
|
||||
self.setBackgroundColor = function(...) end
|
||||
self.setTextColor = function(...) end
|
||||
|
||||
self.t = { }
|
||||
for i = 1, self.height do
|
||||
self.t[i] = {
|
||||
text = string.rep(' ', self.width+1),
|
||||
--text = self.bridge.addText(0, 40+i*4, string.rep(' ', self.width+1), 0xffffff),
|
||||
bg = { },
|
||||
textFields = { },
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function Glasses:setBackgroundBox(boxes, ax, bx, y, bgColor)
|
||||
local colors = {
|
||||
[ colors.black ] = 0x000000,
|
||||
[ colors.brown ] = 0x7F664C,
|
||||
[ colors.blue ] = 0x253192,
|
||||
[ colors.red ] = 0xFF0000,
|
||||
[ colors.gray ] = 0x272727,
|
||||
[ colors.lime ] = 0x426A0D,
|
||||
[ colors.green ] = 0x2D5628,
|
||||
[ colors.white ] = 0xFFFFFF
|
||||
}
|
||||
|
||||
local function overlap(box, ax, bx)
|
||||
if bx < box.ax or ax > box.bx then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
for _,box in pairs(boxes) do
|
||||
if overlap(box, ax, bx) then
|
||||
if box.bgColor == bgColor then
|
||||
ax = math.min(ax, box.ax)
|
||||
bx = math.max(bx, box.bx)
|
||||
box.ax = box.bx + 1
|
||||
elseif ax == box.ax then
|
||||
box.ax = bx + 1
|
||||
elseif ax > box.ax then
|
||||
if bx < box.bx then
|
||||
table.insert(boxes, { -- split
|
||||
ax = bx + 1,
|
||||
bx = box.bx,
|
||||
bgColor = box.bgColor
|
||||
})
|
||||
box.bx = ax - 1
|
||||
break
|
||||
else
|
||||
box.ax = box.bx + 1
|
||||
end
|
||||
elseif ax < box.ax then
|
||||
if bx > box.bx then
|
||||
box.ax = box.bx + 1 -- delete
|
||||
else
|
||||
box.ax = bx + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if bgColor ~= colors.black then
|
||||
table.insert(boxes, {
|
||||
ax = ax,
|
||||
bx = bx,
|
||||
bgColor = bgColor
|
||||
})
|
||||
end
|
||||
|
||||
local deleted
|
||||
repeat
|
||||
deleted = false
|
||||
for k,box in pairs(boxes) do
|
||||
if box.ax > box.bx then
|
||||
if box.box then
|
||||
box.box.delete()
|
||||
end
|
||||
table.remove(boxes, k)
|
||||
deleted = true
|
||||
break
|
||||
end
|
||||
if not box.box then
|
||||
box.box = self.bridge.addBox(
|
||||
math.floor(self.x + (box.ax - 1) * self.multiplier),
|
||||
self.y + y * 4,
|
||||
math.ceil((box.bx - box.ax + 1) * self.multiplier),
|
||||
4,
|
||||
colors[bgColor],
|
||||
self.backgroundOpacity)
|
||||
else
|
||||
box.box.setX(self.x + math.floor((box.ax - 1) * self.multiplier))
|
||||
box.box.setWidth(math.ceil((box.bx - box.ax + 1) * self.multiplier))
|
||||
end
|
||||
end
|
||||
until not deleted
|
||||
end
|
||||
|
||||
function Glasses:write(x, y, text, bg)
|
||||
|
||||
if x < 1 then
|
||||
error(' less ', 6)
|
||||
end
|
||||
if y <= #self.t then
|
||||
local line = self.t[y]
|
||||
local str = line.text
|
||||
str = str:sub(1, x-1) .. text .. str:sub(x + #text)
|
||||
self.t[y].text = str
|
||||
|
||||
for _,tf in pairs(line.textFields) do
|
||||
tf.delete()
|
||||
end
|
||||
line.textFields = { }
|
||||
|
||||
local function split(st)
|
||||
local words = { }
|
||||
local offset = 0
|
||||
while true do
|
||||
local b,e,w = st:find('(%S+)')
|
||||
if not b then
|
||||
break
|
||||
end
|
||||
table.insert(words, {
|
||||
offset = b + offset - 1,
|
||||
text = w,
|
||||
})
|
||||
offset = offset + e
|
||||
st = st:sub(e + 1)
|
||||
end
|
||||
return words
|
||||
end
|
||||
|
||||
local words = split(str)
|
||||
for _,word in pairs(words) do
|
||||
local tf = self.bridge.addText(self.x + word.offset * self.multiplier,
|
||||
self.y+y*4, '', 0xffffff)
|
||||
tf.setScale(self.textScale)
|
||||
tf.setZ(1)
|
||||
tf.setText(word.text)
|
||||
table.insert(line.textFields, tf)
|
||||
end
|
||||
|
||||
self:setBackgroundBox(line.bg, x, x + #text - 1, y, bg)
|
||||
end
|
||||
end
|
||||
|
||||
function Glasses:clear(bg)
|
||||
for _,line in pairs(self.t) do
|
||||
for _,tf in pairs(line.textFields) do
|
||||
tf.delete()
|
||||
end
|
||||
line.textFields = { }
|
||||
line.text = string.rep(' ', self.width+1)
|
||||
-- self.t[i].text.setText('')
|
||||
end
|
||||
end
|
||||
|
||||
function Glasses:reset()
|
||||
self:clear()
|
||||
self.bridge.clear()
|
||||
self.bridge.sync()
|
||||
end
|
||||
|
||||
function Glasses:sync()
|
||||
self.bridge.sync()
|
||||
end
|
||||
|
||||
return Glasses
|
||||
@@ -1,77 +0,0 @@
|
||||
local pals = {
|
||||
{ -- molokai
|
||||
0x101010,
|
||||
0x960050,
|
||||
0x66aa11,
|
||||
0xc47f2c,
|
||||
0x30309b,
|
||||
0x7e40a5,
|
||||
0x3579a8,
|
||||
0x9999aa,
|
||||
0x303030,
|
||||
0xff0090,
|
||||
0x80ff00,
|
||||
0xffba68,
|
||||
0x5f5fee,
|
||||
0xbb88dd,
|
||||
0x4eb4fa,
|
||||
0xd0d0d0,
|
||||
},
|
||||
{ -- solarized
|
||||
0xffffd7,
|
||||
0xd75f00, -- orange
|
||||
0x585858,
|
||||
0x0087ff, -- light blue
|
||||
0x1c1c1c,
|
||||
0x8a8a8a,
|
||||
0xd70000, -- light red
|
||||
0x808080, -- gray
|
||||
0xe4e4e4, -- light gray
|
||||
0x00afaf, -- cyan
|
||||
0x626262,
|
||||
0x5f5faf, -- blue
|
||||
0xaf8700, -- brown
|
||||
0x5f8700, -- green
|
||||
0xaf005f, -- dark red
|
||||
0x262626, -- black
|
||||
},
|
||||
{
|
||||
0xf7f7f7,
|
||||
0xc4a500, -- mustard
|
||||
0xf79aff, -- magenta
|
||||
0x8dcff0, -- light blue
|
||||
0xfee14d, -- yellow
|
||||
0xc4f137, -- lime
|
||||
0x207383, -- dark green
|
||||
0x7a7a7a,
|
||||
0xa1a1a1,
|
||||
0x6ad9cf, -- greenish blue
|
||||
0xba8acc, -- purple
|
||||
0x62a3c4, -- blue gray
|
||||
0xd6837c, -- orange/brown
|
||||
0x7da900, -- green
|
||||
0xb84131, -- redish brown
|
||||
0x1b1b1b,
|
||||
}
|
||||
}
|
||||
term.setPaletteColor(2^0,0xFFFFFF)
|
||||
term.setPaletteColor(2^1,0xFF6300)
|
||||
term.setPaletteColor(2^2,0xFF00DE)
|
||||
term.setPaletteColor(2^3,0x00C3FF)
|
||||
term.setPaletteColor(2^4,0xFFFF00)
|
||||
term.setPaletteColor(2^5,0x91FF00)
|
||||
term.setPaletteColor(2^6,0xFF6DA8)
|
||||
term.setPaletteColor(2^7,0x585757)
|
||||
term.setPaletteColor(2^8,0xA9A9A9)
|
||||
term.setPaletteColor(2^9,0x00FFFF)
|
||||
term.setPaletteColor(2^10,0x7700FF)
|
||||
term.setPaletteColor(2^11,0x0000FF)
|
||||
term.setPaletteColor(2^12,0x4C2700)
|
||||
term.setPaletteColor(2^13,0x00FF00)
|
||||
term.setPaletteColor(2^14,0xFF0000)
|
||||
term.setPaletteColor(2^15,0x000000)
|
||||
|
||||
local pal = pals[tonumber(({...})[1])]
|
||||
for k,v in pairs(pal) do
|
||||
term.setPaletteColour(2^(k - 1), v)
|
||||
end
|
||||
173
ignore/rabbitRancher.lua
Normal file
173
ignore/rabbitRancher.lua
Normal file
@@ -0,0 +1,173 @@
|
||||
--[[
|
||||
Breed rabbits with a rabbit.
|
||||
]]
|
||||
|
||||
local neural = require('neural.interface')
|
||||
local Point = require('point')
|
||||
local Sound = require('sound')
|
||||
local Util = require('util')
|
||||
|
||||
local os = _G.os
|
||||
|
||||
local BREEDING = 'Rabbit'
|
||||
local WALK_SPEED = 1.3
|
||||
local MAX_GROWN = 100
|
||||
local BREED_DELAY = 120
|
||||
|
||||
neural.assertModules({
|
||||
'plethora:sensor',
|
||||
'plethora:scanner',
|
||||
'plethora:laser',
|
||||
'plethora:kinetic',
|
||||
'plethora:introspection',
|
||||
})
|
||||
|
||||
local ID = neural.getID()
|
||||
local fed = { }
|
||||
|
||||
local function resupply()
|
||||
local slot = neural.getEquipment().list()[1]
|
||||
if slot and slot.count > 32 then
|
||||
return
|
||||
end
|
||||
print('resupplying')
|
||||
|
||||
local dispenser = Util.find(neural.scan(), 'name', 'minecraft:wooden_pressure_plate')
|
||||
if dispenser then
|
||||
if math.abs(dispenser.x) > 1 or math.abs(dispenser.z) > 1 then
|
||||
neural.walkTo({ x = dispenser.x, y = 0, z = dispenser.z }, WALK_SPEED)
|
||||
end
|
||||
neural.lookAt(dispenser)
|
||||
neural.getEquipment().suck(1, 64)
|
||||
end
|
||||
end
|
||||
|
||||
local function breed(entity)
|
||||
print('breeding')
|
||||
entity.lastFed = os.clock()
|
||||
fed[entity.id] = entity
|
||||
|
||||
neural.walkTo(entity, WALK_SPEED, .5)
|
||||
entity = neural.getMetaByID(entity.id)
|
||||
if entity and not entity.isChild then
|
||||
neural.lookAt(entity)
|
||||
neural.use(1)
|
||||
os.sleep(.1)
|
||||
end
|
||||
end
|
||||
|
||||
local function kill(entity)
|
||||
print('killing')
|
||||
neural.walkTo(entity, WALK_SPEED, 2)
|
||||
entity = neural.getMetaByID(entity.id)
|
||||
if entity and not entity.isChild then
|
||||
neural.lookAt(entity)
|
||||
neural.fireAt({ x = entity.x, y = 0, z = entity.z })
|
||||
Sound.play('entity.firework.launch')
|
||||
os.sleep(.2)
|
||||
end
|
||||
end
|
||||
|
||||
local function getEntities()
|
||||
return Util.filter(neural.sense(), function(entity)
|
||||
if entity.name == BREEDING and entity.y > -.5 and entity.id ~= ID then
|
||||
return true
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local function getHungry(entities)
|
||||
for _,v in pairs(entities) do
|
||||
if not fed[v.id] or
|
||||
os.clock() - fed[v.id].lastFed > BREED_DELAY then
|
||||
return v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function randomEntity(entities)
|
||||
local r = math.random(1, Util.size(entities))
|
||||
local i = 1
|
||||
for _, v in pairs(entities) do
|
||||
i = i + 1
|
||||
if i > r then
|
||||
return v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function dropOff()
|
||||
print('dropping')
|
||||
|
||||
if neural.getEquipment().list()[2] then
|
||||
local b = Util.find(neural.scan(), 'name', 'minecraft:hopper')
|
||||
if b then
|
||||
neural.walkTo({ x = b.x, y = 0, z = b.z }, 2)
|
||||
|
||||
b = Util.find(neural.scan(), 'name', 'minecraft:hopper')
|
||||
if b and math.abs(b.x) < 1 and math.abs(b.z) < 1 then
|
||||
print('dropped')
|
||||
neural.getEquipment().drop(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function pickup(id)
|
||||
local b = neural.getMetaByID(id)
|
||||
if b then
|
||||
neural.walkTo(b, 2)
|
||||
|
||||
local main = neural.getEquipment().list()[1]
|
||||
local amount = neural.getEquipment().suck(not main and 2 or nil)
|
||||
print('sucked: ' .. amount)
|
||||
if amount > 0 then
|
||||
Sound.play('entity.item.pickup')
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function drops()
|
||||
local sensed = Util.reduce(neural.sense(), function(acc, s)
|
||||
if Util.round(s.y) == 0 and s.name == 'Item' then
|
||||
acc[s.id] = s
|
||||
end
|
||||
return acc
|
||||
end, { })
|
||||
|
||||
local pt = { x = 0, y = 0, z = 0 }
|
||||
while true do
|
||||
local b = Point.closest(pt, sensed)
|
||||
if not b then
|
||||
break
|
||||
end
|
||||
sensed[b.id] = nil
|
||||
|
||||
if pickup(b.id) then
|
||||
pt = b
|
||||
else
|
||||
dropOff()
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
while true do
|
||||
resupply()
|
||||
|
||||
local entities = getEntities()
|
||||
|
||||
if Util.size(entities) > MAX_GROWN then
|
||||
kill(randomEntity(entities))
|
||||
else
|
||||
local entity = getHungry(entities)
|
||||
if entity then
|
||||
breed(entity)
|
||||
else
|
||||
print('sleeping')
|
||||
os.sleep(5)
|
||||
end
|
||||
drops()
|
||||
end
|
||||
end
|
||||
11
lfs/.package
11
lfs/.package
@@ -1,11 +0,0 @@
|
||||
{
|
||||
title = 'LuaFileSystem',
|
||||
repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/lfs',
|
||||
description = [[LuaFileSystem port for computercraft
|
||||
See: https://github.com/keplerproject/luafilesystem
|
||||
|
||||
LuaFileSystem is a Lua library developed to complement the set of functions related to file systems offered by the standard Lua distribution.
|
||||
|
||||
LuaFileSystem offers a portable way to access the underlying directory structure and file attributes. LuaFileSystem is free software and uses the same license as Lua 5.x (MIT).]],
|
||||
license = 'MIT',
|
||||
}
|
||||
@@ -1,237 +0,0 @@
|
||||
-- a port of LuaFileSystem
|
||||
-- https://keplerproject.github.io/luafilesystem/manual.html
|
||||
|
||||
local fs = _G.fs
|
||||
local shell = _ENV.shell
|
||||
|
||||
local lfs = {
|
||||
_VERSION = '1.8.0.computercraft'
|
||||
}
|
||||
|
||||
-- lfs.attributes (filepath [, request_name | result_table])
|
||||
-- Returns a table with the file attributes corresponding to filepath (or nil followed
|
||||
-- by an error message and a system-dependent error code in case of error). If the second
|
||||
-- optional argument is given and is a string, then only the value of the named attribute
|
||||
-- is returned (this use is equivalent to lfs.attributes(filepath)[request_name], but the
|
||||
-- table is not created and only one attribute is retrieved from the O.S.). if a table is
|
||||
-- passed as the second argument, it (result_table) is filled with attributes and returned
|
||||
-- instead of a new table. The attributes are described as follows; attribute mode is a
|
||||
-- string, all the others are numbers, and the time related attributes use the same time
|
||||
-- reference of os.time:
|
||||
function lfs.attributes(path, request_name)
|
||||
path = shell.resolve(path)
|
||||
|
||||
local s, fsattr = pcall(fs.attributes, path)
|
||||
if not s then
|
||||
return nil, fsattr, 1
|
||||
end
|
||||
|
||||
local attributes = type(request_name) == 'table' and request_name or { }
|
||||
|
||||
-- on Unix systems, this represents the device that the inode resides on.
|
||||
-- On Windows systems, represents the drive number of the disk containing the file
|
||||
attributes.dev = fs.getDrive(path)
|
||||
|
||||
-- on Unix systems, this represents the inode number.
|
||||
-- On Windows systems this has no meaning
|
||||
attributes.ino = nil
|
||||
|
||||
--string representing the associated protection mode
|
||||
-- (the values could be file, directory, link, socket, named pipe,
|
||||
-- char device, block device or other)
|
||||
attributes.mode = fsattr.isDir and 'directory' or 'file'
|
||||
|
||||
-- number of hard links to the file
|
||||
attributes.nlink = 0
|
||||
|
||||
-- user-id of owner (Unix only, always 0 on Windows)
|
||||
attributes.uid = 0
|
||||
|
||||
-- group-id of owner (Unix only, always 0 on Windows)
|
||||
attributes.gid = 0
|
||||
|
||||
-- on Unix systems, represents the device type, for special file inodes.
|
||||
-- On Windows systems represents the same as dev
|
||||
attributes.rdev = attributes.dev
|
||||
|
||||
-- time of last access
|
||||
attributes.access = fsattr.modification
|
||||
|
||||
-- time of last data modification
|
||||
attributes.modification = fsattr.modification
|
||||
|
||||
-- time of last file status change
|
||||
attributes.change = fsattr.modification
|
||||
|
||||
-- file size, in bytes
|
||||
attributes.size = fsattr.size
|
||||
|
||||
-- file permissions string
|
||||
local perm = (fs.isDir or fs.isReadOnly(path)) and 'r-x' or 'rwx'
|
||||
attributes.permissions = perm .. perm .. perm
|
||||
|
||||
-- block allocated for file; (Unix only)
|
||||
attributes.blocks = nil
|
||||
|
||||
-- optimal file system I/O blocksize; (Unix only)
|
||||
attributes.blksize = nil
|
||||
|
||||
return type(request_name) ~= 'string' and attributes or attributes[request_name]
|
||||
end
|
||||
|
||||
-- lfs.chdir (path)
|
||||
-- Changes the current working directory to the given path.
|
||||
-- Returns true in case of success or nil plus an error string.
|
||||
function lfs.chdir(path)
|
||||
path = shell.resolve(path)
|
||||
if fs.isDir(path) then
|
||||
shell.setDir(path)
|
||||
return true
|
||||
end
|
||||
return nil, path .. ': No such directory'
|
||||
end
|
||||
|
||||
-- lfs.currentdir ()
|
||||
-- Returns a string with the current working directory or nil plus an error string.
|
||||
function lfs.currentdir()
|
||||
return '/' .. shell.dir()
|
||||
end
|
||||
|
||||
-- iter, dir_obj = lfs.dir (path)
|
||||
-- Lua iterator over the entries of a given directory.
|
||||
-- Each time the iterator is called with dir_obj it returns a directory
|
||||
-- entry's name as a string, or nil if there are no more entries.
|
||||
-- You can also iterate by calling dir_obj:next(), and explicitly close the
|
||||
-- directory before the iteration finished with dir_obj:close().
|
||||
-- Raises an error if path is not a directory.
|
||||
function lfs.dir(path)
|
||||
path = shell.resolve(path)
|
||||
local set = fs.list(path)
|
||||
local iter = function()
|
||||
local key, value = next(set)
|
||||
set[key or false] = nil
|
||||
return value
|
||||
end
|
||||
return iter, {
|
||||
valid = true,
|
||||
closed = false,
|
||||
next = function(self)
|
||||
if not self.valid then
|
||||
error('file iterator invalid')
|
||||
end
|
||||
local n = iter()
|
||||
if not n then
|
||||
self.valid = false
|
||||
end
|
||||
return n
|
||||
end,
|
||||
close = function(self)
|
||||
if self.closed then
|
||||
error('file iterator invalid')
|
||||
end
|
||||
self.closed = true
|
||||
self.valid = false
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
-- lfs.link (old, new[, symlink])
|
||||
-- Creates a link. The first argument is the object to link to and the second is the
|
||||
-- name of the link. If the optional third argument is true, the link will by a symbolic
|
||||
-- link (by default, a hard link is created).
|
||||
function lfs.link(old, new, symlink)
|
||||
if not symlink then
|
||||
return false
|
||||
end
|
||||
-- hard links are not supported in vfs :(
|
||||
old = shell.resolve(old)
|
||||
new = shell.resolve(new)
|
||||
return not not fs.mount(new, 'linkfs', old)
|
||||
end
|
||||
|
||||
-- lfs.mkdir (dirname)
|
||||
-- Creates a new directory. The argument is the name of the new directory.
|
||||
-- Returns true in case of success or nil, an error message and a system-dependent
|
||||
-- error code in case of error.
|
||||
function lfs.mkdir(dirname)
|
||||
dirname = shell.resolve(dirname)
|
||||
if fs.exists(fs.getDir(dirname)) then
|
||||
fs.makeDir(dirname)
|
||||
if fs.isDir(dirname) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return nil, dirname .. ': Unable to create directory', 1
|
||||
end
|
||||
|
||||
-- lfs.rmdir (dirname)
|
||||
-- Removes an existing directory. The argument is the name of the directory.
|
||||
-- Returns true in case of success or nil, an error message and a system-dependent
|
||||
-- error code in case of error.
|
||||
function lfs.rmdir(dirname)
|
||||
dirname = shell.resolve(dirname)
|
||||
if not fs.exists(dirname) or not fs.isDir(dirname) then
|
||||
return false, dirname .. ': Not a directory', 1
|
||||
end
|
||||
pcall(fs.delete, dirname)
|
||||
return not fs.exists(dirname) or false, dirname .. ': Unable to remove directory', 1
|
||||
end
|
||||
|
||||
-- lfs.setmode (file, mode)
|
||||
-- Sets the writing mode for a file. The mode string can be either "binary" or "text".
|
||||
-- Returns true followed the previous mode string for the file, or nil followed by an
|
||||
-- error string in case of errors. On non-Windows platforms, where the two modes are
|
||||
-- identical, setting the mode has no effect, and the mode is always returned as binary.
|
||||
function lfs.setmode(file)
|
||||
if tostring(file) == 'file (closed)' then
|
||||
error('closed file')
|
||||
end
|
||||
return true, 'binary'
|
||||
end
|
||||
|
||||
-- lfs.symlinkattributes (filepath [, request_name])
|
||||
-- Identical to lfs.attributes except that it obtains information about the link itself
|
||||
-- (not the file it refers to). It also adds a target field, containing the file name that
|
||||
-- the symlink points to. On Windows this function does not yet support links, and is
|
||||
-- identical to lfs.attributes.
|
||||
function lfs.symlinkattributes(filepath, request_name)
|
||||
filepath = shell.resolve(filepath)
|
||||
|
||||
local target = fs.resolve(filepath)
|
||||
local attribs = lfs.attributes('/' .. target)
|
||||
if filepath ~= target then
|
||||
attribs.target = '/' .. target
|
||||
attribs.mode = 'link'
|
||||
end
|
||||
|
||||
return request_name and attribs[request_name] or attribs
|
||||
end
|
||||
|
||||
-- lfs.touch (filepath [, atime [, mtime]])
|
||||
-- Set access and modification times of a file. This function is a bind to utime function.
|
||||
-- The first argument is the filename, the second argument (atime) is the access time, and
|
||||
-- the third argument (mtime) is the modification time. Both times are provided in seconds
|
||||
-- (which should be generated with Lua standard function os.time). If the modification time
|
||||
-- is omitted, the access time provided is used; if both times are omitted, the current time
|
||||
-- is used.
|
||||
-- Returns true in case of success or nil, an error message and a system-dependent error
|
||||
-- code in case of error.
|
||||
function lfs.touch(filename, atime, mtime)
|
||||
mtime = mtime or atime
|
||||
filename = shell.resolve(filename)
|
||||
|
||||
if atime or mtime then
|
||||
error('setting access/modification time is not supported')
|
||||
end
|
||||
|
||||
-- cc does not suport setting atime/mtime
|
||||
-- error('lfs.touch not supported')
|
||||
if not fs.exists(filename) then
|
||||
local f = fs.open(filename, 'w')
|
||||
if f then
|
||||
f.close()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return lfs
|
||||
@@ -1 +0,0 @@
|
||||
packages/lfs/tests/test.lua urlfs https://raw.githubusercontent.com/keplerproject/luafilesystem/master/tests/test.lua
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
title = 'LPeg',
|
||||
repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/lpeg',
|
||||
description = [[A pure Lua port of LPeg, Roberto Ierusalimschy's Parsing Expression Grammars library.
|
||||
|
||||
This version of LuLPeg emulates LPeg v0.12.
|
||||
see: https://github.com/pygy/LuLPeg/]],
|
||||
license = 'MIT',
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
rom/modules/main/lpeg.lua urlfs https://raw.githubusercontent.com/pygy/LuLPeg/master/lulpeg.lua
|
||||
334
lzwfs/lzwfs.lua
334
lzwfs/lzwfs.lua
@@ -19,9 +19,9 @@ local SIGC = 'LZWC'
|
||||
local basedictcompress = {}
|
||||
local basedictdecompress = {}
|
||||
for i = 0, 255 do
|
||||
local ic, iic = char(i), char(i, 0)
|
||||
basedictcompress[ic] = iic
|
||||
basedictdecompress[iic] = ic
|
||||
local ic, iic = char(i), char(i, 0)
|
||||
basedictcompress[ic] = iic
|
||||
basedictdecompress[iic] = ic
|
||||
end
|
||||
|
||||
local native = { open = fs.open }
|
||||
@@ -29,123 +29,123 @@ local enabled = false
|
||||
local filters = { }
|
||||
|
||||
local function dictAddA(str, dict, a, b)
|
||||
if a >= 256 then
|
||||
a, b = 0, b+1
|
||||
if b >= 256 then
|
||||
dict = {}
|
||||
b = 1
|
||||
end
|
||||
end
|
||||
dict[str] = char(a,b)
|
||||
a = a+1
|
||||
return dict, a, b
|
||||
if a >= 256 then
|
||||
a, b = 0, b+1
|
||||
if b >= 256 then
|
||||
dict = {}
|
||||
b = 1
|
||||
end
|
||||
end
|
||||
dict[str] = char(a,b)
|
||||
a = a+1
|
||||
return dict, a, b
|
||||
end
|
||||
|
||||
local function compress(input)
|
||||
if type(input) ~= "string" then
|
||||
error ("string expected, got "..type(input))
|
||||
end
|
||||
local len = #input
|
||||
if len <= 1 then
|
||||
return input
|
||||
end
|
||||
if type(input) ~= "string" then
|
||||
error ("string expected, got "..type(input))
|
||||
end
|
||||
local len = #input
|
||||
if len <= 1 then
|
||||
return input
|
||||
end
|
||||
|
||||
local dict = {}
|
||||
local a, b = 0, 1
|
||||
local dict = {}
|
||||
local a, b = 0, 1
|
||||
|
||||
local result = { SIGC }
|
||||
local resultlen = 1
|
||||
local n = 2
|
||||
local word = ""
|
||||
for i = 1, len do
|
||||
local c = sub(input, i, i)
|
||||
local wc = word..c
|
||||
if not (basedictcompress[wc] or dict[wc]) then
|
||||
local write = basedictcompress[word] or dict[word]
|
||||
if not write then
|
||||
error "algorithm error, could not fetch word"
|
||||
end
|
||||
result[n] = write
|
||||
resultlen = resultlen + #write
|
||||
n = n+1
|
||||
if len <= resultlen then
|
||||
return input
|
||||
end
|
||||
dict, a, b = dictAddA(wc, dict, a, b)
|
||||
word = c
|
||||
else
|
||||
word = wc
|
||||
end
|
||||
end
|
||||
result[n] = basedictcompress[word] or dict[word]
|
||||
resultlen = resultlen+#result[n]
|
||||
if len <= resultlen then
|
||||
return input
|
||||
end
|
||||
return tconcat(result)
|
||||
local result = { SIGC }
|
||||
local resultlen = 1
|
||||
local n = 2
|
||||
local word = ""
|
||||
for i = 1, len do
|
||||
local c = sub(input, i, i)
|
||||
local wc = word..c
|
||||
if not (basedictcompress[wc] or dict[wc]) then
|
||||
local write = basedictcompress[word] or dict[word]
|
||||
if not write then
|
||||
error "algorithm error, could not fetch word"
|
||||
end
|
||||
result[n] = write
|
||||
resultlen = resultlen + #write
|
||||
n = n+1
|
||||
if len <= resultlen then
|
||||
return input
|
||||
end
|
||||
dict, a, b = dictAddA(wc, dict, a, b)
|
||||
word = c
|
||||
else
|
||||
word = wc
|
||||
end
|
||||
end
|
||||
result[n] = basedictcompress[word] or dict[word]
|
||||
resultlen = resultlen+#result[n]
|
||||
if len <= resultlen then
|
||||
return input
|
||||
end
|
||||
return tconcat(result)
|
||||
end
|
||||
|
||||
local function dictAddB(str, dict, a, b)
|
||||
if a >= 256 then
|
||||
a, b = 0, b+1
|
||||
if b >= 256 then
|
||||
dict = {}
|
||||
b = 1
|
||||
end
|
||||
end
|
||||
dict[char(a,b)] = str
|
||||
a = a+1
|
||||
return dict, a, b
|
||||
if a >= 256 then
|
||||
a, b = 0, b+1
|
||||
if b >= 256 then
|
||||
dict = {}
|
||||
b = 1
|
||||
end
|
||||
end
|
||||
dict[char(a,b)] = str
|
||||
a = a+1
|
||||
return dict, a, b
|
||||
end
|
||||
|
||||
local function decompress(input)
|
||||
if type(input) ~= "string" then
|
||||
error( "string expected, got "..type(input))
|
||||
end
|
||||
if type(input) ~= "string" then
|
||||
error( "string expected, got "..type(input))
|
||||
end
|
||||
|
||||
if #input <= 1 then
|
||||
return input
|
||||
end
|
||||
if #input <= 1 then
|
||||
return input
|
||||
end
|
||||
|
||||
local control = sub(input, 1, 4)
|
||||
if control ~= SIGC then
|
||||
return input
|
||||
end
|
||||
input = sub(input, 5)
|
||||
local len = #input
|
||||
local control = sub(input, 1, 4)
|
||||
if control ~= SIGC then
|
||||
return input
|
||||
end
|
||||
input = sub(input, 5)
|
||||
local len = #input
|
||||
|
||||
if len < 2 then
|
||||
error("invalid input - not a compressed string")
|
||||
end
|
||||
if len < 2 then
|
||||
error("invalid input - not a compressed string")
|
||||
end
|
||||
|
||||
local dict = {}
|
||||
local a, b = 0, 1
|
||||
local dict = {}
|
||||
local a, b = 0, 1
|
||||
|
||||
local result = {}
|
||||
local n = 1
|
||||
local last = sub(input, 1, 2)
|
||||
result[n] = basedictdecompress[last] or dict[last]
|
||||
n = n+1
|
||||
for i = 3, len, 2 do
|
||||
local code = sub(input, i, i+1)
|
||||
local lastStr = basedictdecompress[last] or dict[last]
|
||||
if not lastStr then
|
||||
error( "could not find last from dict. Invalid input?")
|
||||
end
|
||||
local toAdd = basedictdecompress[code] or dict[code]
|
||||
if toAdd then
|
||||
result[n] = toAdd
|
||||
n = n+1
|
||||
dict, a, b = dictAddB(lastStr..sub(toAdd, 1, 1), dict, a, b)
|
||||
else
|
||||
local tmp = lastStr..sub(lastStr, 1, 1)
|
||||
result[n] = tmp
|
||||
n = n+1
|
||||
dict, a, b = dictAddB(tmp, dict, a, b)
|
||||
end
|
||||
last = code
|
||||
end
|
||||
return tconcat(result)
|
||||
local result = {}
|
||||
local n = 1
|
||||
local last = sub(input, 1, 2)
|
||||
result[n] = basedictdecompress[last] or dict[last]
|
||||
n = n+1
|
||||
for i = 3, len, 2 do
|
||||
local code = sub(input, i, i+1)
|
||||
local lastStr = basedictdecompress[last] or dict[last]
|
||||
if not lastStr then
|
||||
error( "could not find last from dict. Invalid input?")
|
||||
end
|
||||
local toAdd = basedictdecompress[code] or dict[code]
|
||||
if toAdd then
|
||||
result[n] = toAdd
|
||||
n = n+1
|
||||
dict, a, b = dictAddB(lastStr..sub(toAdd, 1, 1), dict, a, b)
|
||||
else
|
||||
local tmp = lastStr..sub(lastStr, 1, 1)
|
||||
result[n] = tmp
|
||||
n = n+1
|
||||
dict, a, b = dictAddB(tmp, dict, a, b)
|
||||
end
|
||||
last = code
|
||||
end
|
||||
return tconcat(result)
|
||||
end
|
||||
|
||||
local function split(str, pattern)
|
||||
@@ -157,39 +157,39 @@ local function split(str, pattern)
|
||||
end
|
||||
|
||||
local function matchesFilter(fname)
|
||||
if not fname:find('lzwfs') then -- don't compress anything with lzwfs in name (sigh)
|
||||
for _, filter in pairs(filters) do
|
||||
if fname:match(filter) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
if not fname:find('lzwfs') then -- don't compress anything with lzwfs in name (sigh)
|
||||
for _, filter in pairs(filters) do
|
||||
if fname:match(filter) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function fs.open(fname, flags)
|
||||
if not enabled then
|
||||
return native.open(fname, flags)
|
||||
end
|
||||
if not enabled then
|
||||
return native.open(fname, flags)
|
||||
end
|
||||
|
||||
if flags == 'r' then
|
||||
local f, err = native.open(fname, 'rb')
|
||||
if not f then
|
||||
return f, err
|
||||
end
|
||||
if flags == 'r' then
|
||||
local f, err = native.open(fname, 'rb')
|
||||
if not f then
|
||||
return f, err
|
||||
end
|
||||
|
||||
local ctr = 0
|
||||
local lines
|
||||
return {
|
||||
read = function()
|
||||
if not lines then
|
||||
lines = decompress(f.readAll())
|
||||
read = function()
|
||||
if not lines then
|
||||
lines = decompress(f.readAll())
|
||||
end
|
||||
ctr = ctr + 1
|
||||
return lines:sub(ctr, ctr)
|
||||
end,
|
||||
readLine = function()
|
||||
ctr = ctr + 1
|
||||
return lines:sub(ctr, ctr)
|
||||
end,
|
||||
readLine = function()
|
||||
if not lines then
|
||||
lines = split(decompress(f.readAll()))
|
||||
lines = split(decompress(f.readAll()))
|
||||
end
|
||||
ctr = ctr + 1
|
||||
return lines[ctr]
|
||||
@@ -197,61 +197,61 @@ function fs.open(fname, flags)
|
||||
readAll = function()
|
||||
return decompress(f.readAll())
|
||||
end,
|
||||
close = function()
|
||||
f.close()
|
||||
close = function()
|
||||
f.close()
|
||||
end,
|
||||
}
|
||||
elseif flags == 'w' or flags == 'a' then
|
||||
if not matchesFilter(fs.combine(fname, '')) then
|
||||
return native.open(fname, flags)
|
||||
end
|
||||
}
|
||||
elseif flags == 'w' or flags == 'a' then
|
||||
if not matchesFilter(fs.combine(fname, '')) then
|
||||
return native.open(fname, flags)
|
||||
end
|
||||
|
||||
local c = { }
|
||||
local c = { }
|
||||
|
||||
if flags == 'a' then
|
||||
local f = fs.open(fname, 'r')
|
||||
if f then
|
||||
tinsert(c, f.readAll())
|
||||
f.close()
|
||||
end
|
||||
end
|
||||
if flags == 'a' then
|
||||
local f = fs.open(fname, 'r')
|
||||
if f then
|
||||
tinsert(c, f.readAll())
|
||||
f.close()
|
||||
end
|
||||
end
|
||||
|
||||
local f, err = native.open(fname, 'wb')
|
||||
if not f then
|
||||
return f, err
|
||||
end
|
||||
local f, err = native.open(fname, 'wb')
|
||||
if not f then
|
||||
return f, err
|
||||
end
|
||||
|
||||
return {
|
||||
write = function(str)
|
||||
tinsert(c, str)
|
||||
return {
|
||||
write = function(str)
|
||||
tinsert(c, str)
|
||||
end,
|
||||
writeLine = function(str)
|
||||
tinsert(c, str)
|
||||
tinsert(c, '\n')
|
||||
tinsert(c, str)
|
||||
tinsert(c, '\n')
|
||||
end,
|
||||
flush = function()
|
||||
-- this isn't gonna work...
|
||||
-- f.write(compress(tconcat(c)))
|
||||
f.flush();
|
||||
flush = function()
|
||||
-- this isn't gonna work...
|
||||
-- f.write(compress(tconcat(c)))
|
||||
f.flush();
|
||||
end,
|
||||
close = function()
|
||||
f.write(compress(tconcat(c)))
|
||||
f.close()
|
||||
close = function()
|
||||
f.write(compress(tconcat(c)))
|
||||
f.close()
|
||||
end,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
return native.open(fname, flags)
|
||||
return native.open(fname, flags)
|
||||
end
|
||||
|
||||
function fs.option(category, action, option)
|
||||
if category == 'compression' then
|
||||
if action == 'enabled' then
|
||||
enabled = option
|
||||
elseif action == 'filters' then
|
||||
filters = option
|
||||
end
|
||||
end
|
||||
if category == 'compression' then
|
||||
if action == 'enabled' then
|
||||
enabled = option
|
||||
elseif action == 'filters' then
|
||||
filters = option
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
print('lzwfs started')
|
||||
|
||||
@@ -6,11 +6,11 @@ local CONFIG = 'usr/config/lzwfs'
|
||||
local config = { }
|
||||
|
||||
if fs.exists(CONFIG) then
|
||||
local f = fs.open(CONFIG, 'r')
|
||||
local f = fs.open(CONFIG, 'r')
|
||||
if f then
|
||||
config = textutils.unserialize(f.readAll())
|
||||
f.close()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
os.run(_ENV, '/packages/lzwfs/lzwfs.lua')
|
||||
|
||||
@@ -14,7 +14,7 @@ local config = Config.load('lzwfs', {
|
||||
})
|
||||
|
||||
local tab = UI.Tab {
|
||||
title = 'Compression',
|
||||
tabTitle = 'Compression',
|
||||
description = 'Disk compression',
|
||||
[1] = UI.Window {
|
||||
x = 2, y = 2, ex = -2, ey = 6,
|
||||
@@ -29,6 +29,7 @@ local tab = UI.Tab {
|
||||
},
|
||||
entry = UI.TextEntry {
|
||||
x = 3, y = 5 , ex = -3,
|
||||
limit = 256,
|
||||
shadowText = 'enter new path',
|
||||
accelerators = {
|
||||
enter = 'add_path',
|
||||
|
||||
11
mbs/.package
11
mbs/.package
@@ -8,4 +8,15 @@ https://github.com/SquidDev-CC/mbs
|
||||
MBS is a series of utilities for improving the default CraftOS experience.
|
||||
]],
|
||||
license = 'MIT',
|
||||
install = [[
|
||||
local Alt = require('opus.alternate')
|
||||
Alt.set('shell', '.mbs/bin/shell.lua')
|
||||
Alt.add('lua', '.mbs/bin/lua.lua')
|
||||
]],
|
||||
uninstall = [[
|
||||
local Alt = require('opus.alternate')
|
||||
Alt.remove('shell', '.mbs/bin/shell.lua')
|
||||
Alt.remove('lua', '.mbs/bin/lua.lua')
|
||||
fs.delete('.mbs')
|
||||
]],
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ local shell = _ENV.shell
|
||||
|
||||
if not fs.exists('.mbs') then
|
||||
print('Installing MBS')
|
||||
--shell.run('mbs download')
|
||||
shell.run('mbs download')
|
||||
end
|
||||
print('Initializing MBS')
|
||||
--shell.run('mbs startup')
|
||||
shell.run('mbs startup')
|
||||
|
||||
@@ -219,9 +219,7 @@ local s, m = pcall(function()
|
||||
UI:start()
|
||||
end)
|
||||
|
||||
if turtle.setStatus then
|
||||
turtle.setStatus('idle')
|
||||
end
|
||||
turtle.setStatus('idle')
|
||||
|
||||
_G._syslog = oldDebug
|
||||
if not s then error(m) end
|
||||
|
||||
@@ -12,12 +12,8 @@ local fs = _G.fs
|
||||
local peripheral = _G.peripheral
|
||||
local shell = _ENV.shell
|
||||
|
||||
local configName = ({...})[1]
|
||||
local configPath = 'miloRemote' .. (configName and "_"..configName or "")
|
||||
|
||||
local context = {
|
||||
state = Config.load(configPath, { displayMode = 0, deposit = true }),
|
||||
configPath = configPath,
|
||||
state = Config.load('miloRemote', { displayMode = 0, deposit = true }),
|
||||
responseHandlers = { },
|
||||
}
|
||||
|
||||
@@ -162,7 +158,7 @@ function page.grid:eventHandler(event)
|
||||
if event.type == 'grid_sort' then
|
||||
context.state.sortColumn = event.sortColumn
|
||||
context.state.inverseSort = event.inverseSort
|
||||
Config.update(configPath, context.state)
|
||||
Config.update('miloRemote', context.state)
|
||||
end
|
||||
return UI.Grid.eventHandler(self, event)
|
||||
end
|
||||
@@ -185,7 +181,7 @@ function page:eventHandler(event)
|
||||
self.statusBar:draw()
|
||||
context:setStatus(depositMode[context.state.deposit].help)
|
||||
context:notifyInfo(depositMode[context.state.deposit].help)
|
||||
Config.update(configPath, context.state)
|
||||
Config.update('miloRemote', context.state)
|
||||
|
||||
elseif event.type == 'focus_change' then
|
||||
context:setStatus(event.focused.help)
|
||||
@@ -247,7 +243,7 @@ function page:eventHandler(event)
|
||||
context:setStatus(event.button.help)
|
||||
context:notifyInfo(event.button.help)
|
||||
self.grid:draw()
|
||||
Config.update(configPath, context.state)
|
||||
Config.update('miloRemote', context.state)
|
||||
|
||||
elseif event.type == 'text_change' and event.element == self.statusBar.filter then
|
||||
self.filter = event.text or ''
|
||||
@@ -322,7 +318,7 @@ function page:applyFilter()
|
||||
v.score = fuzzy(v.lname, filter)
|
||||
if v.score then
|
||||
if v.count > 0 then
|
||||
v.score = v.score + .2
|
||||
v.score = v.score + 1
|
||||
end
|
||||
table.insert(r, v)
|
||||
end
|
||||
@@ -449,7 +445,7 @@ end
|
||||
|
||||
function context:setState(key, value)
|
||||
self.state[key] = value
|
||||
Config.update(configPath, self.state)
|
||||
Config.update('miloRemote', self.state)
|
||||
end
|
||||
|
||||
context.responseHandlers['received'] = function(response)
|
||||
|
||||
@@ -9,8 +9,6 @@ local device = _G.device
|
||||
local os = _G.os
|
||||
local parallel = _G.parallel
|
||||
|
||||
local SCAN_CHUNK_SIZE = 16
|
||||
|
||||
local Storage = class()
|
||||
|
||||
local function loadOld(storage)
|
||||
@@ -265,22 +263,7 @@ function Storage:listItems(throttle)
|
||||
end
|
||||
|
||||
if #t > 0 then
|
||||
local chunk = {}
|
||||
|
||||
-- Split the work into chunks to avoid spamming too many coroutines.
|
||||
for i = 1, #t do
|
||||
table.insert(chunk, t[i])
|
||||
|
||||
-- When we reach the chunk limit, execute them and start a new chunk
|
||||
if #chunk >= SCAN_CHUNK_SIZE then
|
||||
parallel.waitForAll(table.unpack(chunk))
|
||||
chunk = {}
|
||||
end
|
||||
end
|
||||
|
||||
if #chunk > 0 then
|
||||
parallel.waitForAll(table.unpack(chunk))
|
||||
end
|
||||
parallel.waitForAll(table.unpack(t))
|
||||
end
|
||||
|
||||
for _, adapter in self:onlineAdapters() do
|
||||
@@ -308,134 +291,6 @@ function Storage:listItems(throttle)
|
||||
return self.cache
|
||||
end
|
||||
|
||||
-- provide a raw list of all the items in all storage chests
|
||||
-- it might be beneficial to move this to the adapter class at some point and cache the raw item list in this class at some point
|
||||
function Storage:listItemsRaw(throttle)
|
||||
local res = {}
|
||||
|
||||
throttle = throttle or Util.throttle()
|
||||
|
||||
for _, v in pairs(self.nodes) do
|
||||
if v.category == "storage" then
|
||||
local chest = device[v.name]
|
||||
local items = chest.list()
|
||||
|
||||
for slot, item in pairs(items) do
|
||||
items[slot] = itemDB:get(item, function() return chest.getItemMeta(slot) end)
|
||||
end
|
||||
|
||||
res[v.name] = items
|
||||
throttle()
|
||||
end
|
||||
end
|
||||
|
||||
return res
|
||||
end
|
||||
|
||||
-- provide a list of items and which chests provide them
|
||||
function Storage:listProviders(throttle)
|
||||
local res = {}
|
||||
|
||||
local rawItems = self:listItemsRaw(throttle)
|
||||
|
||||
for chest, items in pairs(rawItems) do
|
||||
for slot, item in pairs(items) do
|
||||
local key = table.concat({item.name, item.damage, item.nbtHash}, ":")
|
||||
if not res[key] then
|
||||
res[key] = {}
|
||||
end
|
||||
table.insert(res[key], {item = item, device = device[chest], lockedToThis = (self.nodes[chest].lock or {})[key] or false, slot = slot})
|
||||
end
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
-- defrags the storage system
|
||||
function Storage:defrag(throttle)
|
||||
local items = self:listProviders(throttle)
|
||||
local slotsSaved = 0
|
||||
|
||||
-- This will make sure the table is sorted in the following order:
|
||||
-- Unlocked stacks with less than maxCount items | Locked stacks with less than maxCount items | stacks with more than maxCount items
|
||||
-- This way the locked stacks will be filled first
|
||||
local function sortFunction(a, b)
|
||||
local preferenceA, preferenceB
|
||||
preferenceA = (a.item.count == a.item.maxCount and 3)
|
||||
or (a.lockedToThis and 2)
|
||||
or 1
|
||||
preferenceB = (b.item.count == b.item.maxCount and 3)
|
||||
or (b.lockedToThis and 2)
|
||||
or 1
|
||||
|
||||
if preferenceA < preferenceB then
|
||||
return true
|
||||
elseif preferenceB > preferenceA then
|
||||
return false
|
||||
else
|
||||
return a.item.count < b.item.count
|
||||
end
|
||||
end
|
||||
|
||||
for _, providers in pairs(items) do
|
||||
table.sort(providers, sortFunction)
|
||||
|
||||
-- We're done when we either compressed the stacks so far, that there's only one left (#providers == 1)
|
||||
-- Or when we've compressed so far, that the there's only one stack which has a lower count than the maxCount
|
||||
-- Because of the sorting, we know that this will be the stack in providers[1], so we check if providers[2] is at the maxCount
|
||||
while #providers > 1 and providers[2].item.count ~= providers[2].item.maxCount do
|
||||
local from = providers[1]
|
||||
local to
|
||||
|
||||
-- We're pushing to the highest stack which is still below the maxCount, this way as many slots as possible will be filled
|
||||
-- This loop is guarenteed to assign a value to "to", as the only cases where it wouldn't (#providers == 1 or no provider with less than maxCount)
|
||||
-- are ruled out by the condition of the outer while loop
|
||||
for i = 2, #providers do
|
||||
-- Give preference to locked chests
|
||||
if not (to and to.lockedToThis or false) and providers[i].lockedToThis then
|
||||
to = providers[i]
|
||||
elseif ((to and to.lockedToThis or false) == providers[i].lockedToThis) and providers[i].item.count < providers[i].item.maxCount then
|
||||
to = providers[i]
|
||||
elseif providers[i].item.count == providers[i].item.maxCount then
|
||||
-- As this slot is already at maxCount, all the remaining ones will also be due to sorting
|
||||
-- If any of the remaining providers is locked that doesn't matter. We wouldn't have been able to push there anyways
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
local toMove = math.min(to.item.maxCount - to.item.count, from.item.count)
|
||||
local s, m = pcall(function()
|
||||
from.device.pushItems(to.device.name, from.slot, toMove, to.slot)
|
||||
end)
|
||||
|
||||
if not s and m then
|
||||
_G._syslog(m)
|
||||
end
|
||||
|
||||
if s then
|
||||
to.item.count = to.item.count + toMove
|
||||
from.item.count = from.item.count - toMove
|
||||
else
|
||||
-- Do not try to send to the target again after it failed
|
||||
for i = 2, #providers do
|
||||
if to == providers[i] then
|
||||
table.remove(providers, i)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if from.item.count <= 0 then
|
||||
table.remove(providers, 1)
|
||||
slotsSaved = slotsSaved + 1
|
||||
end
|
||||
|
||||
table.sort(providers, sortFunction)
|
||||
end
|
||||
end
|
||||
|
||||
return slotsSaved
|
||||
end
|
||||
|
||||
function Storage:updateCache(adapter, item, count)
|
||||
if not adapter.cache then
|
||||
adapter.dirty = true
|
||||
@@ -537,8 +392,6 @@ local function rawExport(source, target, item, qty, slot)
|
||||
if amount > 0 then
|
||||
source.lastUpdate = os.clock()
|
||||
target.lastUpdate = os.clock()
|
||||
else
|
||||
-- break -- this should work ?? is cache out of sync ?
|
||||
end
|
||||
end
|
||||
qty = qty - amount
|
||||
@@ -570,7 +423,6 @@ function Storage:export(target, slot, count, item)
|
||||
|
||||
if amount ~= pcount then
|
||||
-- this *should* only happen if cache is out of sync
|
||||
-- or... the target is full
|
||||
self:updateCache(adapter, item, pcount - amount)
|
||||
end
|
||||
|
||||
@@ -581,43 +433,28 @@ function Storage:export(target, slot, count, item)
|
||||
end
|
||||
count = count - amount
|
||||
total = total + amount
|
||||
|
||||
return amount
|
||||
end
|
||||
|
||||
-- request from adapters with this item
|
||||
for _, adapter in self:onlineAdapters() do
|
||||
local cache = adapter.cache and adapter.cache[key]
|
||||
if cache then
|
||||
local request = math.min(count, cache.count)
|
||||
|
||||
local amount = provide(adapter, request)
|
||||
|
||||
-- couldn't provide the amount that was requested
|
||||
-- either the target must be full - or the cache is invalid
|
||||
if amount ~= request then
|
||||
break
|
||||
end
|
||||
provide(adapter, math.min(count, cache.count))
|
||||
if count <= 0 then
|
||||
return total
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if slot then -- ignore warning when exporting to all slots
|
||||
_G._syslog('STORAGE warning: %s(%d): %s%s %s failed to export',
|
||||
item.displayName or item.name, count, self:_sn(target.name),
|
||||
slot and string.format('[%d]', slot) or '[*]', key)
|
||||
end
|
||||
_G._syslog('STORAGE warning: %s(%d): %s%s %s failed to export',
|
||||
item.displayName or item.name, count, self:_sn(target.name),
|
||||
slot and string.format('[%d]', slot) or '[*]', key)
|
||||
|
||||
-- TODO: If there are misses when a slot is specified than something is wrong...
|
||||
-- The caller should confirm the quantity beforehand
|
||||
-- If no slot and full amount is not exported, then no need to check rest of adapters
|
||||
-- ... so should not reach here
|
||||
|
||||
-- but... there is the case where exporting to all slots of the target
|
||||
-- this is valid
|
||||
|
||||
return total
|
||||
end
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ fs.delete('packages/milo/Milo.lua')
|
||||
fs.delete('packages/milo/plugins/listing.lua')
|
||||
fs.delete('packages/milo/apis/milo.lua')
|
||||
fs.delete('packages/milo/plugins/manipulator.lua')
|
||||
fs.delete('packages/milo/apps')
|
||||
|
||||
if peripheral.find('workbench') and shell.openForegroundTab then
|
||||
shell.openForegroundTab('MiloLocal')
|
||||
|
||||
@@ -1,29 +1,33 @@
|
||||
local Milo = require('milo')
|
||||
local UI = require('opus.ui')
|
||||
|
||||
local turtle = _G.turtle
|
||||
|
||||
local learnPage = UI.Page {
|
||||
titleBar = UI.TitleBar { title = 'Learn Recipe' },
|
||||
wizard = UI.Wizard {
|
||||
y = 2, ey = -2,
|
||||
general = UI.WizardPage {
|
||||
index = 1,
|
||||
grid = UI.ScrollingGrid {
|
||||
x = 2, ex = -2, y = 2, ey = -2,
|
||||
disableHeader = true,
|
||||
columns = {
|
||||
{ heading = 'Name', key = 'name'},
|
||||
pages = {
|
||||
general = UI.WizardPage {
|
||||
index = 1,
|
||||
grid = UI.ScrollingGrid {
|
||||
x = 2, ex = -2, y = 2, ey = -2,
|
||||
disableHeader = true,
|
||||
columns = {
|
||||
{ heading = 'Name', key = 'name'},
|
||||
},
|
||||
sortColumn = 'name',
|
||||
},
|
||||
accelerators = {
|
||||
grid_select = 'nextView',
|
||||
},
|
||||
sortColumn = 'name',
|
||||
},
|
||||
accelerators = {
|
||||
grid_select = 'nextView',
|
||||
},
|
||||
},
|
||||
},
|
||||
notification = UI.Notification { },
|
||||
}
|
||||
|
||||
local general = learnPage.wizard.general
|
||||
local general = learnPage.wizard.pages.general
|
||||
|
||||
function general:validate()
|
||||
Milo:setState('learnType', self.grid:getSelected().value)
|
||||
@@ -33,7 +37,7 @@ end
|
||||
function learnPage:enable()
|
||||
local t = { }
|
||||
|
||||
for _, page in pairs(self.wizard:getPages()) do
|
||||
for _, page in pairs(self.wizard.pages) do
|
||||
if page.validFor then
|
||||
t[page.validFor] = {
|
||||
name = page.validFor,
|
||||
@@ -59,7 +63,7 @@ function learnPage.wizard:getPage(index)
|
||||
local pages = { }
|
||||
table.insert(pages, general)
|
||||
local selected = general.grid:getSelected()
|
||||
for _, page in pairs(self:getPages()) do
|
||||
for _, page in pairs(self.pages) do
|
||||
if page.validFor and (not selected or selected.value == page.validFor) then
|
||||
table.insert(pages, page)
|
||||
end
|
||||
|
||||
@@ -33,11 +33,6 @@ local page = UI.Page {
|
||||
event = 'rescan',
|
||||
help = 'Rescan all inventories'
|
||||
},
|
||||
{
|
||||
text = 'Defragment storage',
|
||||
event = 'defrag',
|
||||
help = 'Defragments the storage'
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -255,10 +250,6 @@ function page:eventHandler(event)
|
||||
self.grid:draw()
|
||||
self:setFocus(self.statusBar.filter)
|
||||
|
||||
elseif event.type == 'defrag' then
|
||||
self:defrag()
|
||||
self:refresh(true)
|
||||
|
||||
elseif event.type == 'toggle_display' then
|
||||
displayMode = (displayMode + 1) % 2
|
||||
Util.merge(event.button, displayModes[displayMode])
|
||||
@@ -366,15 +357,6 @@ function page:refresh(force)
|
||||
self.throttle:disable()
|
||||
end
|
||||
|
||||
function page:defrag()
|
||||
local throttle = function() self.throttle:update() end
|
||||
|
||||
self.throttle:enable()
|
||||
local saved = context.storage:defrag(throttle)
|
||||
self.throttle:disable()
|
||||
self:notifyInfo(("Saved %d slots"):format(saved))
|
||||
end
|
||||
|
||||
function page:applyFilter()
|
||||
local function filterItems(t, filter)
|
||||
self.grid.sortColumn = Milo:getState('sortColumn') or 'count'
|
||||
@@ -390,7 +372,7 @@ function page:applyFilter()
|
||||
v.score = fuzzy(v.lname, filter)
|
||||
if v.score then
|
||||
if v.count > 0 then
|
||||
v.score = v.score + .2
|
||||
v.score = v.score + 1
|
||||
end
|
||||
table.insert(r, v)
|
||||
end
|
||||
|
||||
@@ -28,43 +28,13 @@ local networkPage = UI.Page {
|
||||
y = 2, ey = -3,
|
||||
values = context.storage.nodes,
|
||||
columns = {
|
||||
{ key = 'suffix', width = 5, align = 'right' },
|
||||
{ key = 'suffix', width = 4, align = 'right' },
|
||||
{ heading = 'Name', key = 'displayName' },
|
||||
{ heading = 'Type', key = 'mtype', width = 4 },
|
||||
{ heading = 'Pri', key = 'priority', width = 3 },
|
||||
},
|
||||
sortColumn = 'displayName',
|
||||
help = 'Select Node',
|
||||
getDisplayValues = function(_, row)
|
||||
row = Util.shallowCopy(row)
|
||||
local t = { row.name:match(':(.+)_(%d+)$') }
|
||||
if #t ~= 2 then
|
||||
t = { row.name:match('(.+)_(%d+)$') }
|
||||
end
|
||||
if t and #t == 2 then
|
||||
row.name, row.suffix = table.unpack(t)
|
||||
row.name = row.name .. '_' .. row.suffix
|
||||
end
|
||||
row.displayName = row.displayName or row.name
|
||||
return row
|
||||
end,
|
||||
getRowTextColor = function(self, row, selected)
|
||||
if not device[row.name] then
|
||||
return colors.red
|
||||
end
|
||||
if row.mtype == 'ignore' then
|
||||
return colors.lightGray
|
||||
end
|
||||
return UI.Grid.getRowTextColor(self, row, selected)
|
||||
end,
|
||||
sortCompare = function(self, a, b)
|
||||
if self.sortColumn == 'displayName' then
|
||||
local an = a.displayName or a.name
|
||||
local bn = b.displayName or b.name
|
||||
return an:lower() < bn:lower()
|
||||
end
|
||||
return UI.Grid.sortCompare(self, a, b)
|
||||
end,
|
||||
},
|
||||
remove = UI.Button {
|
||||
y = -2, x = -4,
|
||||
@@ -85,6 +55,39 @@ local networkPage = UI.Page {
|
||||
}
|
||||
}
|
||||
|
||||
function networkPage.grid:getDisplayValues(row)
|
||||
row = Util.shallowCopy(row)
|
||||
local t = { row.name:match(':(.+)_(%d+)$') }
|
||||
if #t ~= 2 then
|
||||
t = { row.name:match('(.+)_(%d+)$') }
|
||||
end
|
||||
if t and #t == 2 then
|
||||
row.name, row.suffix = table.unpack(t)
|
||||
row.name = row.name .. '_' .. row.suffix
|
||||
end
|
||||
row.displayName = row.displayName or row.name
|
||||
return row
|
||||
end
|
||||
|
||||
function networkPage.grid:getRowTextColor(row, selected)
|
||||
if not device[row.name] then
|
||||
return colors.red
|
||||
end
|
||||
if row.mtype == 'ignore' then
|
||||
return colors.lightGray
|
||||
end
|
||||
return UI.Grid:getRowTextColor(row, selected)
|
||||
end
|
||||
|
||||
function networkPage.grid:sortCompare(a, b)
|
||||
if self.sortColumn == 'displayName' then
|
||||
local an = a.displayName or a.name
|
||||
local bn = b.displayName or b.name
|
||||
return an:lower() < bn:lower()
|
||||
end
|
||||
return UI.Grid.sortCompare(self, a, b)
|
||||
end
|
||||
|
||||
function networkPage:getList()
|
||||
for _, v in pairs(device) do
|
||||
if not context.storage.nodes[v.name] then
|
||||
@@ -93,7 +96,7 @@ function networkPage:getList()
|
||||
mtype = 'ignore',
|
||||
category = 'ignore',
|
||||
}
|
||||
for _, page in pairs(nodeWizard.wizard:getPages()) do
|
||||
for _, page in pairs(nodeWizard.wizard.pages) do
|
||||
if page.isValidType and page:isValidType(node) then
|
||||
context.storage.nodes[v.name] = node
|
||||
break
|
||||
@@ -188,91 +191,46 @@ nodeWizard = UI.Page {
|
||||
titleBar = UI.TitleBar { title = 'Configure' },
|
||||
wizard = UI.Wizard {
|
||||
y = 2, ey = -2,
|
||||
general = UI.WizardPage {
|
||||
index = 1,
|
||||
form = UI.Form {
|
||||
x = 2, ex = -2, y = 1, ey = 3,
|
||||
manualControls = true,
|
||||
[1] = UI.TextEntry {
|
||||
formLabel = 'Name', formKey = 'displayName',
|
||||
help = 'Set a friendly name',
|
||||
limit = 64,
|
||||
pages = {
|
||||
general = UI.WizardPage {
|
||||
index = 1,
|
||||
form = UI.Form {
|
||||
x = 2, ex = -2, y = 1, ey = 3,
|
||||
manualControls = true,
|
||||
[1] = UI.TextEntry {
|
||||
formLabel = 'Name', formKey = 'displayName',
|
||||
help = 'Set a friendly name',
|
||||
limit = 64,
|
||||
},
|
||||
[2] = UI.Chooser {
|
||||
width = 25,
|
||||
formLabel = 'Type', formKey = 'mtype',
|
||||
--nochoice = 'Storage',
|
||||
help = 'Select type',
|
||||
},
|
||||
},
|
||||
[2] = UI.Chooser {
|
||||
width = 25,
|
||||
formLabel = 'Type', formKey = 'mtype',
|
||||
--nochoice = 'Storage',
|
||||
help = 'Select type',
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 5, ey = -2, x = 2, ex = -2,
|
||||
columns = {
|
||||
{ heading = 'Slot', key = 'slot', width = 4 },
|
||||
{ heading = 'Name', key = 'displayName', },
|
||||
{ heading = 'Qty', key = 'count' , width = 3 },
|
||||
},
|
||||
sortColumn = 'slot',
|
||||
help = 'Contents of inventory',
|
||||
},
|
||||
},
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 5, ey = -2, x = 2, ex = -2,
|
||||
columns = {
|
||||
{ heading = 'Slot', key = 'slot', width = 4 },
|
||||
{ heading = 'Name', key = 'displayName', },
|
||||
{ heading = 'Qty', key = 'count' , width = 3 },
|
||||
},
|
||||
sortColumn = 'slot',
|
||||
help = 'Contents of inventory',
|
||||
getDisplayValues = function(_, row)
|
||||
row = Util.shallowCopy(row)
|
||||
row.displayName = itemDB:getName(row)
|
||||
return row
|
||||
end,
|
||||
},
|
||||
enable = function(self)
|
||||
UI.WizardPage.enable(self)
|
||||
self:focusFirst()
|
||||
end,
|
||||
isValidFor = function()
|
||||
return false
|
||||
end,
|
||||
showInventory = function(self, node)
|
||||
local inventory
|
||||
|
||||
if device[node.name] and device[node.name].list then
|
||||
pcall(function()
|
||||
inventory = device[node.name].list()
|
||||
for k,v in pairs(inventory) do
|
||||
v.slot = k
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
self.grid:setValues(inventory or { })
|
||||
end,
|
||||
validate = function(self)
|
||||
if self.form:save() then
|
||||
nodeWizard.node.category = Util.find(nodeWizard.choices, 'value', nodeWizard.node.mtype).category
|
||||
|
||||
nodeWizard.nodePages = { }
|
||||
table.insert(nodeWizard.nodePages, nodeWizard.wizard.general)
|
||||
for _, page in pairs(nodeWizard.wizard:getPages()) do
|
||||
if not page.isValidFor or page:isValidFor(nodeWizard.node) then
|
||||
table.insert(nodeWizard.nodePages, page)
|
||||
if page.setNode then
|
||||
page:setNode(nodeWizard.node)
|
||||
end
|
||||
end
|
||||
end
|
||||
table.insert(nodeWizard.nodePages, nodeWizard.wizard.confirmation)
|
||||
return true
|
||||
end
|
||||
end,
|
||||
},
|
||||
confirmation = UI.WizardPage {
|
||||
title = 'Confirm changes',
|
||||
index = 2,
|
||||
notice = UI.TextArea {
|
||||
x = 2, ex = -2, y = 2, ey = -2,
|
||||
value =
|
||||
confirmation = UI.WizardPage {
|
||||
title = 'Confirm changes',
|
||||
index = 2,
|
||||
notice = UI.TextArea {
|
||||
x = 2, ex = -2, y = 2, ey = -2,
|
||||
value =
|
||||
[[Press accept to save the changes.
|
||||
|
||||
The settings will take effect immediately!]],
|
||||
},
|
||||
},
|
||||
isValidFor = function()
|
||||
return false
|
||||
end,
|
||||
},
|
||||
},
|
||||
statusBar = UI.StatusBar {
|
||||
@@ -297,11 +255,6 @@ The settings will take effect immediately!]],
|
||||
accelerators = {
|
||||
delete = 'remove_entry',
|
||||
},
|
||||
getDisplayValues = function(_, row)
|
||||
row = Util.shallowCopy(row)
|
||||
row.displayName = itemDB:getName(row)
|
||||
return row
|
||||
end,
|
||||
},
|
||||
remove = UI.Button {
|
||||
x = -4, y = 4,
|
||||
@@ -338,76 +291,143 @@ The settings will take effect immediately!]],
|
||||
statusBar = UI.StatusBar {
|
||||
backgroundColor = 'primary',
|
||||
},
|
||||
show = function(self, entry, callback, whitelistOnly)
|
||||
self.entry = entry
|
||||
self.callback = callback
|
||||
|
||||
if not self.entry.filter then
|
||||
self.entry.filter = { }
|
||||
end
|
||||
|
||||
self.form:setValues(entry)
|
||||
self:resetGrid()
|
||||
|
||||
self.form[3].inactive = whitelistOnly
|
||||
|
||||
UI.SlideOut.show(self)
|
||||
self:setFocus(self.form.scan)
|
||||
|
||||
Milo:pauseCrafting({ key = 'gridInUse', msg = 'Crafting paused' })
|
||||
end,
|
||||
hide = function(self)
|
||||
UI.SlideOut.hide(self)
|
||||
Milo:resumeCrafting({ key = 'gridInUse' })
|
||||
end,
|
||||
resetGrid = function(self)
|
||||
local t = { }
|
||||
for k in pairs(self.entry.filter) do
|
||||
table.insert(t, itemDB:splitKey(k))
|
||||
end
|
||||
self.grid:setValues(t)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'focus_change' then
|
||||
self.statusBar:setStatus(event.focused.help)
|
||||
|
||||
elseif event.type == 'scan_turtle' then
|
||||
local inventory = Milo:getTurtleInventory()
|
||||
for _,item in pairs(inventory) do
|
||||
self.entry.filter[itemDB:makeKey(item)] = true
|
||||
end
|
||||
self:resetGrid()
|
||||
self.grid:update()
|
||||
self.grid:draw()
|
||||
Milo:emptyInventory()
|
||||
|
||||
elseif event.type == 'remove_entry' then
|
||||
local row = self.grid:getSelected()
|
||||
if row then
|
||||
Util.removeByValue(self.grid.values, row)
|
||||
self.grid:update()
|
||||
self.grid:draw()
|
||||
end
|
||||
|
||||
elseif event.type == 'save' then
|
||||
self.form:save()
|
||||
self.entry.filter = { }
|
||||
for _,v in pairs(self.grid.values) do
|
||||
self.entry.filter[itemDB:makeKey(v)] = true
|
||||
end
|
||||
self:hide()
|
||||
self.callback()
|
||||
|
||||
elseif event.type == 'cancel' then
|
||||
self:hide()
|
||||
else
|
||||
return UI.SlideOut.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
--[[ Filter slide out ]] --
|
||||
function nodeWizard.filter:show(entry, callback, whitelistOnly)
|
||||
self.entry = entry
|
||||
self.callback = callback
|
||||
|
||||
if not self.entry.filter then
|
||||
self.entry.filter = { }
|
||||
end
|
||||
|
||||
self.form:setValues(entry)
|
||||
self:resetGrid()
|
||||
|
||||
self.form[3].inactive = whitelistOnly
|
||||
|
||||
UI.SlideOut.show(self)
|
||||
self:setFocus(self.form.scan)
|
||||
|
||||
Milo:pauseCrafting({ key = 'gridInUse', msg = 'Crafting paused' })
|
||||
end
|
||||
|
||||
function nodeWizard.filter:hide()
|
||||
UI.SlideOut.hide(self)
|
||||
Milo:resumeCrafting({ key = 'gridInUse' })
|
||||
end
|
||||
|
||||
function nodeWizard.filter:resetGrid()
|
||||
local t = { }
|
||||
for k in pairs(self.entry.filter) do
|
||||
table.insert(t, itemDB:splitKey(k))
|
||||
end
|
||||
self.grid:setValues(t)
|
||||
end
|
||||
|
||||
function nodeWizard.filter.grid:getDisplayValues(row)
|
||||
row = Util.shallowCopy(row)
|
||||
row.displayName = itemDB:getName(row)
|
||||
return row
|
||||
end
|
||||
|
||||
function nodeWizard.filter:eventHandler(event)
|
||||
if event.type == 'focus_change' then
|
||||
self.statusBar:setStatus(event.focused.help)
|
||||
|
||||
elseif event.type == 'scan_turtle' then
|
||||
local inventory = Milo:getTurtleInventory()
|
||||
for _,item in pairs(inventory) do
|
||||
self.entry.filter[itemDB:makeKey(item)] = true
|
||||
end
|
||||
self:resetGrid()
|
||||
self.grid:update()
|
||||
self.grid:draw()
|
||||
Milo:emptyInventory()
|
||||
|
||||
elseif event.type == 'remove_entry' then
|
||||
local row = self.grid:getSelected()
|
||||
if row then
|
||||
Util.removeByValue(self.grid.values, row)
|
||||
self.grid:update()
|
||||
self.grid:draw()
|
||||
end
|
||||
|
||||
elseif event.type == 'save' then
|
||||
self.form:save()
|
||||
self.entry.filter = { }
|
||||
for _,v in pairs(self.grid.values) do
|
||||
self.entry.filter[itemDB:makeKey(v)] = true
|
||||
end
|
||||
self:hide()
|
||||
self.callback()
|
||||
|
||||
elseif event.type == 'cancel' then
|
||||
self:hide()
|
||||
|
||||
else
|
||||
return UI.SlideOut.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
--[[ General Page ]] --
|
||||
function nodeWizard.wizard.pages.general:enable()
|
||||
UI.WizardPage.enable(self)
|
||||
self:focusFirst()
|
||||
end
|
||||
|
||||
function nodeWizard.wizard.pages.general:isValidFor()
|
||||
return false
|
||||
end
|
||||
|
||||
function nodeWizard.wizard.pages.general:showInventory(node)
|
||||
local inventory
|
||||
|
||||
if device[node.name] and device[node.name].list then
|
||||
pcall(function()
|
||||
inventory = device[node.name].list()
|
||||
for k,v in pairs(inventory) do
|
||||
v.slot = k
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
self.grid:setValues(inventory or { })
|
||||
end
|
||||
|
||||
function nodeWizard.wizard.pages.general.grid:getDisplayValues(row)
|
||||
row = Util.shallowCopy(row)
|
||||
row.displayName = itemDB:getName(row)
|
||||
return row
|
||||
end
|
||||
|
||||
function nodeWizard.wizard.pages.general:validate()
|
||||
if self.form:save() then
|
||||
nodeWizard.node.category = Util.find(nodeWizard.choices, 'value', nodeWizard.node.mtype).category
|
||||
|
||||
nodeWizard.nodePages = { }
|
||||
table.insert(nodeWizard.nodePages, nodeWizard.wizard.pages.general)
|
||||
for _, page in pairs(nodeWizard.wizard.pages) do
|
||||
if not page.isValidFor or page:isValidFor(nodeWizard.node) then
|
||||
table.insert(nodeWizard.nodePages, page)
|
||||
if page.setNode then
|
||||
page:setNode(nodeWizard.node)
|
||||
end
|
||||
end
|
||||
end
|
||||
table.insert(nodeWizard.nodePages, nodeWizard.wizard.pages.confirmation)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
--[[ Confirmation ]]--
|
||||
function nodeWizard.wizard.pages.confirmation:isValidFor()
|
||||
return false
|
||||
end
|
||||
|
||||
--[[ Wizard ]] --
|
||||
function nodeWizard:enable(node)
|
||||
local adapter = node.adapter
|
||||
@@ -420,7 +440,7 @@ function nodeWizard:enable(node)
|
||||
{ name = 'Ignore', value = 'ignore', category = 'ignore' },
|
||||
{ name = 'Hidden', value = 'hidden', category = 'ignore', help = 'Do not show in list' },
|
||||
}
|
||||
for _, page in pairs(self.wizard:getPages()) do
|
||||
for _, page in pairs(self.wizard.pages) do
|
||||
if page.isValidType then
|
||||
local choice = page:isValidType(self.node)
|
||||
if choice and not Util.find(self.choices, 'value', choice.value) then
|
||||
@@ -428,15 +448,15 @@ function nodeWizard:enable(node)
|
||||
end
|
||||
end
|
||||
end
|
||||
self.wizard.general.form[1].shadowText = self.node.name
|
||||
self.wizard.general.form[2].choices = self.choices
|
||||
self.wizard.general.form:setValues(self.node)
|
||||
self.wizard.pages.general.form[1].shadowText = self.node.name
|
||||
self.wizard.pages.general.form[2].choices = self.choices
|
||||
self.wizard.pages.general.form:setValues(self.node)
|
||||
|
||||
self.wizard.general:showInventory(self.node)
|
||||
self.wizard.pages.general:showInventory(self.node)
|
||||
|
||||
self.nodePages = { }
|
||||
table.insert(self.nodePages, self.wizard.general)
|
||||
table.insert(self.nodePages, self.wizard.confirmation)
|
||||
table.insert(self.nodePages, self.wizard.pages.general)
|
||||
table.insert(self.nodePages, self.wizard.pages.confirmation)
|
||||
|
||||
UI.Page.enable(self)
|
||||
end
|
||||
|
||||
@@ -18,9 +18,6 @@ function ExportTask:cycle(context)
|
||||
|
||||
for node in context.storage:filterActive('machine', filter) do
|
||||
tasks:add(function()
|
||||
|
||||
local slots
|
||||
|
||||
for _, entry in pairs(node.exports) do
|
||||
|
||||
if not entry.filter then
|
||||
@@ -69,36 +66,13 @@ function ExportTask:cycle(context)
|
||||
end
|
||||
|
||||
local function exportItems()
|
||||
local function canExport(item)
|
||||
if not node.adapter.__size then
|
||||
node.adapter.__size = node.adapter.size()
|
||||
end
|
||||
|
||||
if not slots then
|
||||
slots = node.adapter.list()
|
||||
end
|
||||
|
||||
for i = 1, node.adapter.__size do
|
||||
local slot = slots[i]
|
||||
if (not slot or slot.name == item.name and
|
||||
(entry.ignoreDamage or slot.damage == item.damage) and
|
||||
(entry.ignoreNbtHash or slot.nbtHash == item.nbtHash) and
|
||||
slot.count < item.maxCount) then
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for key in pairs(entry.filter) do
|
||||
local items = Milo:getMatches(itemDB:splitKey(key), entry)
|
||||
for _,item in pairs(items) do
|
||||
if canExport(item) then
|
||||
if context.storage:export(node, nil, item.count, item) == 0 then
|
||||
break
|
||||
end
|
||||
-- refresh the slots
|
||||
slots = nil
|
||||
if context.storage:export(node, nil, item.count, item) == 0 then
|
||||
-- TODO: really shouldn't break here as there may be room in other slots
|
||||
-- leaving for now for performance reasons
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@ local Ansi = require('opus.ansi')
|
||||
local UI = require('opus.ui')
|
||||
|
||||
local infoTab = UI.Tab {
|
||||
title = 'Info',
|
||||
tabTitle = 'Info',
|
||||
index = 4,
|
||||
textArea = UI.TextArea {
|
||||
x = 2, ex = -2, y = 2, ey = -2,
|
||||
|
||||
@@ -7,7 +7,7 @@ local colors = _G.colors
|
||||
local context = Milo:getContext()
|
||||
|
||||
local machinesTab = UI.Tab {
|
||||
title = 'Machine',
|
||||
tabTitle = 'Machine',
|
||||
index = 3,
|
||||
grid = UI.ScrollingGrid {
|
||||
x = 2, ex = -2, y = 2, ey = -2,
|
||||
|
||||
@@ -7,7 +7,7 @@ local Util = require('opus.util')
|
||||
local context = Milo:getContext()
|
||||
|
||||
local manageTab = UI.Tab {
|
||||
title = 'Manage',
|
||||
tabTitle = 'Manage',
|
||||
index = 1,
|
||||
form = UI.Form {
|
||||
x = 1, ex = -1, ey = -1,
|
||||
|
||||
@@ -4,7 +4,7 @@ local Milo = require('milo')
|
||||
local UI = require('opus.ui')
|
||||
|
||||
local recipeTab = UI.Tab {
|
||||
title = 'Recipe',
|
||||
tabTitle = 'Recipe',
|
||||
index = 2,
|
||||
grid = UI.ScrollingGrid {
|
||||
x = 2, ex = -2, y = 2, ey = -4,
|
||||
|
||||
@@ -7,7 +7,7 @@ local colors = _G.colors
|
||||
local context = Milo:getContext()
|
||||
|
||||
local resetTab = UI.Tab {
|
||||
title = 'Reset',
|
||||
tabTitle = 'Reset',
|
||||
index = 5,
|
||||
noFill = true,
|
||||
textArea = UI.TextArea {
|
||||
|
||||
@@ -156,7 +156,6 @@ local function createPage(node)
|
||||
if row.requested then
|
||||
row.remaining = math.max(0, row.requested - row.crafted)
|
||||
--_syslog('%d %d %d %d', row.remaining, row.requested, row.total, row.crafted)
|
||||
row.total = row.total or 0
|
||||
row.status = (row.status or '') ..
|
||||
string.format(' %d of %d', row.crafted + row.total, row.total + row.requested)
|
||||
else
|
||||
|
||||
@@ -23,7 +23,7 @@ local page = UI.Page {
|
||||
tabs = UI.Tabs {
|
||||
y = 2, ey = -2,
|
||||
inventory = UI.Tab {
|
||||
title = 'Inventory',
|
||||
tabTitle = 'Inventory',
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2, ey = -2,
|
||||
columns = {
|
||||
@@ -33,7 +33,7 @@ local page = UI.Page {
|
||||
},
|
||||
},
|
||||
autostore = UI.Tab {
|
||||
title = 'Deposit',
|
||||
tabTitle = 'Deposit',
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2, ey = -2,
|
||||
columns = {
|
||||
|
||||
@@ -5,9 +5,9 @@ local Util = require('opus.util')
|
||||
local colors = _G.colors
|
||||
local fs = _G.fs
|
||||
|
||||
local context = ({ ... })[1]
|
||||
local STARTUP_FILE = 'usr/autorun/miloRemote.lua'
|
||||
|
||||
local STARTUP_FILE = 'usr/autorun/'..context.configPath..'.lua'
|
||||
local context = ({ ... })[1]
|
||||
|
||||
local setup = UI.SlideOut {
|
||||
titleBar = UI.TitleBar {
|
||||
@@ -59,7 +59,7 @@ function setup:eventHandler(event)
|
||||
self.statusBar:setStatus(event.focused.help)
|
||||
|
||||
elseif event.type == 'form_complete' then
|
||||
Config.update(context.configPath, context.state)
|
||||
Config.update('miloRemote', context.state)
|
||||
self:hide()
|
||||
context.page:refresh('list')
|
||||
context.page.grid:draw()
|
||||
|
||||
@@ -83,7 +83,7 @@ local function createPage(node)
|
||||
parent = monitor,
|
||||
tabs = UI.Tabs {
|
||||
[1] = UI.Tab {
|
||||
title = 'Overview',
|
||||
tabTitle = 'Overview',
|
||||
backgroundColor = colors.black,
|
||||
noFill = true,
|
||||
onlineLabel = UI.Text {
|
||||
@@ -135,14 +135,14 @@ local function createPage(node)
|
||||
},
|
||||
},
|
||||
[2] = UI.Tab {
|
||||
title = 'Stats',
|
||||
tabTitle = 'Stats',
|
||||
noFill = true,
|
||||
textArea = UI.TextArea {
|
||||
y = 3,
|
||||
},
|
||||
},
|
||||
[3] = UI.Tab {
|
||||
title = 'Storage',
|
||||
tabTitle = 'Storage',
|
||||
noFill = true,
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2,
|
||||
@@ -151,13 +151,13 @@ local function createPage(node)
|
||||
{ heading = 'Size', key = 'size', width = 5 },
|
||||
{ heading = 'Used', key = 'used', width = 5 },
|
||||
{ heading = 'Perc', key = 'perc', width = 5 },
|
||||
|
||||
-- TODO: add % to each number
|
||||
},
|
||||
sortColumn = 'name',
|
||||
},
|
||||
},
|
||||
[4] = UI.Tab {
|
||||
title = 'Offline',
|
||||
tabTitle = 'Offline',
|
||||
noFill = true,
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2,
|
||||
@@ -168,14 +168,14 @@ local function createPage(node)
|
||||
},
|
||||
},
|
||||
[5] = UI.Tab {
|
||||
title = 'Activity',
|
||||
tabTitle = 'Activity',
|
||||
noFill = true,
|
||||
term = UI.Embedded {
|
||||
--visible = true,
|
||||
},
|
||||
},
|
||||
[6] = UI.Tab {
|
||||
title = 'Tasks',
|
||||
tabTitle = 'Tasks',
|
||||
noFill = true,
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2,
|
||||
@@ -224,7 +224,7 @@ local function createPage(node)
|
||||
name = n.displayName or n.name,
|
||||
size = n.adapter.__size,
|
||||
used = n.adapter.__used,
|
||||
perc = tostring(math.floor(n.adapter.__used / n.adapter.__size * 100)) .. "%",
|
||||
perc = math.floor(n.adapter.__used / n.adapter.__size * 100),
|
||||
updated = updated,
|
||||
})
|
||||
totals.usedSlots = totals.usedSlots + n.adapter.__used
|
||||
@@ -449,7 +449,7 @@ Unlocked Slots : %d of %d (%d%%)
|
||||
function page:eventHandler(event)
|
||||
if event.type == 'tab_activate' then
|
||||
local state = Milo:getState('statusState') or { }
|
||||
state[node.name] = event.activated.title
|
||||
state[node.name] = event.activated.tabTitle
|
||||
Milo:setState('statusState', state)
|
||||
end
|
||||
return UI.Page.eventHandler(self, event)
|
||||
@@ -472,7 +472,7 @@ Unlocked Slots : %d of %d (%d%%)
|
||||
-- restore active tab
|
||||
local tabState = Milo:getState('statusState') or { }
|
||||
if tabState[node.name] then
|
||||
page.tabs:selectTab(Util.find(page.tabs, 'title', tabState[node.name]))
|
||||
page.tabs:selectTab(Util.find(page.tabs, 'tabTitle', tabState[node.name]))
|
||||
end
|
||||
|
||||
return page
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
local UI = require('opus.ui')
|
||||
local Util = require('opus.util')
|
||||
local Peripheral = require('opus.peripheral')
|
||||
|
||||
local defaultStoragePath = "/usr/config/storage"
|
||||
|
||||
local page = UI.Page {
|
||||
notification = UI.Notification {},
|
||||
|
||||
infoText = UI.TextArea {
|
||||
x = 2, y = 2,
|
||||
height = 2,
|
||||
textColor = colors.yellow,
|
||||
value = "Select storage types to merge into your Milo storage config.",
|
||||
},
|
||||
|
||||
typeGrid = UI.CheckboxGrid {
|
||||
x = 2, y = 4,
|
||||
ex = -2, ey = -4,
|
||||
sortColumn = "amount",
|
||||
inverseSort = true,
|
||||
columns = {
|
||||
{heading = 'Type', key = 'type'},
|
||||
{heading = 'Amount', key = 'amount', align = 'right', width = 6},
|
||||
},
|
||||
},
|
||||
|
||||
rescanButton = UI.Button {
|
||||
x = 2, y = -2,
|
||||
text = 'Rescan',
|
||||
event = 'rescan',
|
||||
},
|
||||
|
||||
doneButton = UI.Button {
|
||||
x = -7, y = -2,
|
||||
text = 'Save',
|
||||
event = 'save',
|
||||
},
|
||||
|
||||
confirm = UI.Question {
|
||||
x = -38, y = -2,
|
||||
label = 'Overwrite Milo settings?',
|
||||
},
|
||||
|
||||
fileSelect = UI.FileSelect {
|
||||
modal = true,
|
||||
enable = function() end,
|
||||
transitionHint = 'expandUp',
|
||||
show = function(self)
|
||||
UI.FileSelect.enable(self)
|
||||
self:focusFirst()
|
||||
self:draw()
|
||||
end,
|
||||
disable = function(self)
|
||||
UI.FileSelect.disable(self)
|
||||
self.parent:focusFirst()
|
||||
self.parent:capture(self.parent)
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'select_cancel' then
|
||||
self:disable()
|
||||
elseif event.type == 'select_file' then
|
||||
self:disable()
|
||||
end
|
||||
return UI.FileSelect.eventHandler(self, event)
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
function page:scan()
|
||||
self.storages = Util.filter(Peripheral.getList(), function(dev)
|
||||
return dev.pushItems
|
||||
end)
|
||||
|
||||
local types = {}
|
||||
Util.each(self.storages, function(dev, name)
|
||||
if not types[dev.type] then types[dev.type] = {amount = 0, type = dev.type} end
|
||||
types[dev.type].amount = types[dev.type].amount + 1
|
||||
end)
|
||||
|
||||
self.typeGrid:setValues(types)
|
||||
self:draw()
|
||||
self:sync()
|
||||
end
|
||||
|
||||
function page:saveConfig(path)
|
||||
local config = Util.readTable(path) or {}
|
||||
Util.each(self.storages, function(dev, name)
|
||||
if self.typeGrid.values[dev.type] and self.typeGrid.values[dev.type].checked and (not config[name] or config[name].mtype == 'ignore') then
|
||||
config[name] = {
|
||||
name = name,
|
||||
category = 'storage',
|
||||
mtype = 'storage',
|
||||
}
|
||||
end
|
||||
end)
|
||||
Util.writeTable(path, config)
|
||||
|
||||
self.notification:success("Config saved to "..path)
|
||||
end
|
||||
|
||||
function page:enable()
|
||||
UI.Page.enable(self)
|
||||
self:scan()
|
||||
end
|
||||
|
||||
function page.typeGrid:getRowTextColor(row, selected)
|
||||
return row.checked and colors.yellow or UI.Grid.getRowTextColor(self, row, selected)
|
||||
end
|
||||
|
||||
function page:eventHandler(event)
|
||||
if event.type == "rescan" then
|
||||
self:scan()
|
||||
|
||||
elseif event.type == "save" then
|
||||
self.confirm:show()
|
||||
|
||||
elseif event.type == "question_yes" then
|
||||
self:saveConfig(defaultStoragePath)
|
||||
self.confirm:hide()
|
||||
|
||||
elseif event.type == "question_no" then
|
||||
self.confirm:hide()
|
||||
self.fileSelect:show()
|
||||
|
||||
elseif event.type == "select_file" then
|
||||
self:saveConfig(event.file)
|
||||
|
||||
else return UI.Page.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
UI:setPage(page)
|
||||
UI:start()
|
||||
@@ -1,172 +0,0 @@
|
||||
-- (Super)MultiFurnace Controller (did I mention, it's SUPER!?)
|
||||
-- This app is designed to wrap up to 4 of kepler155c's furni.lua (multiFurni) arrays and divide up workload,
|
||||
-- it functions as a straight drop-in for furni.lua and no other adjustments are required to make it work.
|
||||
-- Additionally, you get the ability to target any one multiFurni array for smelting when creating the machine recipe in Milo
|
||||
-- Further uses for this direct targeting can be limited-scope auto-smelting, using anywhere from 1/2 to 1/4 of your total
|
||||
-- capacity to auto-smelt, leaving the rest of the cluster available for you when you want it, great for multi-user bases!
|
||||
|
||||
-- Plug this turtle into a modem on your Milo network, and another modem leading to 2-4 turtles running furni.lua (or even furniController.lua for chained setups)
|
||||
|
||||
-- Slots are as follows:
|
||||
-- 1: Master Furnace Input
|
||||
-- 2: Master Furnace Fuel Input
|
||||
-- 3: Master Furnace Output
|
||||
-- 4: Optional (Options: "fuel"/"input"/"output"/nil (Default: nil [ignore]))
|
||||
-- 5-8: Furnace Inputs for 2 to 4 furni.lua arrays (slots mapped in order ascending, T1_Input=4, T2_Input=5, etc)
|
||||
-- 9-12: Furnace Fuels for 2 to 4 furni.lua arrays
|
||||
-- 13-16: Furnace Outputs for 2 to 4 furni.lua arrays
|
||||
|
||||
-- Only user option, slot 4, what to use it for?
|
||||
|
||||
local useSlot4 = nil
|
||||
|
||||
-- Begin main program code
|
||||
-- Find modem with -only- turtles attached (these should be our furni/furniController arrays)
|
||||
local devModem = ""
|
||||
for _, modem in ipairs({peripheral.find("modem")}) do
|
||||
if #modem.getNamesRemote() > 1 then -- We're only looking for 2 or more devices on a network segment, ignore anything less
|
||||
local nTurtles = 0
|
||||
for _, dev in ipairs(modem.getNamesRemote()) do
|
||||
if modem.getTypeRemote(dev) == "turtle" then nTurtles = nTurtles + 1 end
|
||||
end
|
||||
if nTurtles == #modem.getNamesRemote() then
|
||||
devModem = modem
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if devModem ~= "" then
|
||||
print("Found turtle-only modem, detected", #devModem.getNamesRemote(), "turtles", (#devModem.getNamesRemote() > 4 and "(Max 4 will be mapped)" or "(All will be mapped)"))
|
||||
else
|
||||
print("Did not find a modem with only turtles connected. Please check your networking cables/modems and devices, then try again.")
|
||||
return -- We don't have a modem, halt
|
||||
end
|
||||
|
||||
local devTurtles = {}
|
||||
for _, dev in ipairs(devModem.getNamesRemote()) do
|
||||
if #devTurtles >= 4 then break end
|
||||
devTurtles[#devTurtles+1] = peripheral.wrap(dev)
|
||||
print("Mapping", devTurtles[#devTurtles].getLabel(), "("..dev..")", "as device", #devTurtles)
|
||||
devTurtles[#devTurtles].inputSlot = #devTurtles + 4 -- Set the input for this device on second row
|
||||
devTurtles[#devTurtles].fuelSlot = #devTurtles + 8 -- Set the fuel for this device on third row
|
||||
devTurtles[#devTurtles].outputSlot = #devTurtles + 12 -- Set the output for this device on fourth row
|
||||
if devTurtles[#devTurtles].isOn() then
|
||||
print("Resynchronizing", devTurtles[#devTurtles].getLabel())
|
||||
devTurtles[#devTurtles].reboot()
|
||||
else
|
||||
print("Powering", devTurtles[#devTurtles].getLabel(), "on")
|
||||
devTurtles[#devTurtles].turnOn()
|
||||
end
|
||||
end
|
||||
|
||||
local function listInventory() -- Supplement a local .list()-like function
|
||||
local tList = {}
|
||||
for i = 1, 16 do
|
||||
local slotData = turtle.getItemDetail(i) -- DWGFJTLR
|
||||
if slotData ~= nil then
|
||||
slotData.maxStack=turtle.getItemCount(i) + turtle.getItemSpace(i)
|
||||
tList[i] = slotData
|
||||
end
|
||||
end
|
||||
return tList
|
||||
end
|
||||
|
||||
local function manageLocalResources()
|
||||
--print("Input found")
|
||||
local itemCount = turtle.getItemCount(1) / #devTurtles
|
||||
if itemCount < 1 then itemCount = 1 end -- Patch for single items fed into master slot
|
||||
if turtle.getItemCount(1) > 0 then -- Input
|
||||
for _, dev in ipairs(devTurtles) do
|
||||
if turtle.select(1) and ((turtle.compareTo(dev.inputSlot) and turtle.getItemSpace(dev.inputSlot) > 0) or turtle.getItemCount(dev.inputSlot) == 0) then -- Move Input
|
||||
turtle.transferTo(dev.inputSlot, itemCount)
|
||||
end
|
||||
if useSlot4 == "input" and turtle.select(4) and ((turtle.compareTo(dev.inputSlot) and turtle.getItemSpace(dev.inputSlot) > 0) or turtle.getItemCount(dev.inputSlot) == 0) then -- Move Input
|
||||
turtle.transferTo(dev.inputSlot, itemCount)
|
||||
end --Slot 4 input
|
||||
end
|
||||
end
|
||||
if turtle.select(2) and turtle.getSelectedSlot() == 2 then -- Fuel
|
||||
for _, dev in ipairs(devTurtles) do
|
||||
if turtle.compareTo(dev.fuelSlot) or turtle.getItemCount(dev.fuelSlot) == 0 then turtle.transferTo(dev.fuelSlot,64) end -- Move fuel into slot
|
||||
end
|
||||
end
|
||||
if useSlot4 == "fuel" and turtle.select(4) and turtle.getSelectedSlot() == 4 then -- Fuel
|
||||
for _, dev in ipairs(devTurtles) do
|
||||
if turtle.compareTo(dev.fuelSlot) or turtle.getItemCount(dev.fuelSlot) == 0 then turtle.transferTo(dev.fuelSlot,64) end -- Move fuel into slot
|
||||
end
|
||||
end -- Slot 4 fuel
|
||||
|
||||
for _, dev in ipairs(devTurtles) do
|
||||
if turtle.getItemCount(3) == 0 and turtle.getItemCount(dev.outputSlot) > 0 then
|
||||
turtle.select(dev.outputSlot)
|
||||
turtle.transferTo(3, 64)
|
||||
elseif turtle.getItemCount(dev.outputSlot) > 0 and turtle.select(3) and turtle.compareTo(dev.outputSlot) then -- Move output
|
||||
--turtle.setStatus("moving")
|
||||
turtle.select(dev.outputSlot)
|
||||
turtle.transferTo(3, 64)
|
||||
end
|
||||
if useSlot4 == "output" then -- Slot 4 output
|
||||
if turtle.getItemCount(4) == 0 and turtle.getItemCount(dev.outputSlot) > 0 then
|
||||
turtle.select(dev.outputSlot)
|
||||
turtle.transferTo(4, 64)
|
||||
elseif turtle.getItemCount(dev.outputSlot) > 0 and turtle.select(4) and turtle.compareTo(dev.outputSlot) then
|
||||
turtle.select(dev.outputSlot)
|
||||
turtle.transferTo(4, 64)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function manageRemoteResources()
|
||||
local localList = listInventory()
|
||||
for _, dev in ipairs(devTurtles) do
|
||||
local devList = dev.list()
|
||||
--print(textutils.serialize(devList))
|
||||
if devList[2] == nil then
|
||||
if localList[dev.fuelSlot] ~= nil then
|
||||
turtle.setStatus("fueling")
|
||||
dev.pullItems(devModem.getNameLocal(), dev.fuelSlot, 64, 2)
|
||||
end
|
||||
else
|
||||
if localList[dev.fuelSlot] ~= nil and localList[dev.fuelSlot].name == devList[2].name then
|
||||
turtle.setStatus("fueling")
|
||||
dev.pullItems(devModem.getNameLocal(), dev.fuelSlot, 64, 2)
|
||||
end
|
||||
end
|
||||
if devList[1] == nil then
|
||||
if localList[dev.inputSlot] ~= nil then
|
||||
turtle.setStatus("pushing")
|
||||
dev.pullItems(devModem.getNameLocal(), dev.inputSlot, 64, 1)
|
||||
end
|
||||
else
|
||||
if localList[dev.inputSlot] ~= nil and localList[dev.inputSlot].name == devList[1].name then
|
||||
turtle.setStatus("pushing")
|
||||
dev.pullItems(devModem.getNameLocal(), dev.inputSlot, 64, 1)
|
||||
end
|
||||
end -- Move input
|
||||
if devList[3] ~= nil then
|
||||
if localList[dev.outputSlot] == nil then
|
||||
turtle.setStatus("pulling")
|
||||
dev.pushItems(devModem.getNameLocal(), 3, 64, dev.outputSlot)
|
||||
end
|
||||
else
|
||||
if localList[dev.outputSlot] ~= nil then
|
||||
if devList[3] ~= nil and localList[dev.outputSlot].name == devList[3].name then
|
||||
turtle.setStatus("pulling")
|
||||
dev.pushItems(devModem.getNameLocal(), 3, 64, dev.outputSlot)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
while true do -- Main Loop
|
||||
local turtleList = listInventory()
|
||||
if turtleList[1] ~= nil or turtleList[13] ~= nil or turtleList[14] ~= nil or turtleList[15] ~= nil or turtleList[16] ~= nil or ((useSlot4 == "input" or useSlot4 == "fuel") and turtleList[4] ~= nil) then
|
||||
manageLocalResources()
|
||||
end
|
||||
manageRemoteResources()
|
||||
turtle.setStatus("sleeping")
|
||||
sleep(1)
|
||||
end
|
||||
29
miloApps/apps/storageGen.lua
Normal file
29
miloApps/apps/storageGen.lua
Normal file
@@ -0,0 +1,29 @@
|
||||
--[[
|
||||
For initially setting up large amounts of storage chests.
|
||||
]]
|
||||
|
||||
local Util = require('opus.util')
|
||||
|
||||
local peripheral = _G.peripheral
|
||||
|
||||
local args = { ... }
|
||||
local st = args[1] or error('Specify a storage type (ie. minecraft:chest)')
|
||||
|
||||
local config = { }
|
||||
peripheral.find(st, function(n)
|
||||
config[n] = {
|
||||
name = n,
|
||||
category = 'storage',
|
||||
mtype = 'storage',
|
||||
}
|
||||
end)
|
||||
|
||||
print('Found ' .. Util.size(config))
|
||||
|
||||
if Util.size(config) == 0 then
|
||||
error('Invalid peripheral type')
|
||||
end
|
||||
|
||||
Util.writeTable('usr/config/storageGen', config)
|
||||
print('storageGen file created in usr/config')
|
||||
print('update /usr/config/storage with contents (or rename to storage)')
|
||||
@@ -1,14 +1,14 @@
|
||||
{
|
||||
[ "4486006f811b88cacd5f211fd579717e29b600cd" ] = {
|
||||
title = "Simple",
|
||||
category = "Turtle",
|
||||
category = "Mining",
|
||||
icon = "\030 \0315\\\030 \031 \010\030 \0304\031f _ \030 \031c/\0315\\\010\030 \0304 ",
|
||||
run = "simpleMiner.lua",
|
||||
requires = 'turtle',
|
||||
},
|
||||
[ "da39a3ee5e6b4b0d3255bfef95601890afd80709" ] = {
|
||||
title = "Scanning",
|
||||
category = "Turtle",
|
||||
category = "Mining",
|
||||
icon = "\030 \0315\\\030 \031 \010\030 \0304\031f _ \030 \031c/\0315\\\010\030 \0304 ",
|
||||
run = "scanningMiner.lua",
|
||||
requires = 'turtle',
|
||||
|
||||
@@ -2,24 +2,24 @@ local fs = _G.fs
|
||||
local shell = _ENV.shell
|
||||
|
||||
local function recurse(path)
|
||||
if fs.isDir(path) then
|
||||
for _, v in pairs(fs.listEx(path)) do
|
||||
if not v.isReadOnly then
|
||||
recurse(fs.combine(path, v.name))
|
||||
end
|
||||
end
|
||||
elseif path:match('%.lua$') and not fs.isReadOnly(path) then
|
||||
local sz = fs.getSize(path)
|
||||
shell.run('minify.lua minify ' .. path)
|
||||
print(string.format('%s : %.2f%%', path, (sz - fs.getSize(path)) / sz * 100))
|
||||
end
|
||||
if fs.isDir(path) then
|
||||
for _, v in pairs(fs.listEx(path)) do
|
||||
if not v.isReadOnly then
|
||||
recurse(fs.combine(path, v.name))
|
||||
end
|
||||
end
|
||||
elseif path:match('%.lua$') and not fs.isReadOnly(path) then
|
||||
local sz = fs.getSize(path)
|
||||
shell.run('minify.lua minify ' .. path)
|
||||
print(string.format('%s : %.2f%%', path, (sz - fs.getSize(path)) / sz * 100))
|
||||
end
|
||||
end
|
||||
|
||||
local path = ({ ... })[1] or error('Syntax: minifyDir PATH')
|
||||
|
||||
path = fs.combine(path, '')
|
||||
if not fs.isDir(path) then
|
||||
error('Invalid path')
|
||||
error('Invalid path')
|
||||
end
|
||||
|
||||
recurse(path)
|
||||
|
||||
@@ -2,6 +2,7 @@ local Event = require('opus.event')
|
||||
local Socket = require('opus.socket')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local multishell = _ENV.multishell
|
||||
local os = _G.os
|
||||
|
||||
local remoteId
|
||||
@@ -22,7 +23,7 @@ local function wrapTerm(socket)
|
||||
'setTextColor', 'setTextColour', 'setBackgroundColor',
|
||||
'setBackgroundColour', 'scroll', 'setCursorBlink', }
|
||||
|
||||
socket.term = _G.device.terminal
|
||||
socket.term = multishell.term
|
||||
socket.oldTerm = Util.shallowCopy(socket.term)
|
||||
|
||||
for _,k in pairs(methods) do
|
||||
|
||||
156
monitor/mwm.lua
156
monitor/mwm.lua
@@ -11,7 +11,8 @@ local term = _G.term
|
||||
local window = _G.window
|
||||
|
||||
local function syntax()
|
||||
error('Syntax:\nmwm [--config=filename] [monitor]')
|
||||
printError('Syntax:')
|
||||
error('mwm [--config=filename] [monitor]')
|
||||
end
|
||||
|
||||
local args = Util.parse(...)
|
||||
@@ -24,7 +25,8 @@ local monName = args[1]
|
||||
local running
|
||||
local parentMon
|
||||
|
||||
_ENV.multishell = multishell
|
||||
local defaultEnv = Util.shallowCopy(_ENV)
|
||||
defaultEnv.multishell = multishell
|
||||
if monName then
|
||||
parentMon = peripheral.wrap(monName) or syntax()
|
||||
else
|
||||
@@ -91,8 +93,8 @@ end
|
||||
--[[ A runnable process ]]--
|
||||
local Process = { }
|
||||
|
||||
function Process:new(env, args)
|
||||
args.env = shell.makeEnv(env)
|
||||
function Process:new(args)
|
||||
args.env = args.env or Util.shallowCopy(defaultEnv)
|
||||
args.width = args.width or termDim.width
|
||||
args.height = args.height or termDim.height
|
||||
|
||||
@@ -101,8 +103,8 @@ function Process:new(env, args)
|
||||
uid = nextUID(),
|
||||
x = args.x or 1,
|
||||
y = args.y or 1,
|
||||
width = args.width,
|
||||
height = args.height + 1,
|
||||
width = args.width + 2,
|
||||
height = args.height + 3,
|
||||
path = args.path,
|
||||
args = args.args or { },
|
||||
title = args.title or 'shell',
|
||||
@@ -115,12 +117,9 @@ function Process:new(env, args)
|
||||
end
|
||||
|
||||
self.container = Terminal.window(monitor, self.x, self.y, self.width, self.height, true)
|
||||
self.window = window.create(self.container, 1, 2, args.width, args.height, true)
|
||||
self.window = window.create(self.container, 2, 3, args.width, args.height, true)
|
||||
self.terminal = self.window
|
||||
|
||||
self.container.setBackgroundColor(colors.black)
|
||||
self.container.clear()
|
||||
|
||||
self.container.canvas.parent = monitor.canvas
|
||||
if not monitor.canvas.children then
|
||||
monitor.canvas.children = { }
|
||||
@@ -151,35 +150,62 @@ function Process:new(env, args)
|
||||
return self
|
||||
end
|
||||
|
||||
function Process:drawTitle(focused)
|
||||
if self.showSizers and focused then
|
||||
local sizers = '\25 \26 \24 \27'
|
||||
|
||||
self.container.setBackgroundColor(colors.yellow)
|
||||
self.container.setTextColor(colors.black)
|
||||
|
||||
write(self.container, 1, 1, string.rep(' ', self.width))
|
||||
write(self.container, 2, 1, sizers)
|
||||
|
||||
local str = string.format('%d x %d', self.width, self.height - 1)
|
||||
write(self.container, 10, 1, str)
|
||||
else
|
||||
if focused then
|
||||
self.container.setBackgroundColor(colors.yellow)
|
||||
else
|
||||
self.container.setBackgroundColor(colors.lightGray)
|
||||
end
|
||||
self.container.setTextColor(colors.black)
|
||||
write(self.container, 1, 1, string.rep(' ', self.width))
|
||||
write(self.container, 2, 1, self.title)
|
||||
end
|
||||
write(self.container, self.width - 1, 1, '*')
|
||||
end
|
||||
|
||||
function Process:focus(focused)
|
||||
self:drawTitle(focused)
|
||||
if focused then
|
||||
self.container.setBackgroundColor(colors.yellow)
|
||||
else
|
||||
self.container.setBackgroundColor(colors.gray)
|
||||
end
|
||||
self.container.setTextColor(colors.black)
|
||||
write(self.container, 2, 2, string.rep(' ', self.width - 2))
|
||||
write(self.container, 3, 2, self.title)
|
||||
write(self.container, self.width - 2, 2, '*')
|
||||
|
||||
if focused then
|
||||
self.window.restoreCursor()
|
||||
elseif self.showSizers then
|
||||
self:drawSizers(false)
|
||||
end
|
||||
end
|
||||
|
||||
function Process:drawSizers(showSizers)
|
||||
local sizeChars = {
|
||||
'\135', '\139', '\141', '\142'
|
||||
}
|
||||
|
||||
if Util.getVersion() < 1.8 then
|
||||
sizeChars = {
|
||||
'#', '#', '#', '#'
|
||||
}
|
||||
end
|
||||
|
||||
self.showSizers = showSizers
|
||||
|
||||
self.container.setBackgroundColor(colors.black)
|
||||
self.container.setTextColor(colors.white)
|
||||
|
||||
if self.showSizers then
|
||||
write(self.container, 1, 1, sizeChars[1])
|
||||
write(self.container, self.width, 1, sizeChars[2])
|
||||
write(self.container, 1, self.height, sizeChars[3])
|
||||
write(self.container, self.width, self.height, sizeChars[4])
|
||||
|
||||
self.container.setTextColor(colors.yellow)
|
||||
write(self.container, 1, 3, '+')
|
||||
write(self.container, 1, 5, '-')
|
||||
write(self.container, 3, 1, '+')
|
||||
write(self.container, 5, 1, '-')
|
||||
|
||||
local str = string.format('%d x %d', self.width - 2, self.height - 3)
|
||||
write(self.container, (self.width - #str) / 2, 1, str)
|
||||
|
||||
else
|
||||
write(self.container, 1, 1, string.rep(' ', self.width))
|
||||
write(self.container, self.width, 1, ' ')
|
||||
write(self.container, 1, self.height, ' ')
|
||||
write(self.container, self.width, self.height, ' ')
|
||||
write(self.container, 1, 3, ' ')
|
||||
write(self.container, 1, 5, ' ')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -198,48 +224,48 @@ function Process:reposition()
|
||||
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)
|
||||
self.window.reposition(2, 3, self.width - 2, self.height - 3)
|
||||
if self.window ~= self.terminal then
|
||||
self.terminal.reposition(1, 1, self.width, self.height - 1)
|
||||
self.terminal.reposition(1, 1, self.width - 2, self.height - 3)
|
||||
end
|
||||
redraw()
|
||||
end
|
||||
|
||||
function Process:click(x, y)
|
||||
if y == 1 then -- title bar
|
||||
if x == self.width - 1 then
|
||||
if y == 2 then -- title bar
|
||||
if x == self.width - 2 then
|
||||
self:resume('terminate')
|
||||
elseif not self.showSizers then
|
||||
self.showSizers = not self.showSizers
|
||||
self:drawTitle(true)
|
||||
else
|
||||
self:resizeClick(x, y)
|
||||
self:drawSizers(not self.showSizers)
|
||||
end
|
||||
|
||||
elseif x == 1 or y == 1 then -- sizers
|
||||
self:resizeClick(x, y)
|
||||
|
||||
elseif x > 1 and x < self.width then
|
||||
if self.showSizers then
|
||||
self.showSizers = false
|
||||
self:drawTitle(true)
|
||||
self:drawSizers(false)
|
||||
end
|
||||
self:resume('mouse_click', 1, x, y - 1)
|
||||
self:resume('mouse_up', 1, x, y - 1)
|
||||
self:resume('mouse_click', 1, x - 1, y - 2)
|
||||
self:resume('mouse_up', 1, x - 1, y - 2)
|
||||
end
|
||||
end
|
||||
|
||||
function Process:resizeClick(x)
|
||||
if x == 2 then
|
||||
function Process:resizeClick(x, y)
|
||||
if x == 1 and y == 3 then
|
||||
self.height = self.height + 1
|
||||
elseif x == 6 then
|
||||
elseif x == 1 and y == 5 then
|
||||
self.height = self.height - 1
|
||||
elseif x == 4 then
|
||||
elseif x == 3 and y == 1 then
|
||||
self.width = self.width + 1
|
||||
elseif x == 8 then
|
||||
elseif x == 5 and y == 1 then
|
||||
self.width = self.width - 1
|
||||
else
|
||||
return
|
||||
end
|
||||
self:reposition()
|
||||
self:resume('term_resize')
|
||||
self:drawTitle(true)
|
||||
self:drawSizers(true)
|
||||
multishell.saveSession(sessionFile)
|
||||
end
|
||||
|
||||
@@ -327,7 +353,7 @@ function multishell.getTabs()
|
||||
end
|
||||
|
||||
function multishell.launch(env, file, ...)
|
||||
return multishell.openTab(env, {
|
||||
return multishell.openTab({
|
||||
path = file,
|
||||
env = env,
|
||||
title = 'shell',
|
||||
@@ -335,8 +361,8 @@ function multishell.launch(env, file, ...)
|
||||
})
|
||||
end
|
||||
|
||||
function multishell.openTab(env, tabInfo)
|
||||
local process = Process:new(env, tabInfo)
|
||||
function multishell.openTab(tabInfo)
|
||||
local process = Process:new(tabInfo)
|
||||
|
||||
table.insert(processes, 1, process)
|
||||
|
||||
@@ -364,8 +390,8 @@ function multishell.saveSession(filename)
|
||||
table.insert(t, {
|
||||
x = process.x,
|
||||
y = process.y,
|
||||
width = process.width,
|
||||
height = process.height - 1,
|
||||
width = process.width - 2,
|
||||
height = process.height - 3,
|
||||
path = process.path,
|
||||
args = process.args,
|
||||
})
|
||||
@@ -378,7 +404,7 @@ function multishell.loadSession(filename)
|
||||
local config = Util.readTable(filename)
|
||||
if config then
|
||||
for k = #config, 1, -1 do
|
||||
multishell.openTab(_ENV, config[k])
|
||||
multishell.openTab(config[k])
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -417,7 +443,7 @@ function multishell.start()
|
||||
process.x = math.floor(x - (process.width) / 2)
|
||||
process.y = y
|
||||
process:reposition()
|
||||
process:drawTitle(true)
|
||||
process:drawSizers(true)
|
||||
multishell.saveSession(sessionFile)
|
||||
end
|
||||
end
|
||||
@@ -429,7 +455,7 @@ function multishell.start()
|
||||
if not focused.isShell then
|
||||
multishell.setFocus(1) -- shell is always 1
|
||||
else
|
||||
focused:resume(table.unpack(event))
|
||||
focused:resume(unpack(event))
|
||||
end
|
||||
|
||||
elseif event[1] == 'char' or
|
||||
@@ -439,12 +465,12 @@ function multishell.start()
|
||||
|
||||
local focused = processes[#processes]
|
||||
if focused then
|
||||
focused:resume(table.unpack(event))
|
||||
focused:resume(unpack(event))
|
||||
end
|
||||
|
||||
else
|
||||
for _,process in pairs(Util.shallowCopy(processes)) do
|
||||
process:resume(table.unpack(event))
|
||||
process:resume(unpack(event))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -495,7 +521,7 @@ local function addShell()
|
||||
process.co = coroutine.create(function()
|
||||
print('To run a program on the monitor, type "fg <program>"')
|
||||
print('To quit, type "exit"')
|
||||
os.run(shell.makeEnv(_ENV), shell.resolveProgram('shell'))
|
||||
os.run(Util.shallowCopy(defaultEnv), shell.resolveProgram('shell'))
|
||||
multishell.stop()
|
||||
end)
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
title = 'moonscript',
|
||||
repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/moonscript',
|
||||
description = [[MoonScript is a programmer friendly language that compiles into Lua. It gives you the power of the fastest scripting language combined with a rich set of features. It runs on Lua 5.1 and above, including alternative runtimes like LuaJIT.
|
||||
|
||||
See https://moonscript.org.]],
|
||||
license = 'MIT',
|
||||
required = {
|
||||
'lpeg',
|
||||
},
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
Event = require('opus.event')
|
||||
UI = require('opus.ui')
|
||||
|
||||
import kernel from _G
|
||||
import multishell from _ENV
|
||||
|
||||
tasks = multishell and multishell.getTabs and multishell.getTabs! or kernel.routines
|
||||
|
||||
UI\configure 'Tasks', ...
|
||||
|
||||
page = UI.Page {
|
||||
UI.MenuBar {
|
||||
buttons: {
|
||||
{ text: 'Activate', event: 'activate' },
|
||||
{ text: 'Terminate', event: 'terminate' },
|
||||
{ text: 'Inspect', event: 'inspect' },
|
||||
},
|
||||
},
|
||||
grid: UI.ScrollingGrid {
|
||||
y: 2,
|
||||
columns: {
|
||||
{ heading: 'ID', key: 'uid', width: 3 },
|
||||
{ heading: 'Title', key: 'title' },
|
||||
{ heading: 'Status', key: 'status' },
|
||||
{ heading: 'Time', key: 'timestamp' },
|
||||
},
|
||||
values: tasks,
|
||||
sortColumn: 'uid',
|
||||
autospace: true,
|
||||
getDisplayValues: (row) =>
|
||||
elapsed = os.clock! - row.timestamp
|
||||
{
|
||||
uid: row.uid,
|
||||
title: row.title,
|
||||
status: row.isDead and 'error' or coroutine.status(row.co),
|
||||
timestamp: elapsed < 60 and
|
||||
string.format("%ds", math.floor(elapsed)) or
|
||||
string.format("%sm", math.floor(elapsed/6)/10),
|
||||
}
|
||||
},
|
||||
accelerators: {
|
||||
[ 'control-q' ]: 'quit',
|
||||
[ ' ' ]: 'activate',
|
||||
t: 'terminate',
|
||||
},
|
||||
eventHandler: (event) =>
|
||||
t = @grid\getSelected!
|
||||
switch event.type
|
||||
when 'activate', 'grid_select'
|
||||
multishell.setFocus t.uid if t
|
||||
when 'terminate'
|
||||
multishell.terminate t.uid if t
|
||||
when 'inspect'
|
||||
multishell.openTab _ENV, {
|
||||
path: 'sys/apps/Lua.lua',
|
||||
args: { t },
|
||||
focused: true,
|
||||
} if t
|
||||
when 'quit'
|
||||
UI\quit!
|
||||
else
|
||||
UI.Page.eventHandler(@, event)
|
||||
}
|
||||
|
||||
Event.onInterval 1, () ->
|
||||
page.grid\update!
|
||||
page.grid\draw!
|
||||
page\sync!
|
||||
|
||||
UI\setPage page
|
||||
UI\start!
|
||||
@@ -1,43 +0,0 @@
|
||||
local Map = require('opus.map')
|
||||
|
||||
local fs = _G.fs
|
||||
|
||||
local commands = Map.transpose {
|
||||
'packages/moonscript/moon',
|
||||
'packages/moonscript/moonc'
|
||||
}
|
||||
|
||||
local function compatEnv(source)
|
||||
local env = Map.shallowCopy(source._G)
|
||||
Map.merge(env, source)
|
||||
env._G = env
|
||||
_G.requireInjector(env, 'packages/moonscript')
|
||||
return env
|
||||
end
|
||||
|
||||
local function fix(env, args)
|
||||
if #args > 0 then
|
||||
args[1] = env.shell.resolve(args[1])
|
||||
end
|
||||
return args
|
||||
end
|
||||
|
||||
_ENV.shell.registerHandler(function(env, command, args)
|
||||
if command:match('(.+)%.moon$') then
|
||||
return {
|
||||
title = fs.getName(command):match('([^%.]+)'),
|
||||
path = 'packages/moonscript/moon',
|
||||
args = { env.shell.resolveProgram(command), table.unpack(args) },
|
||||
load = loadfile,
|
||||
env = compatEnv(env),
|
||||
}
|
||||
end
|
||||
command = env.shell.resolveProgram(command) or ''
|
||||
return commands[command] and {
|
||||
title = fs.getName(command),
|
||||
path = command,
|
||||
args = fix(env, args),
|
||||
load = loadfile,
|
||||
env = compatEnv(env),
|
||||
}
|
||||
end)
|
||||
@@ -1,8 +0,0 @@
|
||||
packages/moonscript/repo gitfs leafo/moonscript/master
|
||||
packages/moonscript/moon linkfs packages/moonscript/repo/bin/moon
|
||||
packages/moonscript/moonc linkfs packages/moonscript/repo/bin/moonc
|
||||
rom/modules/main/moonscript linkfs packages/moonscript/repo/moonscript
|
||||
rom/modules/main/moon linkfs packages/moonscript/repo/moon
|
||||
#rom/modules/main/moonutil gitfs natnat-mc/moonutil/master/moonutil
|
||||
#rom/modules/main/argparse urlfs https://raw.githubusercontent.com/mpeterv/argparse/master/src/argparse.lua
|
||||
rom/modules/main/argparse urlfs https://raw.githubusercontent.com/luarocks/argparse/master/src/argparse.lua
|
||||
@@ -1,116 +0,0 @@
|
||||
#!/usr/bin/env lua
|
||||
local argparse = require("argparse")
|
||||
local moonscript = require("moonscript.base")
|
||||
local util = require("moonscript.util")
|
||||
local errors = require("moonscript.errors")
|
||||
local unpack = util.unpack
|
||||
local argparser = argparse()({
|
||||
name = "moon"
|
||||
})
|
||||
argparser:argument("script")
|
||||
argparser:argument("args"):args("*")
|
||||
argparser:option("-c --coverage", "Collect and print code coverage")
|
||||
argparser:option("-d", "Disable stack trace rewriting")
|
||||
argparser:option("-v --version", "Print version information")
|
||||
local base = 0
|
||||
local _list_0 = arg
|
||||
for _index_0 = 1, #_list_0 do
|
||||
local flag = _list_0[_index_0]
|
||||
base = base + 1
|
||||
if flag:sub(1, 1) ~= "-" then
|
||||
break
|
||||
end
|
||||
end
|
||||
local args = {
|
||||
unpack(arg, 1, base)
|
||||
}
|
||||
local opts = argparser:parse(args)
|
||||
local print_err
|
||||
print_err = function(...)
|
||||
local msg = table.concat((function(...)
|
||||
local _accum_0 = { }
|
||||
local _len_0 = 1
|
||||
local _list_1 = {
|
||||
...
|
||||
}
|
||||
for _index_0 = 1, #_list_1 do
|
||||
local v = _list_1[_index_0]
|
||||
_accum_0[_len_0] = tostring(v)
|
||||
_len_0 = _len_0 + 1
|
||||
end
|
||||
return _accum_0
|
||||
end)(...), "\t")
|
||||
return io.stderr:write(msg .. "\n")
|
||||
end
|
||||
local run
|
||||
run = function()
|
||||
if opts.version then
|
||||
require("moonscript.version").print_version()
|
||||
os.exit()
|
||||
end
|
||||
local script_fname = shell.resolveProgram(opts.script)
|
||||
args = {
|
||||
unpack(arg, base + 1)
|
||||
}
|
||||
args[-1] = arg[0]
|
||||
args[0] = opts.script
|
||||
local moonscript_chunk, lua_parse_error
|
||||
local passed, err = pcall(function()
|
||||
moonscript_chunk, lua_parse_error = moonscript.loadfile(script_fname, {
|
||||
implicitly_return_root = false
|
||||
})
|
||||
end)
|
||||
if not (passed) then
|
||||
print_err(err)
|
||||
os.exit(1)
|
||||
end
|
||||
if not (moonscript_chunk) then
|
||||
if lua_parse_error then
|
||||
print_err(lua_parse_error)
|
||||
else
|
||||
print_err("Can't file file: " .. tostring(script_fname))
|
||||
end
|
||||
os.exit(1)
|
||||
end
|
||||
util.getfenv(moonscript_chunk).arg = args
|
||||
local run_chunk
|
||||
run_chunk = function()
|
||||
moonscript.insert_loader()
|
||||
moonscript_chunk(unpack(args))
|
||||
return moonscript.remove_loader()
|
||||
end
|
||||
if opts.d then
|
||||
return run_chunk()
|
||||
end
|
||||
local err, trace, cov
|
||||
if opts.coverage then
|
||||
print("starting coverage")
|
||||
local coverage = require("moonscript.cmd.coverage")
|
||||
cov = coverage.CodeCoverage()
|
||||
cov:start()
|
||||
end
|
||||
xpcall(run_chunk, function(_err)
|
||||
err = _err
|
||||
trace = debug.traceback("", 2)
|
||||
end)
|
||||
if err then
|
||||
local truncated = errors.truncate_traceback(util.trim(trace))
|
||||
local rewritten = errors.rewrite_traceback(truncated, err)
|
||||
if rewritten then
|
||||
print_err(rewritten)
|
||||
else
|
||||
print_err(table.concat({
|
||||
err,
|
||||
util.trim(trace)
|
||||
}, "\n"))
|
||||
end
|
||||
return os.exit(1)
|
||||
else
|
||||
if cov then
|
||||
cov:stop()
|
||||
return cov:print_results()
|
||||
end
|
||||
end
|
||||
end
|
||||
return run()
|
||||
-- vim: set filetype=lua:
|
||||
@@ -1,235 +0,0 @@
|
||||
#!/usr/bin/env lua
|
||||
|
||||
local argparse = require "argparse"
|
||||
local lfs = require "lfs"
|
||||
|
||||
local parser = argparse()
|
||||
|
||||
parser:flag("-l --lint", "Perform a lint on the file instead of compiling")
|
||||
parser:flag("-v --version", "Print version")
|
||||
parser:flag("-w --watch", "Watch file/directory for updates")
|
||||
parser:option("--transform", "Transform syntax tree with module")
|
||||
parser:mutex(
|
||||
parser:option("-t --output-to", "Specify where to place compiled files"),
|
||||
parser:option("-o", "Write output to file"),
|
||||
parser:flag("-p", "Write output to standard output"),
|
||||
parser:flag("-T", "Write parse tree instead of code (to stdout)"),
|
||||
parser:flag("-b", "Write parse and compile time instead of code(to stdout)"),
|
||||
parser:flag("-X", "Write line rewrite map instead of code (to stdout)")
|
||||
)
|
||||
parser:flag("-",
|
||||
"Read from standard in, print to standard out (Must be only argument)")
|
||||
|
||||
local read_stdin = arg[1] == "--" -- luacheck: ignore 113
|
||||
|
||||
if not read_stdin then
|
||||
parser:argument("file/directory"):args("+")
|
||||
end
|
||||
|
||||
local opts = parser:parse()
|
||||
|
||||
if opts.version then
|
||||
local v = require "moonscript.version"
|
||||
v.print_version()
|
||||
os.exit()
|
||||
end
|
||||
|
||||
function log_msg(...)
|
||||
if not opts.p then
|
||||
io.stderr:write(table.concat({...}, " ") .. "\n")
|
||||
end
|
||||
end
|
||||
|
||||
local moonc = require("moonscript.cmd.moonc")
|
||||
local util = require "moonscript.util"
|
||||
local normalize_dir = moonc.normalize_dir
|
||||
local compile_and_write = moonc.compile_and_write
|
||||
local path_to_target = moonc.path_to_target
|
||||
|
||||
local function scan_directory(root, collected)
|
||||
root = normalize_dir(root)
|
||||
collected = collected or {}
|
||||
|
||||
for fname in lfs.dir(root) do
|
||||
if not fname:match("^%.") then
|
||||
local full_path = root..fname
|
||||
|
||||
if lfs.attributes(full_path, "mode") == "directory" then
|
||||
scan_directory(full_path, collected)
|
||||
elseif fname:match("%.moon$") then
|
||||
table.insert(collected, full_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return collected
|
||||
end
|
||||
|
||||
local function remove_dups(tbl, key_fn)
|
||||
local hash = {}
|
||||
local final = {}
|
||||
|
||||
for _, v in ipairs(tbl) do
|
||||
local dup_key = key_fn and key_fn(v) or v
|
||||
if not hash[dup_key] then
|
||||
table.insert(final, v)
|
||||
hash[dup_key] = true
|
||||
end
|
||||
end
|
||||
|
||||
return final
|
||||
end
|
||||
|
||||
-- creates tuples of input and target
|
||||
local function get_files(fname, files)
|
||||
files = files or {}
|
||||
|
||||
if lfs.attributes(fname, "mode") == "directory" then
|
||||
for _, sub_fname in ipairs(scan_directory(fname)) do
|
||||
table.insert(files, {
|
||||
sub_fname,
|
||||
path_to_target(sub_fname, opts.output_to, fname)
|
||||
})
|
||||
end
|
||||
else
|
||||
if fname:sub(1, 1) ~= '/' then
|
||||
fname = lfs.currentdir() .. '/' .. fname
|
||||
end
|
||||
|
||||
table.insert(files, {
|
||||
fname,
|
||||
path_to_target(fname, opts.output_to)
|
||||
})
|
||||
end
|
||||
|
||||
return files
|
||||
end
|
||||
|
||||
if read_stdin then
|
||||
local parse = require "moonscript.parse"
|
||||
local compile = require "moonscript.compile"
|
||||
|
||||
local text = io.stdin:read("*a")
|
||||
local tree, err = parse.string(text)
|
||||
|
||||
if not tree then error(err) end
|
||||
local code, err, pos = compile.tree(tree)
|
||||
|
||||
if not code then
|
||||
error(compile.format_error(err, pos, text))
|
||||
end
|
||||
|
||||
print(code)
|
||||
os.exit()
|
||||
end
|
||||
|
||||
local inputs = opts["file/directory"]
|
||||
|
||||
local files = {}
|
||||
for _, input in ipairs(inputs) do
|
||||
get_files(input, files)
|
||||
end
|
||||
|
||||
files = remove_dups(files, function(f)
|
||||
return f[2]
|
||||
end)
|
||||
|
||||
-- returns an iterator that returns files that have been updated
|
||||
local function create_watcher(files)
|
||||
local watchers = require("moonscript.cmd.watchers")
|
||||
|
||||
if watchers.InotifyWacher:available() then
|
||||
return watchers.InotifyWacher(files):each_update()
|
||||
end
|
||||
|
||||
return watchers.SleepWatcher(files):each_update()
|
||||
end
|
||||
|
||||
if opts.watch then
|
||||
-- build function to check for lint or compile in watch
|
||||
local handle_file
|
||||
if opts.lint then
|
||||
local lint = require "moonscript.cmd.lint"
|
||||
handle_file = lint.lint_file
|
||||
else
|
||||
handle_file = compile_and_write
|
||||
end
|
||||
|
||||
local watcher = create_watcher(files)
|
||||
-- catches interrupt error for ctl-c
|
||||
local protected = function()
|
||||
local status, file = true, watcher()
|
||||
if status then
|
||||
return file
|
||||
elseif file ~= "interrupted!" then
|
||||
error(file)
|
||||
end
|
||||
end
|
||||
|
||||
for fname in protected do
|
||||
local target = path_to_target(fname, opts.t)
|
||||
|
||||
if opts.o then
|
||||
target = opts.o
|
||||
end
|
||||
|
||||
local success, err = handle_file(fname, target)
|
||||
if opts.lint then
|
||||
if success then
|
||||
io.stderr:write(success .. "\n\n")
|
||||
elseif err then
|
||||
io.stderr:write(fname .. "\n" .. err .. "\n\n")
|
||||
end
|
||||
elseif not success then
|
||||
io.stderr:write(table.concat({
|
||||
"",
|
||||
"Error: " .. fname,
|
||||
err,
|
||||
"\n",
|
||||
}, "\n"))
|
||||
elseif success == "build" then
|
||||
log_msg("Built", fname, "->", target)
|
||||
end
|
||||
end
|
||||
|
||||
io.stderr:write("\nQuitting...\n")
|
||||
elseif opts.lint then
|
||||
local has_linted_with_error;
|
||||
local lint = require "moonscript.cmd.lint"
|
||||
for _, tuple in pairs(files) do
|
||||
local fname = tuple[1]
|
||||
local res, err = lint.lint_file(fname)
|
||||
if res then
|
||||
has_linted_with_error = true
|
||||
io.stderr:write(res .. "\n\n")
|
||||
elseif err then
|
||||
has_linted_with_error = true
|
||||
io.stderr:write(fname .. "\n" .. err.. "\n\n")
|
||||
end
|
||||
end
|
||||
if has_linted_with_error then
|
||||
os.exit(1)
|
||||
end
|
||||
else
|
||||
for _, tuple in ipairs(files) do
|
||||
local fname, target = util.unpack(tuple)
|
||||
if opts.o then
|
||||
target = opts.o
|
||||
end
|
||||
|
||||
local success, err = compile_and_write(fname, target, {
|
||||
print = opts.p,
|
||||
fname = fname,
|
||||
benchmark = opts.b,
|
||||
show_posmap = opts.X,
|
||||
show_parse_tree = opts.T,
|
||||
transform_module = opts.transform
|
||||
})
|
||||
|
||||
if not success then
|
||||
io.stderr:write(fname .. "\t" .. err .. "\n")
|
||||
os.exit(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,12 +16,12 @@ UI:configure('Equipment', ...)
|
||||
local equipment = device.neuralInterface.getEquipment()
|
||||
|
||||
local slots = {
|
||||
'primary',
|
||||
'offhand',
|
||||
'boots',
|
||||
'leggings',
|
||||
'chest',
|
||||
'helmet',
|
||||
'primary',
|
||||
'offhand',
|
||||
'boots',
|
||||
'leggings',
|
||||
'chest',
|
||||
'helmet',
|
||||
}
|
||||
|
||||
local page = UI.Page {
|
||||
@@ -34,29 +34,29 @@ local page = UI.Page {
|
||||
grid = UI.Grid {
|
||||
y = 2,
|
||||
columns = {
|
||||
{ heading = 'Slot', key = 'index', width = 7 },
|
||||
{ heading = 'Slot', key = 'index', width = 7 },
|
||||
{ heading = 'Name', key = 'displayName' },
|
||||
{ heading = 'Count', key = 'count', width = 5, align = 'right' },
|
||||
},
|
||||
sortColumn = 'index',
|
||||
accelerators = {
|
||||
grid_select = 'show_detail',
|
||||
},
|
||||
getDisplayValues = function(_, row)
|
||||
row = Util.shallowCopy(row)
|
||||
if row.name then
|
||||
local item = itemDB:get(
|
||||
table.concat({ row.name, row.damage, row.nbtHash }, ':'),
|
||||
function()
|
||||
return equipment.getItemMeta(row.index)
|
||||
end)
|
||||
row.displayName = item.displayName
|
||||
else
|
||||
row.displayName = 'empty'
|
||||
end
|
||||
row.index = slots[row.index]
|
||||
return row
|
||||
end,
|
||||
sortColumn = 'index',
|
||||
accelerators = {
|
||||
grid_select = 'show_detail',
|
||||
},
|
||||
getDisplayValues = function(_, row)
|
||||
row = Util.shallowCopy(row)
|
||||
if row.name then
|
||||
local item = itemDB:get(
|
||||
table.concat({ row.name, row.damage, row.nbtHash }, ':'),
|
||||
function()
|
||||
return equipment.getItemMeta(row.index)
|
||||
end)
|
||||
row.displayName = item.displayName
|
||||
else
|
||||
row.displayName = 'empty'
|
||||
end
|
||||
row.index = slots[row.index]
|
||||
return row
|
||||
end,
|
||||
},
|
||||
accelerators = {
|
||||
[ 'control-q' ] = 'quit',
|
||||
@@ -77,58 +77,58 @@ local page = UI.Page {
|
||||
accelerators = {
|
||||
grid_select = 'inspect',
|
||||
},
|
||||
},
|
||||
show = function(self, slot)
|
||||
local detail = equipment.getItemMeta(slot.index)
|
||||
local t = { }
|
||||
for k,v in pairs(detail) do
|
||||
table.insert(t, {
|
||||
name = k,
|
||||
value = v,
|
||||
})
|
||||
end
|
||||
self.grid:setValues(t)
|
||||
self.grid:setIndex(1)
|
||||
UI.SlideOut.show(self)
|
||||
end,
|
||||
},
|
||||
enable = function(self)
|
||||
self:refresh()
|
||||
UI.Page.enable(self)
|
||||
end,
|
||||
refresh = function(self)
|
||||
local t = { }
|
||||
local list = equipment.list()
|
||||
for i = 1, equipment.size() do
|
||||
local v = list[i] or { }
|
||||
v.index = i
|
||||
table.insert(t, v)
|
||||
end
|
||||
self.grid:setValues(t)
|
||||
self.grid:draw()
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'quit' then
|
||||
UI:quit()
|
||||
},
|
||||
show = function(self, slot)
|
||||
local detail = equipment.getItemMeta(slot.index)
|
||||
local t = { }
|
||||
for k,v in pairs(detail) do
|
||||
table.insert(t, {
|
||||
name = k,
|
||||
value = v,
|
||||
})
|
||||
end
|
||||
self.grid:setValues(t)
|
||||
self.grid:setIndex(1)
|
||||
UI.SlideOut.show(self)
|
||||
end,
|
||||
},
|
||||
enable = function(self)
|
||||
self:refresh()
|
||||
UI.Page.enable(self)
|
||||
end,
|
||||
refresh = function(self)
|
||||
local t = { }
|
||||
local list = equipment.list()
|
||||
for i = 1, equipment.size() do
|
||||
local v = list[i] or { }
|
||||
v.index = i
|
||||
table.insert(t, v)
|
||||
end
|
||||
self.grid:setValues(t)
|
||||
self.grid:draw()
|
||||
end,
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'quit' then
|
||||
UI:quit()
|
||||
|
||||
elseif event.type == 'show_detail' then
|
||||
if event.selected.name then
|
||||
self.detail:show(event.selected)
|
||||
end
|
||||
elseif event.type == 'show_detail' then
|
||||
if event.selected.name then
|
||||
self.detail:show(event.selected)
|
||||
end
|
||||
|
||||
elseif event.type == 'drop' then
|
||||
local selected = self.grid:getSelected()
|
||||
equipment.drop(selected.index)
|
||||
self:refresh()
|
||||
elseif event.type == 'drop' then
|
||||
local selected = self.grid:getSelected()
|
||||
equipment.drop(selected.index)
|
||||
self:refresh()
|
||||
|
||||
elseif event.type == 'suck' then
|
||||
local selected = self.grid:getSelected()
|
||||
equipment.suck(selected.index)
|
||||
self:refresh()
|
||||
end
|
||||
elseif event.type == 'suck' then
|
||||
local selected = self.grid:getSelected()
|
||||
equipment.suck(selected.index)
|
||||
self:refresh()
|
||||
end
|
||||
|
||||
UI.Page.eventHandler(self, event)
|
||||
end,
|
||||
UI.Page.eventHandler(self, event)
|
||||
end,
|
||||
}
|
||||
|
||||
Event.onInterval(1, function()
|
||||
|
||||
@@ -188,7 +188,7 @@ function page:eventHandler(event)
|
||||
self:scan()
|
||||
|
||||
elseif event.type == 'grid_select' and event.element == self.detail.grid then
|
||||
multishell.openTab(_ENV, {
|
||||
multishell.openTab({
|
||||
path = 'sys/apps/Lua.lua',
|
||||
args = { event.selected },
|
||||
focused = true,
|
||||
|
||||
@@ -23,7 +23,7 @@ local config = Config.load('Sensor')
|
||||
local page = UI.Page {
|
||||
tabs = UI.Tabs {
|
||||
listing = UI.Tab {
|
||||
title = 'Listing',
|
||||
tabTitle = 'Listing',
|
||||
grid = UI.ScrollingGrid {
|
||||
columns = {
|
||||
{ heading = 'Name', key = 'displayName' },
|
||||
@@ -35,7 +35,7 @@ local page = UI.Page {
|
||||
},
|
||||
},
|
||||
summary = UI.Tab {
|
||||
title = 'Summary',
|
||||
tabTitle = 'Summary',
|
||||
grid = UI.ScrollingGrid {
|
||||
columns = {
|
||||
{ heading = 'Name', key = 'displayName' },
|
||||
@@ -256,7 +256,7 @@ function page:eventHandler(event)
|
||||
UI:quit()
|
||||
|
||||
elseif event.type == 'tab_activate' then
|
||||
config.activeTab = event.activated.title
|
||||
config.activeTab = event.activated.tabTitle
|
||||
Config.update('Sensor', config)
|
||||
end
|
||||
|
||||
@@ -264,7 +264,7 @@ function page:eventHandler(event)
|
||||
end
|
||||
|
||||
if config.activeTab then
|
||||
page.tabs:selectTab(Util.find(page.tabs.children, 'title', config.activeTab))
|
||||
page.tabs:selectTab(Util.find(page.tabs.children, 'tabTitle', config.activeTab))
|
||||
end
|
||||
|
||||
UI:setPage(page)
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
--[[
|
||||
Create a terminal compatible window for glasses canvas.
|
||||
|
||||
Note that the extended chars on glasses are not consistent with
|
||||
the normal cc font.
|
||||
]]
|
||||
|
||||
local Terminal = require('opus.terminal')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local device = _G.device
|
||||
|
||||
local Glasses = { }
|
||||
|
||||
local palette = {
|
||||
['0'] = 0xF0F0F000,
|
||||
['1'] = 0xF2B23300,
|
||||
['2'] = 0xE57FD800,
|
||||
['3'] = 0x99B2F200,
|
||||
['4'] = 0xDEDE6C00,
|
||||
['5'] = 0x7FCC1900,
|
||||
['6'] = 0xF2B2CC00,
|
||||
['7'] = 0x4C4C4C00,
|
||||
['8'] = 0x99999900,
|
||||
['9'] = 0x4C99B200,
|
||||
['a'] = 0xB266E500,
|
||||
['b'] = 0x3366CC00,
|
||||
['c'] = 0x7F664C00,
|
||||
['d'] = 0x57A64E00,
|
||||
['e'] = 0xCC4C4C00,
|
||||
['f'] = 0x19191900,
|
||||
}
|
||||
|
||||
function Glasses.getPalette(opacity)
|
||||
if opacity then
|
||||
for k,v in pairs(palette) do
|
||||
palette[k] = v + opacity
|
||||
end
|
||||
end
|
||||
return palette
|
||||
end
|
||||
|
||||
function Glasses.create(args)
|
||||
local opts = {
|
||||
x = 1, y = 20,
|
||||
width = 51, height = 19,
|
||||
scale = .5,
|
||||
name = 'glasses',
|
||||
opacity = 0xff,
|
||||
}
|
||||
Util.merge(opts, args)
|
||||
|
||||
local xs, ys = 6 * opts.scale, 9 * opts.scale
|
||||
local glasses = device['plethora:glasses']
|
||||
local canvas = glasses.canvas()
|
||||
local _, cy = 1, 1
|
||||
local lines = { }
|
||||
local pal = palette -- Glasses.getPalette(opts.opacity)
|
||||
|
||||
local pos = { x = opts.x * xs, y = opts.y * ys }
|
||||
|
||||
-- create an entry for every char as the glasses font is not fixed width :(
|
||||
local function init(group)
|
||||
for y = 1, opts.height do
|
||||
lines[y] = {
|
||||
text = { },
|
||||
bg = { }
|
||||
}
|
||||
for x = 1, opts.width 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(opts.scale)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local group = canvas.addGroup(pos)
|
||||
init(group)
|
||||
|
||||
local gterm = Terminal.window({
|
||||
isColor = function()
|
||||
return true
|
||||
end,
|
||||
blit = function(text, fg, bg)
|
||||
for x = 1, #text do
|
||||
local ln = lines[cy]
|
||||
if ln and x <= opts.width then
|
||||
ln.bg[x].setColor(pal[bg:sub(x, x)] + opts.opacity)
|
||||
ln.text[x].setColor(pal[fg:sub(x, x)] + opts.opacity)
|
||||
ln.text[x].setText(text:sub(x, x))
|
||||
end
|
||||
end
|
||||
end,
|
||||
setCursorPos = function(_, y)
|
||||
cy = y -- full lines are always blit
|
||||
end,
|
||||
setCursorBlink = function() end,
|
||||
}, 1, 1, opts.width, opts.height, true)
|
||||
|
||||
function gterm.setTextScale() end
|
||||
function gterm.getPosition() return opts.x, opts.y end
|
||||
function gterm.raise()
|
||||
local g = canvas.addGroup(pos)
|
||||
init(g)
|
||||
gterm.redraw()
|
||||
group.remove()
|
||||
group = g
|
||||
end
|
||||
function gterm.destroy()
|
||||
group.remove()
|
||||
end
|
||||
function gterm.getTextScale()
|
||||
return opts.scale
|
||||
end
|
||||
function gterm.getOpacity()
|
||||
return opts.opacity
|
||||
end
|
||||
function gterm.setOpacity(opacity)
|
||||
opts.opacity = opacity
|
||||
gterm.redraw()
|
||||
end
|
||||
function gterm.move(x, y)
|
||||
if opts.x ~= x or opts.y ~= y then
|
||||
opts.x, opts.y = x, y
|
||||
pos = { x = opts.x * xs, y = opts.y * ys }
|
||||
group.setPosition(pos.x, pos.y)
|
||||
end
|
||||
end
|
||||
function gterm.reposition2(x, y, w, h)
|
||||
opts.x, opts.y = x, y
|
||||
opts.width, opts.height = w, h
|
||||
pos = { x = opts.x * xs, y = opts.y * ys }
|
||||
local g = canvas.addGroup(pos)
|
||||
init(g)
|
||||
group.remove()
|
||||
group = g
|
||||
gterm.reposition(1, 1, w, h)
|
||||
gterm.redraw()
|
||||
end
|
||||
|
||||
return gterm
|
||||
end
|
||||
|
||||
return Glasses
|
||||
@@ -17,14 +17,12 @@ function Neural.assertModules(modules)
|
||||
|
||||
for _, m in pairs(modules) do
|
||||
if not Neural.hasModule(m) then
|
||||
local t = { }
|
||||
table.insert(t, 'Required:')
|
||||
print('Required:')
|
||||
for _, v in pairs(modules) do
|
||||
table.insert(t, ' * ' .. (modules[v] or v))
|
||||
print(' * ' .. (modules[v] or v))
|
||||
end
|
||||
table.insert(t, '')
|
||||
table.insert(t, 'Missing: ' .. (all[m] or m))
|
||||
error(table.concat(t, '\n'))
|
||||
print('')
|
||||
error('Missing: ' .. (all[m] or m))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
local device = _G.device
|
||||
local kernel = _G.kernel
|
||||
|
||||
local opus = {
|
||||
'fffff00',
|
||||
'ffff07000',
|
||||
'ff00770b00f4444',
|
||||
'ff00770b00 4444',
|
||||
'ff077777444444444',
|
||||
'f07777744444444444',
|
||||
'f0000777444444444',
|
||||
@@ -15,14 +12,29 @@ local opus = {
|
||||
'077000000000',
|
||||
}
|
||||
|
||||
local function update()
|
||||
local canvas = device['plethora:glasses'] and device['plethora:glasses'].canvas()
|
||||
if canvas then
|
||||
local Tween = require('opus.ui.tween')
|
||||
local Glasses = require('neural.glasses')
|
||||
local hex = {
|
||||
['0'] = 0xF0F0F04F,
|
||||
['1'] = 0xF2B2334F,
|
||||
['2'] = 0xE57FD84F,
|
||||
['3'] = 0x99B2F24F,
|
||||
['4'] = 0xDEDE6C4F,
|
||||
['5'] = 0x7FCC194F,
|
||||
['6'] = 0xF2B2CC4F,
|
||||
['7'] = 0x4C4C4C4F,
|
||||
['8'] = 0x9999994F,
|
||||
['9'] = 0x4C99B24F,
|
||||
['a'] = 0xB266E54F,
|
||||
['b'] = 0x3366CC4F,
|
||||
['c'] = 0x7F664C4F,
|
||||
['d'] = 0x57A64E4F,
|
||||
['e'] = 0xCC4C4C4F,
|
||||
-- ['f'] = 0x191919FF, -- transparent
|
||||
}
|
||||
|
||||
local pal = Glasses.getPalette(0x4f)
|
||||
pal['f'] = nil -- transparent
|
||||
local function update()
|
||||
local canvas = device['plethora:glasses'] and device['plethora:glasses'].canvas()
|
||||
if canvas then
|
||||
local Tween = require('opus.ui.tween')
|
||||
|
||||
canvas.clear()
|
||||
local w, h = canvas.getSize()
|
||||
@@ -30,7 +42,7 @@ local function update()
|
||||
local group = canvas.addGroup(pos)
|
||||
local function drawLine(k, line)
|
||||
for i = 1, #line do
|
||||
local pix = pal[line:sub(i, i)]
|
||||
local pix = hex[line:sub(i, i)]
|
||||
if pix then
|
||||
group.addRectangle(i*1.5, k*2.25, 1.5, 2.25, pix)
|
||||
end
|
||||
@@ -50,7 +62,9 @@ local function update()
|
||||
end
|
||||
end
|
||||
|
||||
kernel.run(_ENV, {
|
||||
kernel.run({
|
||||
title = 'opus',
|
||||
env = _ENV,
|
||||
hidden = true,
|
||||
fn = update,
|
||||
})
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user