@@ -513,11 +513,30 @@ class Interface extends InterfaceConstructor {
513513
514514 if ( this [ kIsMultiline ] ) {
515515 const lines = StringPrototypeSplit ( this . line , '\n' ) ;
516- // Write first line with normal prompt
517- this [ kWriteToOutput ] ( this [ kPrompt ] + lines [ 0 ] ) ;
516+ const terminalRows = this . output ?. rows ;
517+ let startLine = 0 ;
518+ let endLine = lineRows ;
519+
520+ const isTallerThanTerminalHeight = terminalRows && ( lineRows >= terminalRows ) ;
521+
522+ if ( isTallerThanTerminalHeight ) {
523+ const firstVisibleLineIdx = lineRows - terminalRows ;
524+
525+ if ( cursorPos . rows > firstVisibleLineIdx ) {
526+ startLine = firstVisibleLineIdx ;
527+ } else {
528+ startLine = cursorPos . rows ;
529+ endLine = cursorPos . rows + terminalRows - 1 ;
530+ }
531+ }
532+
533+ if ( startLine === 0 ) {
534+ this [ kWriteToOutput ] ( this [ kPrompt ] + lines [ 0 ] ) ;
535+ startLine ++ ;
536+ }
518537
519538 // For continuation lines, add the "|" prefix
520- for ( let i = 1 ; i < lines . length ; i ++ ) {
539+ for ( let i = startLine ; i <= endLine ; i ++ ) {
521540 this [ kWriteToOutput ] ( `\n${ kMultilinePrompt . description } ` + lines [ i ] ) ;
522541 }
523542 } else {
@@ -1156,10 +1175,16 @@ class Interface extends InterfaceConstructor {
11561175
11571176 [ kMoveUpOrHistoryPrev ] ( ) {
11581177 const cursorPos = this . getCursorPos ( ) ;
1159- if ( this [ kIsMultiline ] && cursorPos . rows > 0 ) {
1160- const splitLines = StringPrototypeSplit ( this . line , '\n' ) ;
1161- this [ kMultilineMove ] ( - 1 , splitLines , cursorPos ) ;
1162- return ;
1178+ if ( this [ kIsMultiline ] ) {
1179+ if ( cursorPos . rows > 0 ) {
1180+ const splitLines = StringPrototypeSplit ( this . line , '\n' ) ;
1181+ this [ kMultilineMove ] ( - 1 , splitLines , cursorPos ) ;
1182+ return ;
1183+ } else if ( cursorPos . rows === 0 && this . historyIndex === - 1 ) {
1184+ // Pressing up when at the first line of a new multiline input, should do nothing
1185+ // we don't want the user to lose what he has written so far.
1186+ return ;
1187+ }
11631188 }
11641189 this [ kPreviousCursorCols ] = - 1 ;
11651190 this [ kHistoryPrev ] ( ) ;
0 commit comments