diff --git a/modules/interpreter/src/cpp/Evaluator.cpp b/modules/interpreter/src/cpp/Evaluator.cpp index feb933b9ff..dd2e2e7f17 100644 --- a/modules/interpreter/src/cpp/Evaluator.cpp +++ b/modules/interpreter/src/cpp/Evaluator.cpp @@ -53,6 +53,7 @@ Evaluator::Evaluator(Context* aContext, Interface* aInterface, bool haveEventsLo depth = 0; _haveEventsLoop = haveEventsLoop; io = aInterface; + defaultInterface = aInterface; InCLI = false; bpActive = false; clearStacks(); @@ -204,6 +205,13 @@ Evaluator::getInterface() { return io; } +//====================================================================== +// Returns the default (interactive) interface. +Interface* +Evaluator::getDefaultInterface() +{ + return defaultInterface ? defaultInterface : io; +} //============================================================================= // Returns the ID of the evaluator. size_t @@ -604,7 +612,19 @@ Evaluator::debugCLI() if (haveEventsLoop()) { ProcessEventsDynamicFunctionWithoutWait(); } + // If the current interface is not the default (interactive) one + // (e.g., during evalc), temporarily restore the interactive interface + // so that the debug CLI can read user input. + Interface* savedIO = nullptr; + if (io != defaultInterface && defaultInterface != nullptr) { + savedIO = io; + io = defaultInterface; + } evalCLI(); + // Restore the previous interface after the debug session + if (savedIO != nullptr) { + io = savedIO; + } // After evalCLI() returns, check if debug mode should be exited: // - If a debug command set bpActive to false, keep it false // - If script finished without active breakpoint, exit debug mode diff --git a/modules/interpreter/src/include/Evaluator.hpp b/modules/interpreter/src/include/Evaluator.hpp index 8dee7a8c7c..3b24886fd6 100644 --- a/modules/interpreter/src/include/Evaluator.hpp +++ b/modules/interpreter/src/include/Evaluator.hpp @@ -89,6 +89,13 @@ class NLSINTERPRETER_IMPEXP Evaluator * The interface for I/O */ Interface* io; + /** + * The default (interactive) interface, saved at construction. + * Used to restore interactive I/O during debug sessions + * when the current interface has been temporarily replaced + * (e.g., by evalc). + */ + Interface* defaultInterface = nullptr; int exitCode = 0; @@ -318,6 +325,8 @@ class NLSINTERPRETER_IMPEXP Evaluator setInterface(Interface* _io); Interface* getInterface(); + Interface* + getDefaultInterface(); /** * Process an AST to form an lvalue in an assignment statement. * The AST looks like: