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 0e8f85f6a..f5fde9c62 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/bin/sh.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/bin/sh.lua @@ -12,7 +12,8 @@ end shell.prime() local update_gpu = io.output().tty -local interactive = io.input().tty +local needs_profile = io.input().tty +local input_handler = {hint = sh.hintHandler} if #args == 0 then while true do @@ -20,14 +21,13 @@ if #args == 0 then while not tty.isAvailable() do event.pull("term_available") end - if interactive == true then -- first time run AND interactive - interactive = 0 - tty.setReadHandler({hint = sh.hintHandler}) + if needs_profile then -- first time run AND interactive + needs_profile = nil dofile("/etc/profile.lua") end io.write(sh.expand(os.getenv("PS1") or "$ ")) end - local command = io.read() + local command = tty:read(input_handler) if command then command = text.trim(command) if command == "exit" then 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 b93c01ed4..9fc3df6d1 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/etc/profile.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/etc/profile.lua @@ -3,8 +3,10 @@ local tty = require("tty") local fs = require("filesystem") if tty.isAvailable() then - tty:write("\27[40m\27[37m") - tty.clear() + if io.stdout.tty then + io.write("\27[40m\27[37m") + tty.clear() + end tty.setCursorBlink(true) end dofile("/etc/motd") diff --git a/src/main/resources/assets/opencomputers/loot/openos/lib/core/lua_shell.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/core/lua_shell.lua index 82f4dbe32..ad7997a63 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/lib/core/lua_shell.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/core/lua_shell.lua @@ -68,7 +68,7 @@ local function findKeys(t, r, prefix, name) end end -tty.setReadHandler({hint = function(line, index) +local read_handler = {hint = function(line, index) line = (line or "") local tail = line:sub(index) line = line:sub(1, index - 1) @@ -85,7 +85,7 @@ tty.setReadHandler({hint = function(line, index) table.insert(hints, key .. tail) end return hints -end}) +end} io.write("\27[37m".._VERSION .. " Copyright (C) 1994-2017 Lua.org, PUC-Rio\n") io.write("\27[33mEnter a statement and hit enter to evaluate it.\n") @@ -94,7 +94,7 @@ io.write("Press Ctrl+D to exit the interpreter.\n\27[37m") while tty.isAvailable() do io.write(env._PROMPT) - local command = io.read() + local command = tty:read(read_handler) if not command then -- eof return end diff --git a/src/main/resources/assets/opencomputers/loot/openos/lib/filesystem.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/filesystem.lua index 2171f4279..2d6d7740d 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/lib/filesystem.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/filesystem.lua @@ -24,7 +24,6 @@ end local function saveConfig() local root = filesystem.get("/") if root and not root.isReadOnly() then - filesystem.makeDirectory("/etc") local f = filesystem.open("/etc/filesystem.cfg", "w") if f then f:write("autorun="..tostring(isAutorunEnabled)) diff --git a/src/main/resources/assets/opencomputers/loot/openos/lib/term.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/term.lua index 207c681c0..3ce1df9ff 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/lib/term.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/term.lua @@ -194,9 +194,6 @@ function term.write(value, wrap) end function term.read(history, dobreak, hint, pwchar, filter) - if not io.stdin.tty then - return io.read("*L") - end history = history or {} local handler = history handler.hint = handler.hint or hint 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 5b9708cac..b860dbb77 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/lib/tty.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/tty.lua @@ -3,7 +3,6 @@ local event = require("event") local kb = require("keyboard") local component = require("component") local computer = require("computer") -local process = require("process") local keys = kb.keys local tty = {} @@ -19,11 +18,6 @@ tty.window = tty.internal = {} -function tty.setReadHandler(handler) - checkArg(1, handler, "table") - process.info().data.handler = handler -end - function tty.key_down_handler(handler, cursor, char, code) local data = cursor.data local c = false @@ -268,15 +262,17 @@ function tty.internal.build_vertical_reader() end -- read n bytes, n is unused -function tty.read(_, handler, cursor) +function tty.read(self, handler, cursor) checkArg(1, handler, "table", "number") checkArg(2, cursor, "table", "nil") - if type(handler) == "number" then - -- standard read as a stream, asking for n bytes - handler = process.info().data.handler or {} + if not io.stdin.tty or io.stdin.stream ~= self then + return io.stdin:readLine(false) end + if type(handler) ~= "table" then + handler = {} + end handler.index = 0 cursor = cursor or tty.internal.build_vertical_reader() @@ -324,7 +320,10 @@ function tty.setCursor(x, y) window.x, window.y = x, y end -function tty.write(_, value) +function tty.write(self, value) + if not io.stdout.tty or io.stdout.stream ~= self then + return io.write(value) + end local gpu = tty.gpu() if not gpu then return