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();
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);