Skip to content

Commit 13a9504

Browse files
committed
fix: fix debug command output
1 parent be88033 commit 13a9504

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

src/legacy/main/BuiltinCommands.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#include "ll/api/command/CommandHandle.h"
66
#include "ll/api/command/CommandRegistrar.h"
77
#include "ll/api/io/Logger.h"
8-
#include "ll/api/service/Bedrock.h"
98
#include "lse/Entry.h"
9+
#include "lse/api/DirectFormatter.h"
1010
#include "mc/server/commands/CommandOutput.h"
1111
#include "mc/server/commands/CommandPermissionLevel.h"
1212

@@ -16,8 +16,10 @@
1616
#include "PythonHelper.h"
1717
#endif
1818

19-
extern bool isInConsoleDebugMode;
20-
extern ScriptEngine* debugEngine;
19+
extern bool isInConsoleDebugMode;
20+
extern ScriptEngine* debugEngine;
21+
std::shared_ptr<ll::io::Logger> debugLogger = ll::io::LoggerRegistry::getInstance().getOrCreate("LSEDEBUG");
22+
inline void printConsoleSymbol() { debugLogger->info("> "); }
2123

2224
bool ProcessDebugEngine(const std::string& cmd) {
2325
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_PYTHON
@@ -26,7 +28,7 @@ bool ProcessDebugEngine(const std::string& cmd) {
2628
#endif
2729
if (isInConsoleDebugMode) {
2830
EngineScope enter(debugEngine);
29-
auto& logger = lse::LegacyScriptEngine::getInstance().getSelf().getLogger();
31+
auto& logger = lse::LegacyScriptEngine::getInstance().getSelf().getLogger();
3032
try {
3133
if (cmd == "stop" || cmd == LLSE_DEBUG_CMD) {
3234
return true;
@@ -35,11 +37,11 @@ bool ProcessDebugEngine(const std::string& cmd) {
3537
std::ostringstream sout;
3638
PrintValue(sout, result);
3739
logger.info(sout.str());
38-
std::cout << "> " << std::flush;
40+
printConsoleSymbol();
3941
}
40-
} catch (Exception& e) {
41-
ll::error_utils::printException(e, logger);
42-
std::cout << "> " << std::flush;
42+
} catch (...) {
43+
ll::error_utils::printCurrentException(logger);
44+
printConsoleSymbol();
4345
}
4446
return false;
4547
}
@@ -51,6 +53,7 @@ struct EngineDebugCommand {
5153
};
5254

5355
void RegisterDebugCommand() {
56+
debugLogger->setFormatter(ll::makePolymorphic<lse::io::DirectFormatter>());
5457
auto& command = ll::command::CommandRegistrar::getInstance()
5558
.getOrCreateCommand(LLSE_DEBUG_CMD, "Debug LegacyScriptEngine", CommandPermissionLevel::Owner);
5659
command.overload<EngineDebugCommand>().optional("eval").execute(
@@ -63,8 +66,8 @@ void RegisterDebugCommand() {
6366
std::ostringstream sout;
6467
PrintValue(sout, result);
6568
output.success(sout.str());
66-
} catch (Exception& e) {
67-
ll::error_utils::printException(e, logger);
69+
} catch (...) {
70+
ll::error_utils::printCurrentException(logger);
6871
}
6972
} else {
7073
if (isInConsoleDebugMode) {
@@ -75,7 +78,7 @@ void RegisterDebugCommand() {
7578
// StartDebug
7679
logger.info("Debug mode begins");
7780
isInConsoleDebugMode = true;
78-
std::cout << "> " << std::flush;
81+
printConsoleSymbol();
7982
}
8083
}
8184
}

src/lse/api/DirectFormatter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "lse/api/DirectFormatter.h"
2+
3+
namespace lse::io {
4+
void DirectFormatter::format(const ll::io::LogMessageView& view, std::string& buffer) const noexcept {
5+
buffer = view.msg;
6+
}
7+
} // namespace lse::io

src/lse/api/DirectFormatter.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "ll/api/io/Formatter.h"
2+
3+
namespace lse::io {
4+
using namespace ll::io;
5+
class DirectFormatter : public Formatter {
6+
public:
7+
DirectFormatter() = default;
8+
virtual ~DirectFormatter() override = default;
9+
10+
void format(LogMessageView const& view, std::string& buffer) const noexcept override;
11+
};
12+
13+
} // namespace lse::io

0 commit comments

Comments
 (0)