mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2025-06-29 12:35:16 +00:00
main : Fix Ctrl+D/newline handling (#12951)
This restores the behavior from #491. This does not affect Ctrl+D's ability to terminate --multiline-input lines (#1040). This also actually implements #587: "If the user wants the text to end in a newline, this should be accomplished by explicitly adding a newline by using \ followed by return, then returning control by pressing return again." Fixes #12949
This commit is contained in:
@ -865,9 +865,22 @@ int main(int argc, char ** argv) {
|
|||||||
console::set_display(console::reset);
|
console::set_display(console::reset);
|
||||||
display = true;
|
display = true;
|
||||||
|
|
||||||
// Add tokens to embd only if the input buffer is non-empty
|
if (buffer.empty()) { // Ctrl+D on empty line exits
|
||||||
// Entering a empty line lets the user pass control back
|
LOG("EOF by user\n");
|
||||||
if (buffer.length() > 1) {
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buffer.back() == '\n') {
|
||||||
|
// Implement #587:
|
||||||
|
// If the user wants the text to end in a newline,
|
||||||
|
// this should be accomplished by explicitly adding a newline by using \ followed by return,
|
||||||
|
// then returning control by pressing return again.
|
||||||
|
buffer.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buffer.empty()) { // Enter key on empty line lets the user pass control back
|
||||||
|
LOG_DBG("empty line, passing control back\n");
|
||||||
|
} else { // Add tokens to embd only if the input buffer is non-empty
|
||||||
// append input suffix if any
|
// append input suffix if any
|
||||||
if (!params.input_suffix.empty() && !params.conversation_mode) {
|
if (!params.input_suffix.empty() && !params.conversation_mode) {
|
||||||
LOG_DBG("appending input suffix: '%s'\n", params.input_suffix.c_str());
|
LOG_DBG("appending input suffix: '%s'\n", params.input_suffix.c_str());
|
||||||
@ -915,8 +928,6 @@ int main(int argc, char ** argv) {
|
|||||||
|
|
||||||
n_remain -= line_inp.size();
|
n_remain -= line_inp.size();
|
||||||
LOG_DBG("n_remain: %d\n", n_remain);
|
LOG_DBG("n_remain: %d\n", n_remain);
|
||||||
} else {
|
|
||||||
LOG_DBG("empty line, passing control back\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
input_echo = false; // do not echo this again
|
input_echo = false; // do not echo this again
|
||||||
|
Reference in New Issue
Block a user