fix cat when input is tty

This commit is contained in:
payonel 2017-09-11 08:09:08 -07:00
parent 9d544b3731
commit 0b767e6c7c

View File

@ -7,8 +7,10 @@ if #args == 0 then
args = {"-"}
end
local input_method, input_param = "read", 2048
for i = 1, #args do
local arg = args[i]
local arg = shell.resolve(args[i])
if fs.isDirectory(arg) then
io.stderr:write(string.format('cat %s: Is a directory\n', arg))
ec = 1
@ -16,15 +18,16 @@ for i = 1, #args do
local file, reason
if args[i] == "-" then
file, reason = io.stdin, "missing stdin"
input_method, input_param = "readLine", false
else
file, reason = fs.open(shell.resolve(args[i]))
file, reason = fs.open(arg)
end
if not file then
io.stderr:write(string.format("cat: %s: %s\n", args[i], tostring(reason)))
ec = 1
else
repeat
local chunk = file:read(2048)
local chunk = file[input_method](file, input_param)
if chunk then
io.write(chunk)
end