This commit is contained in:
kepler155c@gmail.com 2017-10-11 16:31:48 -04:00
parent 852ad193f0
commit f9221e67be
6 changed files with 103 additions and 93 deletions

View File

@ -21,7 +21,12 @@ function NFT.parse(imageText)
} }
local num = 1 local num = 1
for _,sLine in ipairs(Util.split(imageText)) do local lines = Util.split(imageText)
while #lines[#lines] == 0 do
table.remove(lines, #lines)
end
for _,sLine in ipairs(lines) do
table.insert(image.fg, { }) table.insert(image.fg, { })
table.insert(image.bg, { }) table.insert(image.bg, { })
table.insert(image.text, { }) table.insert(image.text, { })

View File

@ -380,15 +380,11 @@ function Util.download(url, filename)
end end
function Util.loadUrl(url, env) -- loadfile equivalent function Util.loadUrl(url, env) -- loadfile equivalent
local s, m = pcall(function() local c, msg = Util.httpGet(url)
local c = Util.download(url) if not c then
return load(c, url, nil, env) return c, msg
end)
if s then
return m
end end
return s, m return load(c, url, nil, env)
end end
function Util.runUrl(env, url, ...) -- os.run equivalent function Util.runUrl(env, url, ...) -- os.run equivalent

View File

@ -9,6 +9,7 @@ local colors = _G.colors
local device = _G.device local device = _G.device
local multishell = _ENV.multishell local multishell = _ENV.multishell
local network = _G.network local network = _G.network
local os = _G.os
local shell = _ENV.shell local shell = _ENV.shell
multishell.setTitle(multishell.getCurrent(), 'Network') multishell.setTitle(multishell.getCurrent(), 'Network')
@ -112,7 +113,7 @@ function page:eventHandler(event)
elseif event.type == 'chat' then elseif event.type == 'chat' then
multishell.openTab({ multishell.openTab({
path = 'sys/apps/shell', path = 'sys/apps/shell',
args = { 'chat join opusChat-' .. t.id .. ' guest'}, args = { 'chat join opusChat-' .. t.id .. ' guest-' .. os.getComputerID() },
title = 'Chatroom', title = 'Chatroom',
focused = true, focused = true,
}) })

View File

@ -1,16 +1,20 @@
local parentShell = shell local parentShell = _ENV.shell
shell = { } _ENV.shell = { }
multishell = multishell or { } _ENV.multishell = _ENV.multishell or { }
local fs = _G.fs
local shell = _ENV.shell
local multishell = _ENV.multishell
local sandboxEnv = setmetatable({ }, { __index = _G }) local sandboxEnv = setmetatable({ }, { __index = _G })
for k,v in pairs(getfenv(1)) do for k,v in pairs(_ENV) do
sandboxEnv[k] = v sandboxEnv[k] = v
end end
sandboxEnv.shell = shell sandboxEnv.shell = shell
sandboxEnv.multishell = multishell sandboxEnv.multishell = multishell
requireInjector(getfenv(1)) _G.requireInjector()
local Util = require('util') local Util = require('util')
@ -40,18 +44,33 @@ local function parseCommandLine( ... )
return table.remove(tWords, 1), tWords return table.remove(tWords, 1), tWords
end end
-- Install shell API local function run(env, ...)
function shell.run(...)
local path, args = parseCommandLine(...) local path, args = parseCommandLine(...)
local isUrl = not not path:match("^(https?:)//(([^/:]+):?([0-9]*))(/?.*)$")
if not isUrl then if not path then
path = shell.resolveProgram(path) error('No such program')
end
local isUrl = not not path:match("^(https?:)//(([^/:]+):?([0-9]*))(/?.*)$")
if not isUrl then
path = shell.resolveProgram(path)
if not path then
error('No such program')
end
end
local fn, err
if isUrl then
fn, err = Util.loadUrl(path, env)
else
fn, err = loadfile(path, env)
end
if not fn then
error(err)
end end
if path then
tProgramStack[#tProgramStack + 1] = path
local oldTitle local oldTitle
if multishell and multishell.getTitle then if multishell and multishell.getTitle then
@ -59,23 +78,25 @@ function shell.run(...)
multishell.setTitle(multishell.getCurrent(), fs.getName(path)) multishell.setTitle(multishell.getCurrent(), fs.getName(path))
end end
local result, err
local env = Util.shallowCopy(sandboxEnv)
if isUrl then if isUrl then
result, err = Util.runUrl(env, path, unpack(args)) tProgramStack[#tProgramStack + 1] = path:match("^https?://([^/:]+:?[0-9]*/?.*)$")
else else
result, err = Util.run(env, path, unpack(args)) tProgramStack[#tProgramStack + 1] = path
end end
local r = { fn(table.unpack(args)) }
tProgramStack[#tProgramStack] = nil tProgramStack[#tProgramStack] = nil
if multishell and multishell.getTitle then if multishell and multishell.getTitle then
multishell.setTitle(multishell.getCurrent(), oldTitle or 'shell') multishell.setTitle(multishell.getCurrent(), oldTitle or 'shell')
end end
return result, err return table.unpack(r)
end end
return false, 'No such program'
-- Install shell API
function shell.run(...)
return pcall(run, setmetatable(Util.shallowCopy(sandboxEnv), { __index = _G }), ...)
end end
function shell.exit() function shell.exit()
@ -130,7 +151,6 @@ function shell.resolveProgram( _sCommand )
return sPath .. '.lua' return sPath .. '.lua'
end end
end end
-- Not found -- Not found
return nil return nil
end end
@ -143,7 +163,7 @@ function shell.programs( _bIncludeHidden )
sPath = shell.resolve(sPath) sPath = shell.resolve(sPath)
if fs.isDir( sPath ) then if fs.isDir( sPath ) then
local tList = fs.list( sPath ) local tList = fs.list( sPath )
for n,sFile in pairs( tList ) do for _,sFile in pairs( tList ) do
if not fs.isDir( fs.combine( sPath, sFile ) ) and if not fs.isDir( fs.combine( sPath, sFile ) ) and
(_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= ".") then (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= ".") then
tItems[ sFile ] = true tItems[ sFile ] = true
@ -154,7 +174,7 @@ function shell.programs( _bIncludeHidden )
-- Sort and return -- Sort and return
local tItemList = {} local tItemList = {}
for sItem, b in pairs( tItems ) do for sItem in pairs( tItems ) do
table.insert( tItemList, sItem ) table.insert( tItemList, sItem )
end end
table.sort( tItemList ) table.sort( tItemList )
@ -229,40 +249,18 @@ end
local tArgs = { ... } local tArgs = { ... }
if #tArgs > 0 then if #tArgs > 0 then
return run(_ENV, ...)
local path, args = parseCommandLine(...)
if not path then
error('No such program')
end
local isUrl = not not path:match("^(https?:)//(([^/:]+):?([0-9]*))(/?.*)$")
if not isUrl then
path = shell.resolveProgram(path)
if not path then
error('No such program')
end
end
local fn, err
if isUrl then
fn, err = Util.loadUrl(path, getfenv(1))
else
fn, err = loadfile(path, getfenv(1))
end
if not fn then
error(err)
end
tProgramStack[#tProgramStack + 1] = path
return fn(table.unpack(args))
end end
local Config = require('config') local Config = require('config')
local History = require('history') local History = require('history')
local colors = _G.colors
local keys = _G.keys
local os = _G.os
local term = _G.term
local textutils = _G.textutils
local config = { local config = {
standard = { standard = {
textColor = colors.white, textColor = colors.white,
@ -285,7 +283,7 @@ local config = {
displayDirectory = true, displayDirectory = true,
} }
--Config.load('shell', config) Config.load('shellprompt', config)
local _colors = config.standard local _colors = config.standard
if term.isColor() then if term.isColor() then
@ -384,6 +382,7 @@ local function autocomplete(line, suggestions)
end end
local results = { } local results = { }
local files = { }
if #words == 0 then if #words == 0 then
files = autocompleteFile(results, words) files = autocompleteFile(results, words)
@ -398,7 +397,6 @@ local function autocomplete(line, suggestions)
end end
local match = words[#words] or '' local match = words[#words] or ''
local files = { }
for f in pairs(results) do for f in pairs(results) do
if f:sub(1, #match) == match then if f:sub(1, #match) == match then
table.insert(files, f) table.insert(files, f)
@ -438,12 +436,12 @@ local function autocomplete(line, suggestions)
if #tDirs > 0 and #tDirs < #tFiles then if #tDirs > 0 and #tDirs < #tFiles then
local w = term.getSize() local w = term.getSize()
local nMaxLen = w / 8 local nMaxLen = w / 8
for n, sItem in pairs(files) do for _,sItem in pairs(files) do
nMaxLen = math.max(string.len(sItem) + 1, nMaxLen) nMaxLen = math.max(string.len(sItem) + 1, nMaxLen)
end end
local nCols = math.floor(w / nMaxLen) local nCols = math.floor(w / nMaxLen)
if #tDirs < nCols then if #tDirs < nCols then
for i = #tDirs + 1, nCols do for _ = #tDirs + 1, nCols do
table.insert(tDirs, '') table.insert(tDirs, '')
end end
end end
@ -457,7 +455,7 @@ local function autocomplete(line, suggestions)
term.setTextColour(_colors.promptTextColor) term.setTextColour(_colors.promptTextColor)
term.setBackgroundColor(_colors.promptBackgroundColor) term.setBackgroundColor(_colors.promptBackgroundColor)
write("$ " ) term.write("$ " )
term.setTextColour(_colors.commandTextColor) term.setTextColour(_colors.commandTextColor)
term.setBackgroundColor(colors.black) term.setBackgroundColor(colors.black)
@ -507,7 +505,7 @@ local function shellRead(history)
nScroll = (sx + nPos) - w nScroll = (sx + nPos) - w
end end
local cx,cy = term.getCursorPos() local _,cy = term.getCursorPos()
term.setCursorPos( sx, cy ) term.setCursorPos( sx, cy )
if sReplace then if sReplace then
term.write( string.rep( sReplace, math.max( string.len(sLine) - nScroll, 0 ) ) ) term.write( string.rep( sReplace, math.max( string.len(sLine) - nScroll, 0 ) ) )
@ -518,7 +516,7 @@ local function shellRead(history)
end end
while true do while true do
local sEvent, param, param2 = os.pullEventRaw() local sEvent, param = os.pullEventRaw()
if sEvent == "char" then if sEvent == "char" then
sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 ) sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
@ -605,7 +603,7 @@ local function shellRead(history)
end end
end end
local cx, cy = term.getCursorPos() local _, cy = term.getCursorPos()
term.setCursorPos( w + 1, cy ) term.setCursorPos( w + 1, cy )
print() print()
term.setCursorBlink( false ) term.setCursorBlink( false )
@ -622,7 +620,7 @@ while not bExit do
end end
term.setTextColour(_colors.promptTextColor) term.setTextColour(_colors.promptTextColor)
term.setBackgroundColor(_colors.promptBackgroundColor) term.setBackgroundColor(_colors.promptBackgroundColor)
write("$ " ) term.write("$ " )
term.setTextColour(_colors.commandTextColor) term.setTextColour(_colors.commandTextColor)
term.setBackgroundColor(colors.black) term.setBackgroundColor(colors.black)
local sLine = shellRead(history) local sLine = shellRead(history)
@ -635,9 +633,9 @@ while not bExit do
end end
term.setTextColour(_colors.textColor) term.setTextColour(_colors.textColor)
if #sLine > 0 then if #sLine > 0 then
local result, err = shell.run( sLine ) local result, err = shell.run(sLine)
if not result and err then if not result and err then
printError(err) _G.printError(err)
end end
end end
end end

View File

@ -88,6 +88,16 @@
run = "simpleMiner.lua", run = "simpleMiner.lua",
requires = 'turtle', requires = 'turtle',
}, },
[ "131260cbfbb0c821f8eae5e7c3c296c7aa4d50b9" ] = {
title = "Music",
category = "Apps",
icon = "\030 \031f === \
\030 \031f | |\
\030 \031fo| o|\
",
run = "usr/apps/music.lua",
requires = 'turtle',
},
c47ae15370cfe1ed2781eedc1dc2547d12d9e972 = { c47ae15370cfe1ed2781eedc1dc2547d12d9e972 = {
title = "Help", title = "Help",
category = "Apps", category = "Apps",

View File

@ -47,7 +47,7 @@ if device.wireless_modem then
os.sleep(3) os.sleep(3)
local tabId = multishell.openTab({ local tabId = multishell.openTab({
fn = chatClient, fn = chatClient,
title = 'Chatroom', title = 'Chat',
hidden = true, hidden = true,
}) })
tab = multishell.getTab(tabId) tab = multishell.getTab(tabId)