Example #1
0
 this.clear = function(){
   
   output.write(
     ansiEscapes.clearScreen + 
     ansiEscapes.cursorTo(0,0) + 
     repeat('\n ',output.getHeight()) + 
     ansiEscapes.cursorTo(0,0)
   );
 }
Example #2
0
  this.fillRect = function(x,y,width,height,text){//text is optional
    

    var outputWidth = output.getWidth();
    var outputHeight = output.getHeight();
  
    text = text||'';
    var toWrite = ansiEscapes.cursorTo(x,y);//move to x,y   
    
    for (var dy = 0; dy < height; dy ++){//move down
      for (var dx = 0; dx < width; dx ++){//move across
        if (dy + y >= outputHeight || dx + x >= outputWidth  || dy + y < 0 || dx + x < 0){
          return;//don't print things offscreen dummy
          //console.log('ooh')
        }        
        // put a space in there... or the character from the "text" option
        toWrite = toWrite + ( text[dy*width+dx] ||' ');
      }
      //drop in a newline and move across to X
      toWrite = toWrite + '\n' + ansiEscapes.cursorForward(x);  
    }    
    
    //toWrite = toWrite + (ansiEscapes.cursorTo(x,y));
    
    output.write(applyStyle(toWrite));//flush it down the pipe 
  }
Example #3
0
 this.drawLine = function(x1,y1,x2,y2,character){
   //only vertical or horizontal lines
   var toWrite = '';
   if (y1 == y2){// horizontal
     var left = Math.min(x1,x2);
     var right = Math.max(x1,x2);      
     toWrite = ansiEscapes.cursorTo(left,y1) + repeat(character||canvas._getLineCharacter(),(right-left)+1);      
   }
   else if (x1 == x2){// vertical
     var top = Math.min(y1,y2);
     var bottom = Math.max(y1,y2);      
     toWrite = ansiEscapes.cursorTo(0,top) + repeat(ansiEscapes.cursorForward(x1) + (character||canvas._getLineCharacter()) + '\r\n',(bottom-top)+1);
   }else{
     return;// I don't do diagonal lines.
   }
   
   output.write(toWrite);
 }
Example #4
0
  this.drawImage = function(x,y,width,height,imageData){// imageData is an iterable thing in RGBA format.  Width and height are in PX and not in Chars!

      var ret = ansiEscapes.cursorTo(x,y);
      
      var options = options || {};
      
      var dat = imageData||[];
      
      var outputWidth = output.getWidth();
      var outputHeight = output.getHeight();
      

      var i = 0;
      while (i < dat.length){
        //handle off-screen writing in X direction
        if ( x + (i/4)%width  >= outputWidth){
          //return;
        }
        //handle writing offscreen in Y direction
         if ( y + ((i/4)/width)/2  >= outputHeight){
          //return;
        }
        
        // it's RGBA
        var top = [dat[i],dat[i+1],dat[i+2]];
        var bottom = [dat[i + width*4 ],dat[i + width*4+1],dat[i + width*4+2]];
        
        ret = ret + (termPx(top,bottom));
        
        i = i + 4;
        if ( (i/4) % width == 0 ){// move to next line
          ret = ret + ('\n');
          i = i + width*4;//skip line
          // move over
          ret = ret + ansiEscapes.cursorForward(x);
        }
      }
      
    //move back
    ret = ret + (ansiEscapes.cursorTo(x,y));
    output.write(ret);
  } 
