feat: implement interactive REPL with line editing and syntax highlighting in Wren

Replace the simple fgets-based REPL loop with a full-featured interactive Wren REPL module. The new implementation supports cursor movement via arrow keys, Ctrl-A/E for line start/end, Ctrl-C/D for exit/delete, character insertion/deletion, and syntax highlighting of the current input line. The C side now imports the "repl" Wren module and runs the libuv event loop instead of blocking on stdin reads.
This commit is contained in:
Bob Nystrom
2016-05-21 03:30:09 +00:00
parent 1de17224e8
commit 33c211f7c2
7 changed files with 1370 additions and 19 deletions
+3
View File
@@ -5,6 +5,7 @@
#include "io.wren.inc"
#include "os.wren.inc"
#include "repl.wren.inc"
#include "scheduler.wren.inc"
#include "timer.wren.inc"
@@ -162,6 +163,8 @@ static ModuleRegistry modules[] =
STATIC_METHOD("allArguments", processAllArguments)
END_CLASS
END_MODULE
MODULE(repl)
END_MODULE
MODULE(scheduler)
CLASS(Scheduler)
STATIC_METHOD("captureMethods_()", schedulerCaptureMethods)
+3 -19
View File
@@ -6,8 +6,6 @@
#include "scheduler.h"
#include "vm.h"
#define MAX_LINE_LENGTH 1024 // TODO: Something less arbitrary.
// The single VM instance that the CLI uses.
static WrenVM* vm;
@@ -259,23 +257,9 @@ int runRepl()
printf("\\\\/\"-\n");
printf(" \\_/ wren v%s\n", WREN_VERSION_STRING);
char line[MAX_LINE_LENGTH];
for (;;)
{
printf("> ");
if (!fgets(line, MAX_LINE_LENGTH, stdin))
{
printf("\n");
break;
}
// TODO: Handle failure.
wrenInterpret(vm, line);
// TODO: Automatically print the result of expressions.
}
wrenInterpret(vm, "import \"repl\"\n");
uv_run(loop, UV_RUN_DEFAULT);
freeVM();