Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
autoComplete: options.autoComplete ,
autoCompleteMenu: options.autoCompleteMenu ,
autoCompleteHint: !! options.autoCompleteHint
} ;
// Now inputs is an array of input, input being an array of char (thanks to JS using UCS-2 instead of UTF-8)
if ( Array.isArray( options.history ) ) {
inputs = options.history.map( str => string.unicode.toArray( str ).slice( 0 , options.maxLength ) ) ;
}
if ( options.default && typeof options.default === 'string' ) {
inputs.push( string.unicode.toArray( options.default ).slice( 0 , options.maxLength ) ) ;
}
else {
inputs.push( [] ) ;
}
var init = () => {
inputIndex = inputs.length - 1 ;
offset = boundOffset( offset ) ;
if ( options.y !== undefined ) {
options.x = options.x || 1 ;
this.moveTo.eraseLineAfter( options.x , options.y ) ;
finishInit( options.x , options.y ) ;
}
if ( charCode >= 0x80 ) {
// Unicode bytes per char guessing
if ( charCode < 0xc0 ) { continue ; } // We are in a middle of an unicode multibyte sequence... Something fails somewhere, we will just continue for now...
else if ( charCode < 0xe0 ) { bytes = 2 ; }
else if ( charCode < 0xf0 ) { bytes = 3 ; }
else if ( charCode < 0xf8 ) { bytes = 4 ; }
else if ( charCode < 0xfc ) { bytes = 5 ; }
else { bytes = 6 ; }
charBuffer[ 0 ] = charCode ;
charBuffer[ 1 ] = charBuffer[ 2 ] = charBuffer[ 3 ] = charBuffer[ 4 ] = charBuffer[ 5 ] = 0 ;
( await readStream( stream , bytes - 1 ) ).copy( charBuffer , 1 ) ;
char = charBuffer.toString( 'utf8' ) ;
codepoint = string.unicode.firstCodePoint( char ) ;
//this.emit( 'key' , char , [ char ] , { isCharacter: true , codepoint: codepoint , code: charBuffer } ) ;
this.emit( 'char' , char , codepoint ) ;
}
else {
// Standard ASCII
char = String.fromCharCode( charCode ) ;
//this.emit( 'key' , char , [ char ] , { isCharacter: true , codepoint: charCode , code: charCode } ) ;
this.emit( 'char' , char , charCode ) ;
}
}
} ;
width = 0 ;
height = data.length ;
attr = options.attr !== undefined ? options.attr : ScreenBuffer.prototype.DEFAULT_ATTR ;
if ( attr && typeof attr === 'object' && ! attr.BYTES_PER_ELEMENT ) { attr = ScreenBuffer.object2attr( attr ) ; }
attrTrans = attr ;
if ( options.transparencyChar ) {
if ( ! options.transparencyType ) { attrTrans |= TRANSPARENCY ; }
else { attrTrans |= options.transparencyType & TRANSPARENCY ; }
}
// Compute the width of the screenBuffer
for ( y = 0 ; y < data.length ; y ++ ) {
lineWidth = string.unicode.width( data[ y ] ) ;
if ( lineWidth > width ) { width = lineWidth ; }
}
// Create the buffer with the right width & height
screenBuffer = new ScreenBuffer( { width: width , height: height } ) ;
// Fill the buffer with data
for ( y = 0 ; y < data.length ; y ++ ) {
if ( ! options.transparencyChar ) {
screenBuffer.put( { x: 0 , y: y , attr: attr } , data[ y ] ) ;
}
else {
length = data[ y ].length ;
for ( x = 0 ; x < length ; x ++ ) {
if ( data[ y ][ x ] === options.transparencyChar ) {
if ( attr && typeof attr === 'object' ) { attr = this.object2attr( attr ) ; }
if ( typeof attr !== 'string' ) { attr = this.esc.styleReset.on ; }
// Process the input string
if ( typeof str !== 'string' ) {
if ( str.toString ) { str = str.toString() ; }
else { return ; }
}
if ( args.length ) { str = string.format( str , ... args ) ; }
str = termkit.stripControlChars( str ) ;
//characters = punycode.ucs2.decode( str ) ;
characters = string.unicode.toArray( str ) ;
len = characters.length ;
moveToNeeded = true ;
this.stdout.write( attr ) ;
for ( i = 0 ; i < len ; i ++ ) {
if ( moveToNeeded ) { this.moveTo( x , y ) ; }
this( characters[ i ] ) ;
x += dx ;
y += dy ;
moveToNeeded = ! inline ;
if ( x < 0 ) {
if ( ! wrap ) { break ; }
buffer = this.buffer ;
if ( options && typeof options === 'object' ) {
if ( options.char || options.attr ) {
clearBuffer = Buffer.allocUnsafe( this.ITEM_SIZE ) ;
// Write the attributes
attr = options.attr !== undefined ? options.attr : this.DEFAULT_ATTR ;
if ( attr && typeof attr === 'object' && ! attr.BYTES_PER_ELEMENT ) { attr = this.object2attr( attr ) ; }
this.writeAttr( clearBuffer , attr , 0 ) ;
// Write the character
char = options.char && typeof options.char === 'string' ? options.char : ' ' ;
//char = punycode.ucs2.encode( [ punycode.ucs2.decode( termkit.stripControlChars( char ) )[ 0 ] ] ) ;
char = string.unicode.firstChar( termkit.stripControlChars( char ) ) ;
//clearBuffer.write( char , this.ATTR_SIZE , this.CHAR_SIZE ) ;
this.writeChar( clearBuffer , char , 0 ) ;
}
else if ( options.clearBuffer ) {
clearBuffer = options.clearBuffer ;
}
// This option is used when we want to clear a Buffer instance, not a ScreenBuffer instance
if ( options.buffer ) { buffer = options.buffer ; }
start = options.start ? Math.floor( options.start / this.ITEM_SIZE ) : 0 ;
end = options.end ? Math.floor( options.end / this.ITEM_SIZE ) : buffer.length / this.ITEM_SIZE ;
region = options.region ? options.region : null ;
}
else {
width = 0 ;
height = data.length ;
attr = options.attr !== undefined ? options.attr : ScreenBufferHD.prototype.DEFAULT_ATTR ;
if ( attr && typeof attr === 'object' && ! attr.BYTES_PER_ELEMENT ) { attr = ScreenBufferHD.object2attr( attr ) ; }
attrTrans = attr ;
if ( options.transparencyChar ) {
if ( ! options.transparencyType ) { attrTrans |= ScreenBufferHD.prototype.TRANSPARENCY ; }
else { attrTrans |= options.transparencyType & ScreenBufferHD.prototype.TRANSPARENCY ; }
}
// Compute the width of the screenBuffer
for ( y = 0 ; y < data.length ; y ++ ) {
lineWidth = string.unicode.width( data[ y ] ) ;
if ( lineWidth > width ) { width = lineWidth ; }
}
// Create the buffer with the right width & height
screenBuffer = new ScreenBufferHD( { width: width , height: height } ) ;
// Fill the buffer with data
for ( y = 0 ; y < data.length ; y ++ ) {
if ( ! options.transparencyChar ) {
screenBuffer.put( { x: 0 , y: y , attr: attr } , data[ y ] ) ;
}
else {
length = data[ y ].length ;
for ( x = 0 ; x < length ; x ++ ) {
if ( data[ y ][ x ] === options.transparencyChar ) {
var computeAllCoordinate = () => {
var scroll ,
inputWidth = string.unicode.arrayWidth( inputs[ inputIndex ] ) ,
hintWidth = string.unicode.arrayWidth( hint ) ;
end = offsetCoordinate( inputWidth ) ;
endHint = offsetCoordinate( inputWidth + hintWidth ) ;
if ( endHint.y > this.height ) {
// We have gone out of the screen, scroll!
scroll = endHint.y - this.height ;
dynamic.style.noFormat( '\n'.repeat( scroll ) ) ;
start.y -= scroll ;
end.y -= scroll ;
endHint.y -= scroll ;
}
cursorCoordinate() ;
ScreenBufferHD.prototype.dump = function() {
var y , x , offset , str = '' , char ;
for ( y = 0 ; y < this.height ; y ++ ) {
for ( x = 0 ; x < this.width ; x ++ ) {
offset = ( y * this.width + x ) * this.ITEM_SIZE ;
char = this.readChar( this.buffer , offset ) ;
str += char + ( string.unicode.isFullWidth( char ) ? ' ' : ' ' ) ;
str += string.format( '%x%x%x%x %x%x%x%x %x%x ' ,
this.buffer.readUInt8( offset ) ,
this.buffer.readUInt8( offset + 1 ) ,
this.buffer.readUInt8( offset + 2 ) ,
this.buffer.readUInt8( offset + 3 ) ,
this.buffer.readUInt8( offset + 4 ) ,
this.buffer.readUInt8( offset + 5 ) ,
this.buffer.readUInt8( offset + 6 ) ,
this.buffer.readUInt8( offset + 7 ) ,
this.buffer.readUInt8( offset + 8 ) ,
this.buffer.readUInt8( offset + 9 )
) ;
}
str += '\n' ;
Element.truncateContent = ( content , maxWidth , hasMarkup ) =>
hasMarkup ? misc.truncateMarkupString( content , maxWidth ) : string.unicode.truncateWidth( content , maxWidth ) ;
return Math.max( ... content.map( line => string.unicode.width( line ) ) ) ;