From f00c2dd6a26295ff0cfdd4ffdb2d6330e3059d9a Mon Sep 17 00:00:00 2001 From: payonel Date: Wed, 19 Jul 2017 22:37:04 -0700 Subject: [PATCH 1/2] simplify tty check slightly and add comment that tty should not be used directly by user code maybe i should just move tty to /lib/core --- .../assets/opencomputers/loot/openos/lib/tty.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/resources/assets/opencomputers/loot/openos/lib/tty.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/tty.lua index b860dbb77..131975a8a 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/lib/tty.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/tty.lua @@ -261,12 +261,12 @@ function tty.internal.build_vertical_reader() } end --- read n bytes, n is unused -function tty.read(self, handler, cursor) +-- PLEASE do not use this method directly, use io.read or tty.read +function tty.read(_, handler, cursor) checkArg(1, handler, "table", "number") checkArg(2, cursor, "table", "nil") - if not io.stdin.tty or io.stdin.stream ~= self then + if not io.stdin.tty then return io.stdin:readLine(false) end @@ -320,8 +320,9 @@ function tty.setCursor(x, y) window.x, window.y = x, y end -function tty.write(self, value) - if not io.stdout.tty or io.stdout.stream ~= self then +-- PLEASE do not use this method directly, use io.write or term.write +function tty.write(_, value) + if not io.stdout.tty then return io.write(value) end local gpu = tty.gpu() From 2a178f6d41395fc564d1c4e0ef17d264f9eae5b1 Mon Sep 17 00:00:00 2001 From: payonel Date: Tue, 8 Aug 2017 18:44:32 -0700 Subject: [PATCH 2/2] fix quiet /bin/source quiet mode in /bin/source was a mess -- making .shrc scripts not able to print. Also, a lot of the /bin/sh arg parsing code has traditionally been over complicated. cleaned that up as well thanks to old code that expected strings in the args having been removed some time ago --- .../assets/opencomputers/loot/openos/bin/sh.lua | 10 +++------- .../assets/opencomputers/loot/openos/bin/source.lua | 5 +---- .../assets/opencomputers/loot/openos/etc/profile.lua | 2 +- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/main/resources/assets/opencomputers/loot/openos/bin/sh.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/sh.lua index f5fde9c62..01f627e4c 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/bin/sh.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/bin/sh.lua @@ -4,14 +4,10 @@ local tty = require("tty") local text = require("text") local sh = require("sh") -local input = table.pack(...) -local args = shell.parse(select(3,table.unpack(input))) -if input[2] then - table.insert(args, 1, input[2]) -end +local args, options = shell.parse(...) shell.prime() -local update_gpu = io.output().tty +local update_gpu = io.output().tty and not options.c local needs_profile = io.input().tty local input_handler = {hint = sh.hintHandler} @@ -38,7 +34,7 @@ if #args == 0 then io.stderr:write((reason and tostring(reason) or "unknown error") .. "\n") end end - elseif not interactive then + else return -- eof end if update_gpu and tty.getCursor() > 1 then diff --git a/src/main/resources/assets/opencomputers/loot/openos/bin/source.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/source.lua index 2b1cc20ec..8286ad1ed 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/bin/source.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/bin/source.lua @@ -24,9 +24,6 @@ local source_data = process.list[source_proc].data source_data.aliases = current_data.aliases -- hacks to propogate sub shell env changes source_data.vars = current_data.vars source_data.io[0] = file -- set stdin to the file -if options.q then - source_data.io[1] = {tty=false,write=function()end} -- set stdin to the file -end -process.internal.continue(source_proc) +process.internal.continue(source_proc, "-c") file:close() -- should have closed when the process closed, but just to be sure diff --git a/src/main/resources/assets/opencomputers/loot/openos/etc/profile.lua b/src/main/resources/assets/opencomputers/loot/openos/etc/profile.lua index 9fc3df6d1..76c7ecca3 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/etc/profile.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/etc/profile.lua @@ -40,5 +40,5 @@ shell.setWorkingDirectory(os.getenv("HOME")) local home_shrc = shell.resolve(".shrc") if fs.exists(home_shrc) then - loadfile(shell.resolve("source", "lua"))(home_shrc, "-q") + loadfile(shell.resolve("source", "lua"))(home_shrc) end