Clear gets an option to reset the palette (#582)

Fixes #555.
This commit is contained in:
Luca 2020-11-17 13:53:20 +01:00 committed by GitHub
parent f194f4fa3a
commit d2a1a00dc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 3 deletions

View File

@ -1 +1,6 @@
clear clears the screen.
clear clears the screen and/or resets the palette.
ex:
"clear" clears the screen, but keeps the palette.
"clear screen" does the same as "clear"
"clear palette" resets the palette, but doesn't clear the screen
"clear all" clears the screen and resets the palette

View File

@ -1,2 +1,33 @@
term.clear()
term.setCursorPos(1, 1)
local tArgs = { ... }
local function printUsage()
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usages:")
print(programName)
print(programName .. " screen")
print(programName .. " palette")
print(programName .. " all")
end
local function clear()
term.clear()
term.setCursorPos(1, 1)
end
local function resetPalette()
for i = 0, 15 do
term.setPaletteColour(math.pow(2, i), term.nativePaletteColour(math.pow(2, i)))
end
end
local sCommand = tArgs[1] or "screen"
if sCommand == "screen" then
clear()
elseif sCommand == "palette" then
resetPalette()
elseif sCommand == "all" then
clear()
resetPalette()
else
printUsage()
end

View File

@ -49,6 +49,7 @@ end
shell.setCompletionFunction("rom/programs/alias.lua", completion.build(nil, completion.program))
shell.setCompletionFunction("rom/programs/cd.lua", completion.build(completion.dir))
shell.setCompletionFunction("rom/programs/clear.lua", completion.build({ completion.choice, { "screen", "palette", "all" } }))
shell.setCompletionFunction("rom/programs/copy.lua", completion.build(
{ completion.dirOrFile, true },
completion.dirOrFile