Merge remote-tracking branch 'upstream/master-MC1.7.10' into master-MC1.8.9

This commit is contained in:
payonel 2017-05-15 07:18:04 -07:00
commit dd15d6c7fb
15 changed files with 111 additions and 50 deletions

View File

@ -1,22 +1,30 @@
local args = {...}
if args[1] then
local shell = require("shell")
local args, ops = shell.parse(...)
local hostname = args[1]
if hostname then
local file, reason = io.open("/etc/hostname", "w")
if not file then
io.stderr:write(reason .. "\n")
io.stderr:write("failed to open for writing: ", reason, "\n")
return 1
else
file:write(args[1])
file:close()
os.setenv("HOSTNAME", args[1])
os.setenv("PS1", "$HOSTNAME:$PWD# ")
end
file:write(hostname)
file:close()
ops.update = true
else
local file = io.open("/etc/hostname")
if file then
io.write(file:read("*l"), "\n")
hostname = file:read("*l")
file:close()
else
io.stderr:write("Hostname not set\n")
return 1
end
end
if ops.update then
os.setenv("HOSTNAME_SEPARATOR", hostname and #hostname > 0 and ":" or "")
os.setenv("HOSTNAME", hostname)
elseif hostname then
print(hostname)
else
io.stderr:write("Hostname not set\n")
return 1
end

View File

@ -24,32 +24,23 @@ function os.getenv(varname)
local env = env()
if not varname then
return env
elseif varname == '#' then
return #env
end
return env[varname]
end
function os.setenv(varname, value)
checkArg(1, varname, "string", "number")
if value == nil then
env()[varname] = nil
else
local success, val = pcall(tostring, value)
if success then
env()[varname] = val
return val
else
return nil, val
end
if value ~= nil then
value = tostring(value)
end
env()[varname] = value
return value
end
function os.remove(...)
return fs.remove(...)
end
function os.rename(...)
return fs.rename(...)
end
os.remove = fs.remove
os.rename = fs.rename
function os.sleep(timeout)
checkArg(1, timeout, "number", "nil")

View File

@ -6,7 +6,7 @@ local function onComponentAvailable(_, componentType)
(componentType == "gpu" and component.isAvailable("screen"))
then
component.gpu.bind(component.screen.address)
local depth = 2^(component.gpu.getDepth())
local depth = math.floor(2^(component.gpu.getDepth()))
os.setenv("TERM", "term-"..depth.."color")
require("computer").pushSignal("gpu_bound", component.gpu.address, component.screen.address)
end

View File

@ -32,6 +32,9 @@ local function components_changed(ename, address, type)
-- recheck what kb to use
window.keyboard = nil
end
if (type == "screen" or type == "gpu") and not tty.isAvailable() then
computer.pushSignal("term_unavailable")
end
elseif (ename == "component_added" or ename == "component_available") and type == "keyboard" then
-- we need to clear the current terminals cached keyboard (if any) when
-- a new keyboard becomes available. This is in case the new keyboard was
@ -43,10 +46,6 @@ local function components_changed(ename, address, type)
-- primary keyboard is a valid keyboard (weird, in my opinion)
window.keyboard = nil
end
if (type == "screen" or type == "gpu") and not tty.isAvailable() then
computer.pushSignal("term_unavailable")
end
end
event.listen("component_removed", components_changed)

View File

@ -1,10 +1,3 @@
local shell = require("shell")
require("event").listen("init", function()
local file = io.open("/etc/hostname")
if file then
os.setenv("HOSTNAME", file:read("*l"))
os.setenv("PS1", "$HOSTNAME:$PWD# ")
file:close()
end
end)
-- there doesn't seem to be a reason to update $HOSTNAME after the init signal
-- as user space /etc/profile comes after this point anyways
loadfile("/bin/hostname.lua")("--update")

View File

@ -16,7 +16,7 @@ set HOME=/home
set IFS=\
set MANPATH=/usr/man:.
set PAGER=/bin/more
set PS1='$PWD # '
set PS1='$HOSTNAME$HOSTNAME_SEPARATOR$PWD # '
set PWD=/
set SHELL=/bin/sh
set LS_COLORS="{FILE=0xFFFFFF,DIR=0x66CCFF,LINK=0xFFAA00,['*.lua']=0x00FF00}"

View File

@ -20,7 +20,7 @@ function event.register(key, callback, interval, times)
local handler =
{
key = key,
times = times or math.huge,
times = times or 1,
callback = callback,
interval = interval or math.huge,
}
@ -155,7 +155,7 @@ function event.listen(name, callback)
return false
end
end
return event.register(name, callback)
return event.register(name, callback, math.huge, math.huge)
end
function event.onError(message)

View File

@ -193,8 +193,6 @@ function term.read(history, dobreak, hint, pwchar, filter)
inject_filter(handler, filter)
inject_mask(cursor, dobreak, pwchar)
-- todo, make blinking work from here
-- handler.blink or w.blink
return tty.read(handler, cursor)
end

View File

@ -63,6 +63,7 @@ local function tab_handler(handler, cursor)
if cache_size == 1 and cache.i == 0 then
-- there was only one solution, and the user is asking for the next
handler.cache = hints(cache[1], cursor.index + 1)
if not handler.cache then return end
handler.cache.i = -1
cache = handler.cache
cache_size = #cache

View File

@ -2,7 +2,7 @@ NAME
hostname - Display and modify hostname
SYNOPIS
hostname [NEW NAME]
hostname [NEW NAME] [--update]
EXAMPLES
hostname
@ -10,3 +10,6 @@ EXAMPLES
hostname test
Sets hostname of this computer to test
hostname --update
Updates $HOSTNAME by reading /etc/hostname in case it was set manually. Does not print to stdout

View File

@ -0,0 +1,17 @@
NAME
less - file viewer
SYNOPSIS
less [FILE]
DESCRIPTION
'less' is a filter for paging through text, as is 'more'. 'less', unlike 'more', support scroll in reverse
EXAMPLES
less example.txt
Displays the contents of file `example.txt`
find / | less
filter the output of `file /` through the 'less' pager
SEE ALSO
more

View File

@ -0,0 +1,8 @@
NAME
lshw - hardware viewer
SYNOPSIS
lshw
DESCRIPTION
'lshw' shows you the device information of your PC.

View File

@ -0,0 +1,9 @@
NAME
rmdir - remove empty directories
SYNOPIS
rmdir [DIRECTORY]
EXAMPLES
rmdir doc
Removes doc if and only if doc is an empty directory

View File

@ -0,0 +1,19 @@
NAME
set - set a environment variable
SYNOPSIS
set [VARIABLE]=[VALUE]
DESCRIPTION
set an environment variable. Quote [VALUE] to include spaces or non alphanumerics.
EXAMPLES
set
Shows all environment variables
set example="Hello World"; echo $example
Prints Hello World without quotes
set LS_COLORS="{FILE=0xFFFFFF,DIR=0x66CCFF,LINK=0xFFAA00,['*.lua']=0xFFFF00}"
Change ls colors, showing lua files in yellow. Note ls color defaults are set in /etc/profile
SEE ALSO
unset

View File

@ -0,0 +1,15 @@
NAME
unset - remove an environment variable
SYNOPSIS
unset [VARNAME]
DESCRIPTION
Removes an environment variable
EXAMPLES
unset some_variable
Removes the environment variable some_variable
SEE ALSO
set