mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-14 09:46:53 -04:00
fix cat when input is tty
This commit is contained in:
parent
9d544b3731
commit
0b767e6c7c
@ -7,8 +7,10 @@ if #args == 0 then
|
|||||||
args = {"-"}
|
args = {"-"}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local input_method, input_param = "read", 2048
|
||||||
|
|
||||||
for i = 1, #args do
|
for i = 1, #args do
|
||||||
local arg = args[i]
|
local arg = shell.resolve(args[i])
|
||||||
if fs.isDirectory(arg) then
|
if fs.isDirectory(arg) then
|
||||||
io.stderr:write(string.format('cat %s: Is a directory\n', arg))
|
io.stderr:write(string.format('cat %s: Is a directory\n', arg))
|
||||||
ec = 1
|
ec = 1
|
||||||
@ -16,15 +18,16 @@ for i = 1, #args do
|
|||||||
local file, reason
|
local file, reason
|
||||||
if args[i] == "-" then
|
if args[i] == "-" then
|
||||||
file, reason = io.stdin, "missing stdin"
|
file, reason = io.stdin, "missing stdin"
|
||||||
|
input_method, input_param = "readLine", false
|
||||||
else
|
else
|
||||||
file, reason = fs.open(shell.resolve(args[i]))
|
file, reason = fs.open(arg)
|
||||||
end
|
end
|
||||||
if not file then
|
if not file then
|
||||||
io.stderr:write(string.format("cat: %s: %s\n", args[i], tostring(reason)))
|
io.stderr:write(string.format("cat: %s: %s\n", args[i], tostring(reason)))
|
||||||
ec = 1
|
ec = 1
|
||||||
else
|
else
|
||||||
repeat
|
repeat
|
||||||
local chunk = file:read(2048)
|
local chunk = file[input_method](file, input_param)
|
||||||
if chunk then
|
if chunk then
|
||||||
io.write(chunk)
|
io.write(chunk)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user