From 506200cf8b5c8419ce97d16dc8c50f4634e21ebe Mon Sep 17 00:00:00 2001 From: Bipin Yadav <83943505+bipinyadav3175@users.noreply.github.com> Date: Tue, 7 Apr 2026 00:24:06 +0530 Subject: [PATCH] cli: fix stripping of \n in multiline input (#21485) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- common/console.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/common/console.cpp b/common/console.cpp index a770416ab7..36f645f332 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);