Exemplo n.º 1
0
		message: ( message, color = 'black' ) => {
			customStdout.muted = false; //allow output so we can draw

			let spaceTop = Math.floor( getSpaceTop() );
			let spaceLeft = getSpaceLeft(); //space left from frame

			Readline.cursorTo( BEAST.RL, spaceLeft, (spaceTop + 4 + Math.floor( ( BEAST.MINHEIGHT - 7 ) / 2 ) - 2) ); //go to middle of board

			let space = ( (BEAST.MINWIDTH - 2) / 2 ) - ( (message.length + 2) / 2 ); //rest space minus the message length
			let spaceMiddleLeft = Math.floor( space );
			let spaceMiddleRight = Math.ceil( space );

			BEAST.RL.write(`${' '.repeat( BEAST.MINWIDTH - 2 )}\n`); //clear line
			Readline.moveCursor(BEAST.RL, spaceLeft, 0);             //move cursor into board
			BEAST.RL.write(`${' '.repeat( BEAST.MINWIDTH - 2 )}\n`); //clear line
			Readline.moveCursor(BEAST.RL, spaceLeft, 0);             //move cursor into board
			BEAST.RL.write(`${' '.repeat( spaceMiddleLeft )}${Chalk[ color ].bgWhite.bold(` ${message} `)}${' '.repeat( spaceMiddleRight )}\n`);
			Readline.moveCursor(BEAST.RL, spaceLeft, 0);             //move cursor into board
			BEAST.RL.write(`${' '.repeat( BEAST.MINWIDTH - 2 )}\n`); //clear line
			Readline.moveCursor(BEAST.RL, spaceLeft, 0);             //move cursor into board
			BEAST.RL.write(`${' '.repeat( BEAST.MINWIDTH - 2 )}\n`); //clear line

			Readline.cursorTo( BEAST.RL, 0, (CliSize().rows - 1) ); //go to bottom of board and rest cursor there

			customStdout.muted = true; //no more user output now!
		},
Exemplo n.º 2
0
 rl._refreshLine = _.wrap(rl._refreshLine, function (func) {
   func.call(rl);
   var line = this._prompt + this.line;
   var visualLength = ansiTrim(line).length;
   readline.moveCursor(this.output, -line.length, 0);
   readline.moveCursor(this.output, visualLength, 0);
 });
Exemplo n.º 3
0
  rl._refreshLine = _.wrap(rl._refreshLine, function( func ) {
    func.call(rl);
    var line = this._prompt + this.line;
    var cursorPos = this._getCursorPos();

    readline.moveCursor(this.output, -line.length, 0);
    readline.moveCursor(this.output, cursorPos.cols, 0);
  });
Exemplo n.º 4
0
tty.restoreCursorPos = function() {
  if ( !this.cursorPos ) return;
  var line = this.rl._prompt + this.rl.line;
  readline.moveCursor(this.rl.output, -line.length, 0);
  readline.moveCursor(this.rl.output, this.cursorPos.cols, 0);
  this.cursorPos = null;
  return this;
};
Exemplo n.º 5
0
/**
                               * Clear some text that was previously printed on an interactive stream,
                               * without trailing newline character (so we have to move back to the
                               * beginning of the line).
                               */
