<commit_before>/**
 * Base prompt implementation
 * Should be extended by prompt types.
 */

var _ = require("lodash");
var utils = require("../utils/utils");
var clc = require("cli-color");
var ansiTrim = require("cli-color/lib/trim");
var readline = require("readline");


/**
 * Module exports
 */

module.exports = Prompt;


/**
 * Prompt constructor
 */

function Prompt( question, rl ) {

  // Setup instance defaults property
  _.assign( this, {
    height   : 0,
    answered : false
  });

  // Set defaults prompt options
  this.opt = _.defaults( question, {
    validate: function() { return true; },
    filter: function( val ) { return val; }
  });

  // Normalize choices
  if ( _.isArray(this.opt.choices) ) {
    this.opt.choices = utils.normalizeChoices( this.opt.choices );
  }

  this.rl = rl;

  return this;
}


/**
 * Start the Inquiry session and manage output value filtering
 * @param  {Function} cb  Callback when prompt is done
 * @return {this}
 */

Prompt.prototype.run = function( cb ) {
  var self = this;
  this._run(function( value ) {
    self.filter( value, cb );
  });
  return this;
};

// default noop (this one should be overwritten in prompts)
Prompt.prototype._run = function( cb ) { cb(); };


/**
 * Remove the prompt from screen
 * @param  {Number}  Extra lines to remove (probably to compensate the "enter" key line
 *                   return)
 * @return {Prompt}  self
 */

Prompt.prototype.clean = function( extra ) {
  _.isNumber(extra) || (extra = 0);
  var len = this.height + extra;

  while ( len-- ) {
    readline.moveCursor(this.rl.output, +Infinity, 0);
    this.rl.output.write(
      clc.bol(0, true) +
      (new Array(clc.width)).join(" ") + // write a full line of space to force cleanup
      clc.bol(0, true)
    );
    if ( len ) readline.moveCursor(this.rl.output, 0, -1);
  }
  return this;
};
<commit_msg>Fix Unix prompts (rel #22)<commit_after>/**
 * Base prompt implementation
 * Should be extended by prompt types.
 */

var _ = require("lodash");
var utils = require("../utils/utils");
var clc = require("cli-color");
var ansiTrim = require("cli-color/lib/trim");
var readline = require("readline");


/**
 * Module exports
 */

module.exports = Prompt;


/**
 * Prompt constructor
 */

function Prompt( question, rl ) {

  // Setup instance defaults property
  _.assign( this, {
    height   : 0,
    answered : false
  });

  // Set defaults prompt options
  this.opt = _.defaults( question, {
    validate: function() { return true; },
    filter: function( val ) { return val; }
  });

  // Normalize choices
  if ( _.isArray(this.opt.choices) ) {
    this.opt.choices = utils.normalizeChoices( this.opt.choices );
  }

  this.rl = rl;

  return this;
}


/**
 * Start the Inquiry session and manage output value filtering
 * @param  {Function} cb  Callback when prompt is done
 * @return {this}
 */

Prompt.prototype.run = function( cb ) {
  var self = this;
  this._run(function( value ) {
    self.filter( value, cb );
  });
  return this;
};

// default noop (this one should be overwritten in prompts)
Prompt.prototype._run = function( cb ) { cb(); };


/**
 * Remove the prompt from screen
 * @param  {Number}  Extra lines to remove (probably to compensate the "enter" key line
 *                   return)
 * @return {Prompt}  self
 */

Prompt.prototype.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;
};

{'fraction_non_alphanumeric': 0.14777105118326914, 'fraction_numerical': 0.004127682993946065, 'mean_word_length': 2.8835470085470085, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4397540', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1165, 'n_words': 342}