@@ -190,9 +190,7 @@ describe('Terminal', () => {
190190 } ) ;
191191 it ( 'should clear a buffer larger than rows' , async ( ) => {
192192 // Fill the buffer with dummy rows
193- for ( let i = 0 ; i < term . rows * 2 ; i ++ ) {
194- await term . writeP ( 'test\n' ) ;
195- }
193+ await term . writeP ( 'test\n' . repeat ( term . rows * 2 ) ) ;
196194
197195 const promptLine = term . buffer . lines . get ( term . buffer . ybase + term . buffer . y ) ;
198196 term . clear ( ) ;
@@ -389,9 +387,7 @@ describe('Terminal', () => {
389387
390388 it ( 'should not scroll down, when a custom keydown handler prevents the event' , async ( ) => {
391389 // Add some output to the terminal
392- for ( let i = 0 ; i < term . rows * 3 ; i ++ ) {
393- await term . writeP ( 'test\r\n' ) ;
394- }
390+ await term . writeP ( 'test\r\n' . repeat ( term . rows * 3 ) ) ;
395391 const startYDisp = ( term . rows * 2 ) + 1 ;
396392 term . attachCustomKeyEventHandler ( ( ) => {
397393 return false ;
@@ -731,70 +727,87 @@ describe('Terminal', () => {
731727 it ( `${ range } : 2 characters per cell` , async function ( ) : Promise < void > {
732728 const high = String . fromCharCode ( 0xD800 ) ;
733729 const cell = new CellData ( ) ;
730+ const values : string [ ] = [ ] ;
734731 for ( let j = i ; j <= i + 0xF ; j ++ ) {
735- await term . writeP ( high + String . fromCharCode ( j ) ) ;
736- const tchar = term . buffer . lines . get ( 0 ) ! . loadCell ( 0 , cell ) ;
737- assert . equal ( tchar . getChars ( ) , high + String . fromCharCode ( j ) ) ;
732+ values . push ( high + String . fromCharCode ( j ) ) ;
733+ }
734+ await term . writeP ( values . join ( '\r\n' ) ) ;
735+ for ( let idx = 0 ; idx < values . length ; idx ++ ) {
736+ const expected = values [ idx ] ;
737+ const tchar = term . buffer . lines . get ( idx ) ! . loadCell ( 0 , cell ) ;
738+ assert . equal ( tchar . getChars ( ) , expected ) ;
738739 assert . equal ( tchar . getChars ( ) . length , 2 ) ;
739740 assert . equal ( tchar . getWidth ( ) , 1 ) ;
740- assert . equal ( term . buffer . lines . get ( 0 ) ! . loadCell ( 1 , cell ) . getChars ( ) , '' ) ;
741- term . reset ( ) ;
741+ assert . equal ( term . buffer . lines . get ( idx ) ! . loadCell ( 1 , cell ) . getChars ( ) , '' ) ;
742742 }
743743 } ) ;
744744 it ( `${ range } : 2 characters at last cell` , async ( ) => {
745745 const high = String . fromCharCode ( 0xD800 ) ;
746746 const cell = new CellData ( ) ;
747- term . buffer . x = term . cols - 1 ;
747+ const values : string [ ] = [ ] ;
748748 for ( let j = i ; j <= i + 0xF ; j ++ ) {
749- await term . writeP ( high + String . fromCharCode ( j ) ) ;
750- assert . equal ( term . buffer . lines . get ( 0 ) ! . loadCell ( term . buffer . x - 1 , cell ) . getChars ( ) , high + String . fromCharCode ( j ) ) ;
751- assert . equal ( term . buffer . lines . get ( 0 ) ! . loadCell ( term . buffer . x - 1 , cell ) . getChars ( ) . length , 2 ) ;
752- assert . equal ( term . buffer . lines . get ( 1 ) ! . loadCell ( 0 , cell ) . getChars ( ) , '' ) ;
753- term . reset ( ) ;
749+ values . push ( high + String . fromCharCode ( j ) ) ;
750+ }
751+ await term . writeP ( values . map ( ( value , idx ) => `\x1b[${ idx + 1 } ;${ term . cols } H${ value } ` ) . join ( '' ) ) ;
752+ for ( let idx = 0 ; idx < values . length ; idx ++ ) {
753+ const expected = values [ idx ] ;
754+ assert . equal ( term . buffer . lines . get ( idx ) ! . loadCell ( term . cols - 1 , cell ) . getChars ( ) , expected ) ;
755+ assert . equal ( term . buffer . lines . get ( idx ) ! . loadCell ( term . cols - 1 , cell ) . getChars ( ) . length , 2 ) ;
756+ assert . equal ( term . buffer . lines . get ( idx + 1 ) ! . loadCell ( 0 , cell ) . getChars ( ) , '' ) ;
754757 }
755758 } ) ;
756759 it ( `${ range } : 2 characters per cell over line end with autowrap` , async function ( ) : Promise < void > {
757760 const high = String . fromCharCode ( 0xD800 ) ;
758761 const cell = new CellData ( ) ;
762+ term . resize ( term . cols , 40 ) ;
763+ const values : string [ ] = [ ] ;
759764 for ( let j = i ; j <= i + 0xF ; j ++ ) {
760- term . buffer . x = term . cols - 1 ;
761- await term . writeP ( 'a' + high + String . fromCharCode ( j ) ) ;
762- assert . equal ( term . buffer . lines . get ( 0 ) ! . loadCell ( term . cols - 1 , cell ) . getChars ( ) , 'a' ) ;
763- assert . equal ( term . buffer . lines . get ( 1 ) ! . loadCell ( 0 , cell ) . getChars ( ) , high + String . fromCharCode ( j ) ) ;
764- assert . equal ( term . buffer . lines . get ( 1 ) ! . loadCell ( 0 , cell ) . getChars ( ) . length , 2 ) ;
765- assert . equal ( term . buffer . lines . get ( 1 ) ! . loadCell ( 1 , cell ) . getChars ( ) , '' ) ;
766- term . reset ( ) ;
765+ values . push ( high + String . fromCharCode ( j ) ) ;
766+ }
767+ await term . writeP ( values . map ( ( value , idx ) => `\x1b[${ idx * 2 + 1 } ;${ term . cols } H` + 'a' + value ) . join ( '' ) ) ;
768+ for ( let idx = 0 ; idx < values . length ; idx ++ ) {
769+ const expected = values [ idx ] ;
770+ const row = idx * 2 ;
771+ assert . equal ( term . buffer . lines . get ( row ) ! . loadCell ( term . cols - 1 , cell ) . getChars ( ) , 'a' ) ;
772+ assert . equal ( term . buffer . lines . get ( row + 1 ) ! . loadCell ( 0 , cell ) . getChars ( ) , expected ) ;
773+ assert . equal ( term . buffer . lines . get ( row + 1 ) ! . loadCell ( 0 , cell ) . getChars ( ) . length , 2 ) ;
774+ assert . equal ( term . buffer . lines . get ( row + 1 ) ! . loadCell ( 1 , cell ) . getChars ( ) , '' ) ;
767775 }
768776 } ) ;
769777 it ( `${ range } : 2 characters per cell over line end without autowrap` , async function ( ) : Promise < void > {
770778 const high = String . fromCharCode ( 0xD800 ) ;
771779 const cell = new CellData ( ) ;
780+ const values : string [ ] = [ ] ;
772781 for ( let j = i ; j <= i + 0xF ; j ++ ) {
773- term . buffer . x = term . cols - 1 ;
774- await term . writeP ( '\x1b[?7l' ) ; // Disable wraparound mode
775782 const width = wcwidth ( ( 0xD800 - 0xD800 ) * 0x400 + j - 0xDC00 + 0x10000 ) ;
776783 if ( width !== 1 ) {
777784 continue ;
778785 }
779- await term . writeP ( 'a' + high + String . fromCharCode ( j ) ) ;
780- // auto wraparound mode should cut off the rest of the line
781- assert . equal ( term . buffer . lines . get ( 0 ) ! . loadCell ( term . cols - 1 , cell ) . getChars ( ) , high + String . fromCharCode ( j ) ) ;
782- assert . equal ( term . buffer . lines . get ( 0 ) ! . loadCell ( term . cols - 1 , cell ) . getChars ( ) . length , 2 ) ;
783- assert . equal ( term . buffer . lines . get ( 1 ) ! . loadCell ( 1 , cell ) . getChars ( ) , '' ) ;
784- term . reset ( ) ;
786+ values . push ( high + String . fromCharCode ( j ) ) ;
787+ }
788+ await term . writeP ( '\x1b[?7l' + values . map ( ( value , idx ) => `\x1b[${ idx + 1 } ;${ term . cols } H` + 'a' + value ) . join ( '' ) ) ;
789+ for ( let idx = 0 ; idx < values . length ; idx ++ ) {
790+ const expected = values [ idx ] ;
791+ assert . equal ( term . buffer . lines . get ( idx ) ! . loadCell ( term . cols - 1 , cell ) . getChars ( ) , expected ) ;
792+ assert . equal ( term . buffer . lines . get ( idx ) ! . loadCell ( term . cols - 1 , cell ) . getChars ( ) . length , 2 ) ;
793+ assert . equal ( term . buffer . lines . get ( idx + 1 ) ! . loadCell ( 1 , cell ) . getChars ( ) , '' ) ;
785794 }
786795 } ) ;
787796 it ( `${ range } : splitted surrogates` , async function ( ) : Promise < void > {
788797 const high = String . fromCharCode ( 0xD800 ) ;
789798 const cell = new CellData ( ) ;
799+ const values : string [ ] = [ ] ;
790800 for ( let j = i ; j <= i + 0xF ; j ++ ) {
791- await term . writeP ( high + String . fromCharCode ( j ) ) ;
792- const tchar = term . buffer . lines . get ( 0 ) ! . loadCell ( 0 , cell ) ;
793- assert . equal ( tchar . getChars ( ) , high + String . fromCharCode ( j ) ) ;
801+ values . push ( high + String . fromCharCode ( j ) ) ;
802+ }
803+ await term . writeP ( values . join ( '\r\n' ) ) ;
804+ for ( let idx = 0 ; idx < values . length ; idx ++ ) {
805+ const expected = values [ idx ] ;
806+ const tchar = term . buffer . lines . get ( idx ) ! . loadCell ( 0 , cell ) ;
807+ assert . equal ( tchar . getChars ( ) , expected ) ;
794808 assert . equal ( tchar . getChars ( ) . length , 2 ) ;
795809 assert . equal ( tchar . getWidth ( ) , 1 ) ;
796- assert . equal ( term . buffer . lines . get ( 0 ) ! . loadCell ( 1 , cell ) . getChars ( ) , '' ) ;
797- term . reset ( ) ;
810+ assert . equal ( term . buffer . lines . get ( idx ) ! . loadCell ( 1 , cell ) . getChars ( ) , '' ) ;
798811 }
799812 } ) ;
800813 }
0 commit comments