From 0b767e6c7ce553c6bf98f914e4fa42c95d072e2d Mon Sep 17 00:00:00 2001 From: payonel Date: Mon, 11 Sep 2017 08:09:08 -0700 Subject: [PATCH] fix cat when input is tty --- .../assets/opencomputers/loot/openos/bin/cat.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/resources/assets/opencomputers/loot/openos/bin/cat.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/cat.lua index c1e9818f8..fafe5f0e9 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/bin/cat.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/bin/cat.lua @@ -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