const printRestoredPatternCaret = (
  pattern: string,
  currentUsageRows: number,
  pipe: stream$Writable | tty$WriteStream,
) => {
  const inputText = `${chalk.dim(' pattern \u203A')} ${pattern}`;

  pipe.write(
    ansiEscapes.cursorTo(stringLength(inputText), currentUsageRows - 1),
  );
  pipe.write(ansiEscapes.cursorRestorePosition);
};
const printRestoredPatternCaret = (
pattern,
currentUsageRows,
pipe) =>
{
  const inputText = `${chalk.dim(' pattern \u203A')} ${pattern}`;

  pipe.write(
  ansiEscapes.cursorTo(stringLength(inputText), currentUsageRows - 1));

  pipe.write(ansiEscapes.cursorRestorePosition);
};
Example #7
0
    printTypeahead(
    pattern,
    allResults,
    max)
    {
      const total = allResults.length;
      const results = allResults.slice(0, max);
      const inputText = `${chalk.dim(' pattern \u203A')} ${pattern}`;

      pipe.write(ansiEscapes.eraseDown);
      pipe.write(inputText);
      pipe.write(ansiEscapes.cursorSavePosition);

      if (pattern) {
        if (total) {
          pipe.write(`\n\n Pattern matches ${total} ${pluralizeFile(total)}.`);
        } else {
          pipe.write(`\n\n Pattern matches no files.`);
        }

        const width = getTerminalWidth();
        const prefix = `  ${chalk.dim('\u203A')} `;
        const padding = stringLength(prefix) + 2;

        results.
        map(rawPath => {
          const filePath = trimAndFormatPath(padding, config, rawPath, width);
          return highlight(rawPath, filePath, pattern, config.rootDir);
        }).
        forEach(
        filePath => pipe.write(`\n  ${chalk.dim('\u203A')} ${filePath}`));


        if (total > max) {
          const more = total - max;
          pipe.write(
          // eslint-disable-next-line max-len
          `\n  ${chalk.dim(`\u203A and ${more} more ${pluralizeFile(more)}`)}`);

        }
      } else {
        // eslint-disable-next-line max-len
        pipe.write(`\n\n ${chalk.italic.yellow('Start typing to filter by a filename regex pattern.')}`);
      }

      pipe.write(ansiEscapes.cursorTo(stringLength(inputText), usageRows - 1));
      pipe.write(ansiEscapes.cursorRestorePosition);
    }
Example #8
0
    printTypeahead(pattern: string, max: number) {
      const matchedTests = this.getMatchedTests(pattern);

      const total = matchedTests.length;
      const results = matchedTests.slice(0, max);
      const inputText = `${chalk.dim(' pattern \u203A')} ${pattern}`;

      pipe.write(ansiEscapes.eraseDown);
      pipe.write(inputText);
      pipe.write(ansiEscapes.cursorSavePosition);

      if (pattern) {
        if (total) {
          pipe.write(`\n\n Pattern matches ${total} ${pluralizeTest(total)}`);
        } else {
          pipe.write(`\n\n Pattern matches no tests`);
        }

        pipe.write(' from cached test suites.');

        const width = getTerminalWidth();

        results.forEach(name => {
          const testName = formatTestNameByPattern(name, pattern, width - 4);

          pipe.write(`\n ${chalk.dim('\u203A')} ${testName}`);
        });

        if (total > max) {
          const more = total - max;
          pipe.write(
            // eslint-disable-next-line max-len
            `\n  ${chalk.dim(`\u203A and ${more} more ${pluralizeTest(more)}`)}`,
          );
        }
      } else {
        pipe.write(
          // eslint-disable-next-line max-len
          `\n\n ${chalk.italic.yellow('Start typing to filter by a test name regex pattern.')}`,
        );
      }

      pipe.write(ansiEscapes.cursorTo(stringLength(inputText), usageRows - 1));
      pipe.write(ansiEscapes.cursorRestorePosition);
    }
Example #9
0
 this.moveTo = function(x,y){
   output.write(
     ansiEscapes.cursorTo(x||0,y||0)
   );
 }
Example #10
0
 video.renderer.renderFrame = function () {
   renderFrame.apply(this, arguments)
   process.stdout.write(ansiEscapes.cursorTo(0, 0))
   process.stdout.write(ansiEscapes.image(canvas.toBuffer()))
 }