@@ -409,7 +409,10 @@ function output (plainText = "") {
409409 */
410410export function getLineByIndex ( index ) {
411411
412- var toPush = Math . max ( index - lines . length + 1 , 0 ) ;
412+ let toPush = Math . max ( index - lines . length + 1 , 0 ) ;
413+
414+ if ( index > 100 )
415+ throw new Error ( `Petuh inc.` ) ;
413416
414417 if ( toPush > 0 )
415418 pushLines ( toPush ) ;
@@ -463,10 +466,11 @@ export function scrollDown () {
463466 */
464467function sizeChanged ( ) {
465468
466- var tel = document . createElement ( "span" ) ,
469+ let tel = document . createElement ( "span" ) ,
467470 testScrollbar = document . createElement ( "div" ) ,
468471 scrollBarWidth ,
469- lastOverflowProperty = elements . output . style . overflowY ;
472+ lastOverflowProperty = elements . output . style . overflowY ,
473+ ow , oh ;
470474
471475 elements . output . style . overflowY = "scroll" ;
472476 testScrollbar . className = LINE_CLASS_NAME ;
@@ -478,15 +482,29 @@ function sizeChanged () {
478482 tel . innerHTML = "XXXXXXXXXX" ;
479483 testScrollbar . appendChild ( tel ) ;
480484
481- SYMBOL_WIDTH = tel . offsetWidth / 10 ;
482- SYMBOL_HEIGHT = tel . offsetHeight ;
485+ SYMBOL_WIDTH = ( tel . offsetWidth / 10 ) || 8.8 ;
486+ SYMBOL_HEIGHT = tel . offsetHeight || 19 ;
483487
484- WIDTH = Math . floor ( ( elements . terminal . offsetWidth - scrollBarWidth ) / SYMBOL_WIDTH ) ;
485- HEIGHT = Math . floor ( elements . terminal . offsetHeight / SYMBOL_HEIGHT ) ;
488+ WIDTH = ( ow = Math . floor ( ( elements . terminal . offsetWidth - scrollBarWidth ) / SYMBOL_WIDTH ) )
489+ || SYMBOL_HEIGHT * 32 ;
490+ HEIGHT = ( oh = Math . floor ( elements . terminal . offsetHeight / SYMBOL_HEIGHT ) )
491+ || SYMBOL_WIDTH * 80 ;
486492
487493 elements . input . style . width = `${ WIDTH * SYMBOL_WIDTH } px` ;
488494
489495 elements . output . removeChild ( testScrollbar ) ;
496+
497+ // In case of custom styling when integrating WebTerminal to other solutions, the WebTerminal
498+ // may be hidden on the page by default. This will cause WebTerminal to set up wrong
499+ // width/height (= 0). This block yields the size calculation until the parent element appears
500+ // on the page.
501+ if ( ! ow || ! oh ) {
502+ setTimeout ( sizeChanged , 25 ) ;
503+ let m = `[WebTerminal] Size calculations delayed for 25s due to WebTerminal is not`
504+ + ` attached to the page. If this message doesn't stop appearing, check if`
505+ + ` WebTerminal's iFrame is visible and is attached to the DOM.` ;
506+ try { console . warn ( m ) ; } catch ( e ) { console . log ( m ) ; }
507+ }
490508
491509 // elements.output.style.width = `${ WIDTH * SYMBOL_WIDTH + scrollBarWidth }px`;
492510 // elements.output.style.height = `${ HEIGHT * SYMBOL_HEIGHT }px`; = 100%
0 commit comments