@@ -865,9 +865,22 @@ int main(int argc, char ** argv) {
865865 console::set_display (console::reset);
866866 display = true ;
867867
868- // Add tokens to embd only if the input buffer is non-empty
869- // Entering a empty line lets the user pass control back
870- if (buffer.length () > 1 ) {
868+ if (buffer.empty ()) { // Ctrl+D on empty line exits
869+ LOG (" EOF by user\n " );
870+ break ;
871+ }
872+
873+ if (buffer.back () == ' \n ' ) {
874+ // Implement #587:
875+ // If the user wants the text to end in a newline,
876+ // this should be accomplished by explicitly adding a newline by using \ followed by return,
877+ // then returning control by pressing return again.
878+ buffer.pop_back ();
879+ }
880+
881+ if (buffer.empty ()) { // Enter key on empty line lets the user pass control back
882+ LOG_DBG (" empty line, passing control back\n " );
883+ } else { // Add tokens to embd only if the input buffer is non-empty
871884 // append input suffix if any
872885 if (!params.input_suffix .empty () && !params.conversation_mode ) {
873886 LOG_DBG (" appending input suffix: '%s'\n " , params.input_suffix .c_str ());
@@ -915,8 +928,6 @@ int main(int argc, char ** argv) {
915928
916929 n_remain -= line_inp.size ();
917930 LOG_DBG (" n_remain: %d\n " , n_remain);
918- } else {
919- LOG_DBG (" empty line, passing control back\n " );
920931 }
921932
922933 input_echo = false ; // do not echo this again
0 commit comments