From: Bipin Yadav Date: Mon, 6 Apr 2026 18:54:06 +0000 (+0530) Subject: cli: fix stripping of \n in multiline input (#21485) X-Git-Tag: upstream/0.0.8681 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=b9aa4f088150c8ec4274505b4b2b70f2fa5cef12;p=pkg%2Fggml%2Fsources%2Fllama.cpp cli: fix stripping of \n in multiline input (#21485) * 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 * Fix EditorConfig linter error --------- Co-authored-by: Sigbjørn Skjæret --- diff --git a/common/console.cpp b/common/console.cpp index a770416ab..36f645f33 100644 --- a/common/console.cpp +++ b/common/console.cpp @@ -700,13 +700,13 @@ namespace console { std::vector 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);