@@ -614,37 +614,49 @@ export const taskLog = (title: string) => {
614
614
process . stdout . write ( `${ ACTIVE } ${ title } \n` ) ;
615
615
616
616
let output = '' ;
617
+ let frame = '' ;
617
618
618
619
// clears previous output
619
- const clear = ( buffer = 0 ) : void => {
620
- if ( ! output ) return ;
621
- const lines = output . split ( '\n' ) . length + buffer ;
622
- process . stdout . write ( erase . lines ( lines + 1 ) ) ;
620
+ const clear = ( eraseTitle = false ) : void => {
621
+ if ( ! frame ) return ;
622
+ const terminalWidth = process . stdout . columns ;
623
+ const frameHeight = frame . split ( '\n' ) . reduce ( ( height , line ) => {
624
+ // accounts for line wraps
625
+ height += Math . ceil ( line . length / terminalWidth ) ;
626
+ return height ;
627
+ } , 0 ) ;
628
+ const lines = frameHeight + ( eraseTitle ? 1 : 0 ) ;
629
+
630
+ process . stdout . write ( cursor . up ( lines ) ) ;
631
+ process . stdout . write ( erase . down ( ) ) ;
623
632
} ;
624
633
625
634
// logs the output
626
- const print = ( ) : void => {
627
- const lines = output . split ( '\n' ) ;
635
+ const print = ( limit = 0 ) : void => {
636
+ const lines = output . split ( '\n' ) . slice ( - limit ) ;
637
+ // reset frame
638
+ frame = '' ;
628
639
for ( const line of lines ) {
629
- const msg = color . dim ( `${ BAR } ${ line } \n` ) ;
630
- process . stdout . write ( msg ) ;
640
+ frame += `${ BAR } ${ line } \n` ;
631
641
}
642
+ process . stdout . write ( color . dim ( frame ) ) ;
632
643
} ;
633
644
634
645
return {
635
646
set text ( data : string ) {
636
647
clear ( ) ;
637
648
output += data ;
638
- print ( ) ;
649
+ // half the height of the terminal
650
+ const frameHeight = Math . ceil ( process . stdout . rows / 2 ) ;
651
+ print ( frameHeight ) ;
639
652
} ,
640
653
fail ( message : string ) : void {
641
- clear ( 1 ) ; // includes clearing the `title`
654
+ clear ( true ) ;
642
655
process . stdout . write ( `${ ERROR } ${ message } \n` ) ;
643
- // log the output on failure
644
- print ( ) ;
656
+ print ( ) ; // log the output on failure
645
657
} ,
646
658
success ( message : string ) : void {
647
- clear ( 1 ) ; // includes clearing the `title`
659
+ clear ( true ) ;
648
660
process . stdout . write ( `${ SUCCESS } ${ message } \n` ) ;
649
661
}
650
662
} ;
0 commit comments