From a431a9ca4cb6c46a3e71c825da59d3e2a76fe1da Mon Sep 17 00:00:00 2001 From: RDW Date: Fri, 9 Feb 2024 18:30:14 +0100 Subject: [PATCH 1/2] Runtime: Add some usage instructions to the CLI's REPL --- Runtime/evo.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Runtime/evo.lua b/Runtime/evo.lua index ffb43446..fe55b429 100644 --- a/Runtime/evo.lua +++ b/Runtime/evo.lua @@ -356,6 +356,12 @@ function evo.evaluateChunk(commandName, argv) if not luaCodeToEvaluate then printf(transform.brightGreen("Welcome to Evo.lua %s (REPL powered by LuaJIT)"), EVO_VERSION) + printf( + "Evaluating code in %s mode. To exit, press %s or type %s.", + transform.brightMagenta("live edit"), + transform.brightYellow("CTRL+C"), + transform.brightYellow("os.exit()") + ) runtime.bindings.runtime_repl_start() return end From 5fcb091c3dd75e9655bde16bab6f2138828a7ab8 Mon Sep 17 00:00:00 2001 From: RDW Date: Fri, 9 Feb 2024 18:33:52 +0100 Subject: [PATCH 2/2] Refactor: Turn the REPL usage info into a message string Makes it far easier to test and consistent with the rest of the code. --- Runtime/evo.lua | 19 ++++++++++++------- Tests/snapshot-test.lua | 9 ++++++--- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Runtime/evo.lua b/Runtime/evo.lua index fe55b429..18baf3d8 100644 --- a/Runtime/evo.lua +++ b/Runtime/evo.lua @@ -101,6 +101,16 @@ A list of supported profiling modes and their combinations can be found here: %s transform.brightYellow("LUAJIT_PROFILEFILE=results.txt evo profile script.lua ..."), transform.brightBlue("https://luajit.org/ext_profiler.html") ), + REPL_WELCOME_TEXT = format( + transform.brightGreen("Welcome to Evo.lua %s (REPL powered by LuaJIT)"), + EVO_VERSION + ), + REPL_USAGE_INSTRUCTIONS = format( + "Evaluating code in %s mode. To exit, press %s or type %s.", + transform.brightMagenta("live edit"), + transform.brightYellow("CTRL+C"), + transform.brightYellow("os.exit()") + ), }, } @@ -355,13 +365,8 @@ function evo.evaluateChunk(commandName, argv) local luaCodeToEvaluate = unpack(argv) if not luaCodeToEvaluate then - printf(transform.brightGreen("Welcome to Evo.lua %s (REPL powered by LuaJIT)"), EVO_VERSION) - printf( - "Evaluating code in %s mode. To exit, press %s or type %s.", - transform.brightMagenta("live edit"), - transform.brightYellow("CTRL+C"), - transform.brightYellow("os.exit()") - ) + print(evo.messageStrings.REPL_WELCOME_TEXT) + print(evo.messageStrings.REPL_USAGE_INSTRUCTIONS) runtime.bindings.runtime_repl_start() return end diff --git a/Tests/snapshot-test.lua b/Tests/snapshot-test.lua index e15ceb05..f7a0023c 100644 --- a/Tests/snapshot-test.lua +++ b/Tests/snapshot-test.lua @@ -112,9 +112,12 @@ local testCases = { .. SHELL_ESCAPE_SYMBOL .. " | evo eval", onExit = function(observedOutput, status, terminationReason, exitCodeOrSignalID) - local welcomeText = - transform.brightGreen(format("Welcome to Evo.lua %s (REPL powered by LuaJIT)", EVO_VERSION)) - local expectedOutput = welcomeText .. "\n" .. "> Hello from the REPL!" .. "\n" + local expectedOutput = evo.messageStrings.REPL_WELCOME_TEXT + .. "\n" + .. evo.messageStrings.REPL_USAGE_INSTRUCTIONS + .. "\n" + .. "> Hello from the REPL!" + .. "\n" assertEquals(observedOutput, expectedOutput) assertExitFailure(observedOutput, status, terminationReason, exitCodeOrSignalID) end,