Skip to content

Commit 506200c

Browse files
bipinyadav3175CISC
andauthored
cli: fix stripping of \n in multiline input (ggml-org#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 <sigbjorn.skjaeret@scala.com> * Fix EditorConfig linter error --------- Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com>
1 parent 15f786e commit 506200c

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

common/console.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -700,13 +700,13 @@ namespace console {
700700
std::vector<std::string> entries;
701701
size_t viewing_idx = SIZE_MAX;
702702
std::string backup_line; // current line before viewing history
703-
void add(const std::string & line) {
703+
void add(std::string_view line) {
704704
if (line.empty()) {
705705
return;
706706
}
707707
// avoid duplicates with the last entry
708708
if (entries.empty() || entries.back() != line) {
709-
entries.push_back(line);
709+
entries.emplace_back(line);
710710
}
711711
// also clear viewing state
712712
end_viewing();
@@ -1031,11 +1031,12 @@ namespace console {
10311031

10321032
if (!end_of_stream && !line.empty()) {
10331033
// remove the trailing newline for history storage
1034+
std::string_view hline = line;
10341035
if (!line.empty() && line.back() == '\n') {
1035-
line.pop_back();
1036+
hline.remove_suffix(1);
10361037
}
10371038
// TODO: maybe support multiline history entries?
1038-
history.add(line);
1039+
history.add(hline);
10391040
}
10401041

10411042
fflush(out);

0 commit comments

Comments
 (0)