function clearStringBackwards(stream, str) {
  readline.moveCursor(stream, -stream.columns, 0);
  readline.clearLine(stream, 0);
  let lineCount = (str.match(/\n/g) || []).length;
  while (lineCount > 0) {
    readline.moveCursor(stream, 0, -1);
    readline.clearLine(stream, 0);
    --lineCount;
  }
}
Exemplo n.º 6
0
tty.clean = function( extra ) {
  _.isNumber(extra) || (extra = 0);
  var len = this.height + extra;

  while ( len-- ) {
    readline.moveCursor(this.rl.output, -clc.width, 0);
    readline.clearLine(this.rl.output, 0);
    if ( len ) readline.moveCursor(this.rl.output, 0, -1);
  }
  return this;
};
Exemplo n.º 7
0
function clearNthLine(stdout, n) {
  if (!supportsColor) {
    return;
  }

  if (n == 0) {
    clearLine(stdout);
    return;
  }
  readline.cursorTo(stdout, 0);
  readline.moveCursor(stdout, 0, -n);
  readline.clearLine(stdout, CLEAR_WHOLE_LINE);
  readline.moveCursor(stdout, 0, n);
}
function outputQueues(swtch, firstRun) {
  let total = 0;

  if (! firstRun) {
    readline.moveCursor(std, 0, -(swtch.dimension + 1));
  }

  // Print all virtual output queues of each input in one line, plus the total
  // number of packets in each input queue

  swtch.inputs.forEach(function(input) {
    const queueTotal = input.reduce((prev, cur) => prev + cur, 0);

    total += queueTotal;
    readline.clearLine(std, 0);

    std.write(input.map(function(output, i) {
      const cell = _.truncate(_.padStart(output, 3), {
        length: 3,
        omission: '…'
      });

      return argv.colored ? cell[colors[i % colors.length]] : cell;
    }).join(' '));

    std.write(`  (Σ = ${queueTotal})\n`);
  });

  readline.clearLine(std, 0);
  std.write(`Σ = ${total}\n`);
}
Exemplo n.º 9
0
		board: () => {
			BEAST.debugging.report(`draw: board`, 1);

			customStdout.muted = false; //allow output so we can draw

			let spaceTop = Math.floor( getSpaceTop() );
			let spaceLeft = getSpaceLeft();

			Readline.cursorTo( BEAST.RL, 0, (spaceTop + 4) ); //go to top of board

			for(let boardRow of BEAST.BOARD) { //iterate over each row
				let line = ''; //translate BEAST.BOARD to ASCII

				for(let x = 0; x < ( BEAST.MINWIDTH - 2 ); x++) { //iterate over each column in this row
					let element = BEAST.SYMBOLS[ boardRow[ x ] ]; //get the symbol for the element we found

					if( element ) { //if there was an element found
						line += element;
					}
					else { //add space
						line += ' ';
					}
				}

				Readline.moveCursor(BEAST.RL, spaceLeft, 0); //move cursor into board
				BEAST.RL.write(`${line}\n`); //print line inside the frame
			}

			Readline.cursorTo( BEAST.RL, 0, (CliSize().rows - 1) ); //go to bottom of board and rest cursor there

			customStdout.muted = true; //no more user output now!
		},
Exemplo n.º 10
0
rl.on('line', function (line) {
    readline.moveCursor(process.stdout,0,-1);
    process.stdout.clearLine();
    if (fileConfirmationMode){
      fileConfirmationMode = false;
      if (line === "Y"){
        console_out(color("Relayed to " + fileConfirmationData.from + " that you Accepted. Waiting to receive file...", "green"));
        fileConfirmationData.response = true;
      }else{
        fileConfirmationData.response = false;
        console_out(color("Relayed to " + fileConfirmationData.from + " that you Rejected. Aborted file receive.", "red"));
      }
      socket.emit('fileConfirmResponse', fileConfirmationData);
    } else {
      if (line[0] == "/" && line.length > 1) {
          var cmd = line.match(/[a-z]+\b/)[0];
          var arg = line.substr(cmd.length+2, line.length);
          chat_command(cmd, arg);
      } else {
          // send chat message
          socket.emit('send', { type: 'chat', message: line, nick: nick });
          rl.prompt(true);
      }
    }

});
Exemplo n.º 11
0
function writeOnNthLine(stdout, n, msg) {
  if (!supportsColor) {
    return;
  }

  if (n == 0) {
    readline.cursorTo(stdout, 0);
    stdout.write(msg);
    readline.clearLine(stdout, CLEAR_RIGHT_OF_CURSOR);
    return;
  }
  readline.cursorTo(stdout, 0);
  readline.moveCursor(stdout, 0, -n);
  stdout.write(msg);
  readline.clearLine(stdout, CLEAR_RIGHT_OF_CURSOR);
  readline.cursorTo(stdout, 0);
  readline.moveCursor(stdout, 0, n);
}
Exemplo n.º 12
0
 process.on('SIGINT', () => {
   // Remove '^C' text from stdout.
   readline.clearLine(process.stdout, -1)
   readline.moveCursor(process.stdout, -2, 0)
   // Set counter to 0 which will stop alarm.
   i = 0
   // Reset CTRL-C to default behavior.
   process.on('SIGINT', process.exit)
 })
