1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:18:12 +00:00

LibLine: Change get_line to return a Result<String, Error>

This fixes a bunch of FIXME's in LibLine.
Also handles the case where read() would read zero bytes in vt_dsr() and
effectively block forever by erroring out.

Fixes #2370
This commit is contained in:
AnotherTest 2020-05-25 16:57:07 +04:30 committed by Andreas Kling
parent 1e30ef239b
commit bc9013f706
7 changed files with 87 additions and 22 deletions

View file

@ -67,6 +67,7 @@ static bool s_dump_ast = false;
static bool s_print_last_result = false;
static OwnPtr<Line::Editor> s_editor;
static int s_repl_line_level = 0;
static bool s_fail_repl = false;
static String prompt_for_level(int level)
{
@ -85,7 +86,14 @@ String read_next_piece()
StringBuilder piece;
do {
String line = s_editor->get_line(prompt_for_level(s_repl_line_level));
auto line_result = s_editor->get_line(prompt_for_level(s_repl_line_level));
if (line_result.is_error()) {
s_fail_repl = true;
return "";
}
auto& line = line_result.value();
s_editor->add_to_history(line);
piece.append(line);
@ -369,7 +377,7 @@ JS::Value ReplObject::load_file(JS::Interpreter& interpreter)
void repl(JS::Interpreter& interpreter)
{
while (true) {
while (!s_fail_repl) {
String piece = read_next_piece();
if (piece.is_empty())
continue;