]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
cli: fix stripping of \n in multiline input (#21485) upstream/0.0.8681
authorBipin Yadav <redacted>
Mon, 6 Apr 2026 18:54:06 +0000 (00:24 +0530)
committerGitHub <redacted>
Mon, 6 Apr 2026 18:54:06 +0000 (20:54 +0200)
* llama-cli: fix stripping of \n in multiline input

* Change & string to string_view

* Apply suggestions from code review

Co-authored-by: Sigbjørn Skjæret <redacted>
* Fix EditorConfig linter error

---------

Co-authored-by: Sigbjørn Skjæret <redacted>
common/console.cpp

index a770416ab7a9f9b102cf881800adf2ef6df03030..36f645f3329e3b8bd58a6309055f0f3ea186a8f9 100644 (file)
@@ -700,13 +700,13 @@ namespace console {
         std::vector<std::string> entries;
         size_t viewing_idx = SIZE_MAX;
         std::string backup_line; // current line before viewing history
-        void add(const std::string & line) {
+        void add(std::string_view line) {
             if (line.empty()) {
                 return;
             }
             // avoid duplicates with the last entry
             if (entries.empty() || entries.back() != line) {
-                entries.push_back(line);
+                entries.emplace_back(line);
             }
             // also clear viewing state
             end_viewing();
@@ -1031,11 +1031,12 @@ namespace console {
 
         if (!end_of_stream && !line.empty()) {
             // remove the trailing newline for history storage
+            std::string_view hline = line;
             if (!line.empty() && line.back() == '\n') {
-                line.pop_back();
+                hline.remove_suffix(1);
             }
             // TODO: maybe support multiline history entries?
-            history.add(line);
+            history.add(hline);
         }
 
         fflush(out);