Exemplo n.º 13
0
Prompt.prototype.error = function( error ) {
  readline.moveCursor( this.rl.output, -cliWidth(), 0 );
  readline.clearLine( this.rl.output, 0 );

  var errMsg = chalk.red(">> ") +
      (error || "Please enter a valid value");
  this.write( errMsg );

  return this.up();
};
Exemplo n.º 14
0
  _write(stream, message) {
    if (this._interactive && stream.isTTY && isPreviousLogInteractive) {
      readline.moveCursor(stream, 0, -1);
      readline.clearLine(stream);
      readline.cursorTo(stream, 0);
    }

    stream.write(message + '\n');
    isPreviousLogInteractive = this._interactive;
  }
 new webpack.ProgressPlugin(function handler(progress, msg){
   var perc = Math.round(progress * 100);
   var progressBar = new Array(Math.round(perc/2)).join(color.green('■'));
   progressBar += new Array( 50 - Math.round(perc/2) ).join('-');
   
   readline.clearLine(process.stdout, 0);  // clear current text
   readline.cursorTo(process.stdout, 0);  // move cursor to beginning of line
   process.stdout.write(`\nBuilding [${progressBar}] ${perc}% `);
   readline.moveCursor(process.stdout, 0, -1);
 })
Exemplo n.º 16
0
Prompt.prototype.hint = function( hint ) {
  readline.moveCursor( this.rl.output, -cliWidth(), 0 );
  readline.clearLine( this.rl.output, 0 );

  if ( hint.length ) {
    var hintMsg = chalk.cyan(">> ") + hint;
    this.write( hintMsg );
  }

  return this.up();
};
Exemplo n.º 17
0
 readline._historyNext = function() {
   if(!lines.length || vpos >= lines.length) return;
   var cl = readline.line;
   var nl = lines[++vpos] || line || '';
   var x = 0, pos = readline.cursor;
   if(nl.length < pos) {
     x = nl.length - pos;
   }
   rl.moveCursor(readline.input, x, 1);
   readline.line = nl;
 }
Exemplo n.º 18
0
  function redraw() {
    readline.clearLine(process.stdout, 0)
    readline.cursorTo(process.stdout, 0)

    for (let i = 0; i < drawnLines; i++) {
      readline.moveCursor(process.stdout, 0, -1)
      readline.clearLine(process.stdout, 0)
    }

    draw()
  }
Exemplo n.º 19
0
race.on("done", function(cars) {
    readline.moveCursor(process.stdout, 0, this.cars.length + 2);
    
    let carColors = cars.map(function(car) {
        return car.color;
    });

    console.log(`Winner is: ${carColors.join(", ")}`);
    process.stderr.write('\x1B[?25h'); // this reshows our cursor
    process.exit();
});
Exemplo n.º 20
0
function writeLine (line, prevLine) {
  rl.pause()
  if (prevLine) {
    readline.moveCursor(process.stdout, 0, -1)
  }
  readline.clearLine(process.stdout, 0)
  readline.cursorTo(process.stdout, 0)
  console.log(line.toString())
  rl.prompt(true)
  rl.resume()
}
Exemplo n.º 21
0
 readline._historyPrev = function() {
   if(vpos === 0) return;
   var cl = readline.line;
   var nl = lines[--vpos] || line || '';
   var x = 0, pos = readline.cursor;
   if(nl.length < pos) {
     x = nl.length - pos;
   }
   rl.moveCursor(readline.input, x, -1);
   readline.line = nl;
   readline.cursor = pos + x;
 }
Exemplo n.º 22
0
 console.log = function(outputContent, replace, print) {
     if (!options.message && !print) return;
     if (!replace) {
         outputStream.write(outputContent + '\r\n');
         rl.close();
     } else {
         readline.moveCursor(outputStream, cursorDx * -1, cursorDy * -1);
         readline.clearScreenDown(outputStream);
         outputStream.write(outputContent);
         dxInfo = getStrOccRowColumns(outputContent);
         cursorDx = dxInfo.columns;
         cursorDy = dxInfo.rows;
     }
 }
