[web] Support multiline mode in web REPL
This commit is contained in:
parent
1ecd0a6912
commit
068da2fb41
|
@ -274,16 +274,6 @@ const char* nasal_repl_eval(void* context, const char* line) {
|
||||||
return ctx->last_error.c_str();
|
return ctx->last_error.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// // Process output
|
|
||||||
// auto lines = split_string(result, '\n');
|
|
||||||
// if (!lines.empty()) {
|
|
||||||
// // Remove empty lines from the end
|
|
||||||
// while (!lines.empty() && lines.back().empty()) {
|
|
||||||
// lines.pop_back();
|
|
||||||
// }
|
|
||||||
// result = join_string(lines, "\n");
|
|
||||||
// }
|
|
||||||
|
|
||||||
ctx->last_result = result;
|
ctx->last_result = result;
|
||||||
return ctx->last_result.c_str();
|
return ctx->last_result.c_str();
|
||||||
|
|
||||||
|
@ -296,21 +286,28 @@ const char* nasal_repl_eval(void* context, const char* line) {
|
||||||
|
|
||||||
int nasal_repl_is_complete(void* context, const char* line) {
|
int nasal_repl_is_complete(void* context, const char* line) {
|
||||||
auto* ctx = static_cast<WebReplContext*>(context);
|
auto* ctx = static_cast<WebReplContext*>(context);
|
||||||
std::string input_line(line);
|
|
||||||
|
|
||||||
// Handle empty input or single semicolon
|
if (!ctx->initialized) {
|
||||||
if (input_line.empty() || input_line == ";") {
|
return -1; // Error state
|
||||||
return 1; // Input is complete
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the new line to source
|
// Handle empty input
|
||||||
ctx->source.push_back(input_line);
|
if (!line || strlen(line) == 0) {
|
||||||
|
return 0; // Complete
|
||||||
// Use existing REPL check_need_more_input functionality
|
}
|
||||||
bool needs_more = ctx->repl_instance->check_need_more_input(ctx->source);
|
|
||||||
|
// Handle REPL commands
|
||||||
ctx->source.pop_back();
|
if (line[0] == '.') {
|
||||||
return needs_more;
|
return 0; // Commands are always complete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a temporary source vector with existing source plus new line
|
||||||
|
std::vector<std::string> temp_source = ctx->source;
|
||||||
|
temp_source.push_back(line);
|
||||||
|
|
||||||
|
// Use the REPL's check_need_more_input method
|
||||||
|
int result = ctx->repl_instance->check_need_more_input(temp_source);
|
||||||
|
return result; // Ensure a return value is provided
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add this function to expose version info
|
// Add this function to expose version info
|
||||||
|
|
Loading…
Reference in New Issue