]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
Exit from interactive mode if input stream is bad (#491)
authorHarald Fernengel <redacted>
Sun, 26 Mar 2023 05:25:46 +0000 (07:25 +0200)
committerGitHub <redacted>
Sun, 26 Mar 2023 05:25:46 +0000 (08:25 +0300)
Allow exiting the interactive prompt also with CTRL-D on Unix and CTRL-Z
on Windows.

examples/main/main.cpp

index 9af8a74056c87a0851a95d4fa4f665aabbca486f..e9478d5413f27a844b5f1fc7ffadbbff3ea97bee 100644 (file)
@@ -450,7 +450,10 @@ int main(int argc, char ** argv) {
                 std::string line;
                 bool another_line = true;
                 do {
-                    std::getline(std::cin, line);
+                    if (!std::getline(std::cin, line)) {
+                        // input stream is bad or EOF received
+                        return 0;
+                    }
                     if (line.empty() || line.back() != '\\') {
                         another_line = false;
                     } else {