From 3ca2a397dd9adeab692a1a1160996bf6ec4caba3 Mon Sep 17 00:00:00 2001 From: q66 Date: Wed, 31 Aug 2016 22:21:00 +0100 Subject: [PATCH] use ostd stdin --- Makefile | 2 +- repl.cc | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index b8b37d3f..6bfd3aab 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ library: $(LIBCS_LIB) $(LIBCS_LIB): $(LIBCS_OBJ) ar rcs $(LIBCS_LIB) $(LIBCS_OBJ) -repl: $(LIBCS_LIB) +repl: $(LIBCS_LIB) repl.cc $(CXX) $(CXXFLAGS) $(LIBCS_CXXFLAGS) $(LDFLAGS) repl.cc -o repl $(LIBCS_LIB) clean: diff --git a/repl.cc b/repl.cc index 37e45fe5..50a13098 100644 --- a/repl.cc +++ b/repl.cc @@ -10,25 +10,26 @@ ostd::ConstCharRange version = "CubeScript 0.0.1 (REPL mode) Copyright (C) 2016 Daniel \"q66\" Kolesa"; CsSvar *prompt = nullptr; -static ostd::Maybe read_line() { +static ostd::String read_line() { ostd::write(prompt->get_value()); - char buf[512]; - if (fgets(buf, sizeof(buf), stdin)) { - return ostd::String(buf); + auto app = ostd::appender(); + /* i really need to implement some sort of get_line for ostd streams */ + for (char c = ostd::in.getchar(); c && (c != '\n'); c = ostd::in.getchar()) { + app.put(c); } - return ostd::nothing; + return ostd::move(app.get()); } static void do_tty(CsState &cs) { ostd::writeln(version); for (;;) { auto line = read_line(); - if (!line) { + if (line.empty()) { continue; } CsValue ret; ret.set_null(); - cs.run_ret(line.value(), ret); + cs.run_ret(line, ret); if (ret.get_type() != CsValueType::null) { ostd::writeln(ret.get_str()); }