mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-15 10:21:45 -04:00
Miscellaneous tweaks to OpenOS (#2636)
* Parse Lua REPL inputs with an implicit "return " If an input does not start with a leading "=", this will parse the input with "return " appended and, if that fails, will parse as a normal statement. This allows for normal expressions to be entered into the repl (such as `2 + 2`) but does mean the parse errors for malformed inputs are confusing. For instance, `3 + ` will error at '3' rather than '<eof>'. * Do not insert into history if a duplicate This mimics the behaviour of shells such as bash or zsh, where whitespace-only lines are not entered into history, nor are ones equal to the previous input. This makes history navigation slightly easier.
This commit is contained in:
parent
e742af6112
commit
5b0c085c2d
@ -101,7 +101,10 @@ while tty.isAvailable() do
|
||||
if string.sub(command, 1, 1) == "=" then
|
||||
code, reason = load("return " .. string.sub(command, 2), "=stdin", "t", env)
|
||||
else
|
||||
code, reason = load(command, "=stdin", "t", env)
|
||||
code, reason = load("return " .. command, "=stdin", "t", env)
|
||||
if not code then
|
||||
code, reason = load(command, "=stdin", "t", env)
|
||||
end
|
||||
end
|
||||
if code then
|
||||
local result = table.pack(xpcall(code, debug.traceback))
|
||||
|
@ -32,11 +32,11 @@ function tty.key_down_handler(handler, cursor, char, code)
|
||||
elseif code == keys.enter or code == keys.numpadenter then
|
||||
cursor:move(math.huge)
|
||||
cursor:draw("\n")
|
||||
if #data > 0 then
|
||||
if data:find("%S") and data ~= handler[1] then
|
||||
table.insert(handler, 1, data)
|
||||
handler[(tonumber(os.getenv("HISTSIZE")) or 10)+1]=nil
|
||||
handler[0]=nil
|
||||
end
|
||||
handler[0]=nil
|
||||
return nil, data .. "\n"
|
||||
elseif code == keys.up or code == keys.down then
|
||||
local ni = handler.index + (code == keys.up and 1 or -1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user