Exemplo n.º 23
0
				})(function (err) {
					if (err) {
						console.error('Error occurred');
						return next(err);
					}

					readline.clearLine(process.stdout, 0);
					readline.cursorTo(process.stdout, 0);
					readline.moveCursor(process.stdout, 0, -1);
					console.log('  → '.white + String('[' + [date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate()].join('/') + '] ').gray + String(scriptExport.name).reset + '... ' + 'OK'.green);

					// Record success in schemaLog
					db.sortedSetAdd('schemaLog', Date.now(), path.basename(file, '.js'), next);
				});
Exemplo n.º 24
0
    _render: function (index) {
        if (!this._enabled || !isatty) {
            return;
        }

        cursor.hide();
        readline.moveCursor(process.stdout, -process.stdout.columns, -this._lineCount);
        var lineCount = 0;
        var numProgressBars = this._progressBars.length;
        for (var i = 0; i < numProgressBars; i++) {
            if (i === index) {
                readline.clearLine(process.stdout, 1);
                process.stdout.write(this._progressBars[i].text + os.EOL);
            }
            else {
                readline.moveCursor(process.stdout, -process.stdout.columns, +1);
            }

            lineCount++;
        }

        this._lineCount = lineCount;
        cursor.show();
    },
Exemplo n.º 25
0
    cursor.input.on("data", function(data) {
      log("got data " + data);
      data.toString().split("").forEach(function(c) {
        const cmd = commands[c];
        if(cmd) {
          log("command: " + cmd.name);
          cmd();
          renderAnalysis();
        }
      });

      // hide the characters
      readline.moveCursor(setup.input, -data.length, 0);
      readline.clearLine(setup.input, 1);
    });
Exemplo n.º 26
0
  function nextHandler(){
    if (!taskCount)
    {
      var newWarnings = flow.warns.length - warningCount;
      var timeDiff = process.hrtime(time.time);
      time.time = parseInt(timeDiff[0] * 1e3 + timeDiff[1] / 1e6, 10);
      timing.push(time);
      warningCount = flow.warns.length;

      if (!options.silent && !options.verbose && !stdoutHandlerSilent && handlers.length)
      {
        var extraInfo = time.extraInfo ? time.extraInfo(flow) : '';
        if (process.stdout.isTTY)
        {
          if (process.stdout._bytesDispatched == stdoutPos)
          {
            readline.moveCursor(process.stdout, 0, -1);
            readline.clearLine(process.stdout, 0);
            process.stdout.write(
              stdoutHandlerTitle +
              (extraInfo ? chalk.gray(' [') + chalk.yellow(extraInfo) + chalk.gray(']') : '') +
              chalk.gray(' – '));
          }
          else
          {
            if (extraInfo)
              process.stdout.write('       ' + chalk.yellow(extraInfo) + '\n');
            process.stdout.write('       ');
          }

          process.stdout.write(
            chalk.green('DONE') +
            (newWarnings > 0 ? ' ' + chalk.bgRed('(' + newWarnings + (newWarnings > 1 ? ' warnings)' : ' warning)')) : '') +
            (time.time > 10 ? chalk.gray(' (' + time.time + 'ms)') : '') +
            '\n'
          );
        }
        else
        {
          if (extraInfo)
            process.stdout.write('       * ' + extraInfo + '\n');
        }
      }

      process.nextTick(runHandler);
    }
  }
Exemplo n.º 27
0
  function nextHandler(){
    var lastHandler = !handlers.length;

    if (!taskCount && !lastHandler)
    {
      time.time = new Date - time.time;
      timing.push(time);

      if (!options.verbose)
      {
        var extraInfo = time.extraInfo ? time.extraInfo(flow) : '';
        if (process.stdout.isTTY)
        {

          if (process.stdout._bytesDispatched == stdoutPos)
          {
            readline.moveCursor(process.stdout, 0, -1);
            readline.clearLine(process.stdout, 0);
            process.stdout.write(
              stdoutHandlerTitle +
              (extraInfo ? chalk.gray(' [') + chalk.yellow(extraInfo) + chalk.gray(']') : '') +
              chalk.gray(' – '));
          }
          else
          {
            if (extraInfo)
              process.stdout.write('       ' + chalk.yellow(extraInfo) + '\n');
            process.stdout.write('       ');
          }

          process.stdout.write(
            chalk.green('DONE') +
            (time.time > 10 ? chalk.gray(' (' + time.time + 'ms)') : '') +
            '\n'
          );
        }
        else
        {
          if (extraInfo)
            process.stdout.write('       * ' + extraInfo + '\n');
        }
      }

      process.nextTick(runHandler);
    }
  }
Exemplo n.º 28
0
        this.intervalId = setInterval(function() {
            k++;
            if (k > max) {
                this.stop();
            }
            outputContent = util.format('%s', self.value);
            //将光标移动到已经写入的字符前面,
            readline.moveCursor(outputStream, cursorDx * -1, cursorDy * -1);
            //清除当前光标后的所有文字信息,以便接下来输出信息能写入到控制台
            readline.clearScreenDown(outputStream);
            outputStream.write(outputContent);
            //不要使用这个方法,此方法中写入的数据会被作为line事件的输入源读取
            //rl.write(outputContent);
            dxInfo = getStrOccRowColumns(outputContent);

            cursorDx = dxInfo.columns;
            cursorDy = dxInfo.rows;
        }, 1000);
Exemplo n.º 29
0
race.on("update", function() {
    process.stderr.write('\x1B[?25l'); // this hides our cursor
    let colNum = process.stdout.columns;
    let lengthPerCol = this.length / colNum;    
    let trackEdge = new Array(colNum).fill("◎").join("");
    readline.clearLine(process.stdout, 0);
    console.log(trackEdge);
    this.cars.forEach(function(car) {
        let numOfSpaces = Math.floor(car.position / lengthPerCol);
        if(numOfSpaces  > colNum - 1) {
            numOfSpaces = colNum - 1;
        }
        let spaces = numOfSpaces > 0 ? new Array(numOfSpaces).fill(" ").join("") : "";
        let carChar = chalk[car.color]("►");
        console.log(`${spaces}${carChar}`);
    });
    console.log(trackEdge);
    readline.moveCursor(process.stdout, 0, 0 - (this.cars.length + 2));        
});
Exemplo n.º 30
0
			async.eachSeries(files, function (file, next) {
				var scriptExport = require(file);
				var date = new Date(scriptExport.timestamp);
				var version = path.dirname(file).split('/').pop();
				var progress = {
					current: 0,
					total: 0,
					incr: Upgrade.incrementProgress,
					script: scriptExport,
					date: date,
				};

				console.log('  → '.white + String('[' + [date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate()].join('/') + '] ').gray + String(scriptExport.name).reset + '...');

				// For backwards compatibility, cross-reference with schemaDate (if found). If a script's date is older, skip it
				if ((!results.schemaDate && !results.schemaLogCount) || (scriptExport.timestamp <= results.schemaDate && semver.lt(version, '1.5.0'))) {
					readline.clearLine(process.stdout, 0);
					readline.cursorTo(process.stdout, 0);
					readline.moveCursor(process.stdout, 0, -1);
					console.log('  → '.white + String('[' + [date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate()].join('/') + '] ').gray + String(scriptExport.name).reset + '... ' + 'skipped'.grey);
					db.sortedSetAdd('schemaLog', Date.now(), path.basename(file, '.js'), next);
					return;
				}

				// Do the upgrade...
				scriptExport.method.bind({
					progress: progress,
				})(function (err) {
					if (err) {
						console.error('Error occurred');
						return next(err);
					}

					readline.clearLine(process.stdout, 0);
					readline.cursorTo(process.stdout, 0);
					readline.moveCursor(process.stdout, 0, -1);
					console.log('  → '.white + String('[' + [date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate()].join('/') + '] ').gray + String(scriptExport.name).reset + '... ' + 'OK'.green);

					// Record success in schemaLog
					db.sortedSetAdd('schemaLog', Date.now(), path.basename(file, '.js'), next);
				});
			}, next);