<commit_before>var _ = require('../utils')
var co = require('co')

/**
 * Question basic constructor.
 *
 * @param {Object} config Configure of the question.
 */
function Base(prompt, config) {
  _.extend(this, config)
  this.prompt = prompt
}

/**
 * Render question output message.
 * Different type question will cover this method to get different output style.
 */
Base.prototype.render = function () {}

/**
 * Move cursor and clean last answer when validate error.
 *
 * @returns {Object} Self.
 */
Base.prototype.doError = function (result, answer) {
  this.renderError(result, answer)
  
  var prompt = this.prompt
  prompt.restoreCursorPos()
    .up(1)
    .cleanAfter()
    .cacheCursorPos()
}

/**
 * Render error when validation fails (will be overridden)
 */
Base.prototype.renderError = function () {}

/**
 * Using `co` to wrap, adapt to normal function and generator.
 *
 * @param {Function} fn
 * @returns {Function} Run `fn` and return promise.
 */
function colize (fn) {
  if (_.isGeneratorFunction(fn)) {
    return co.wrap(fn)
  } else {
    return co.wrap(function* () {
      return yield Promise.resolve(fn.apply(this, arguments))
    })
  }
}

/**
 * Filter answer, also make the process.
 *
 * @param {Mixed} answer
 * @returns Self.
 */
var filterNoop = function (answer) {
  return answer
}
Base.prototype._filter = function (answer) {
  var filter = colize(this.filter || filterNoop)
  return filter(answer)
}

/**
 * Validate answers
 *
 * @param {Boolean|String} answer
 * @returns {Boolean|String|Promise} True or error message, or Promise when `config.validate` is a generator.
 */
var validateNoop = function () {
  return true
}
Base.prototype._validate = function (answer) {
  var validate = colize(this.validate || validateNoop)
  return validate(answer)
}

/**
 * Print answer.
 *
 * @param {Boolean|String} answer
 */
var chalk = require('chalk')
Base.prototype.renderAnswer = function (answer) {
  this.prompt.write(chalk.cyan('(' + answer + ')\n'))
}

/**
* Do something after taking the answer, like clean input, print answer and so on.
*/
Base.prototype.doAfter = function (answer) {
  var len = this.default ? this.default.length : -2<commit_msg>Tweak answer render<commit_after>var _ = require('../utils')
var co = require('co')

/**
 * Question basic constructor.
 *
 * @param {Object} config Configure of the question.
 */
function Base(prompt, config) {
  _.extend(this, config)
  this.prompt = prompt
}

/**
 * Render question output message.
 * Different type question will cover this method to get different output style.
 */
Base.prototype.render = function () {}

/**
 * Move cursor and clean last answer when validate error.
 *
 * @returns {Object} Self.
 */
Base.prototype.doError = function (result, answer) {
  this.renderError(result, answer)
  
  var prompt = this.prompt
  prompt.restoreCursorPos()
    .up(1)
    .cleanAfter()
    .cacheCursorPos()
}

/**
 * Render error when validation fails (will be overridden)
 */
Base.prototype.renderError = function () {}

/**
 * Using `co` to wrap, adapt to normal function and generator.
 *
 * @param {Function} fn
 * @returns {Function} Run `fn` and return promise.
 */
function colize (fn) {
  if (_.isGeneratorFunction(fn)) {
    return co.wrap(fn)
  } else {
    return co.wrap(function* () {
      return yield Promise.resolve(fn.apply(this, arguments))
    })
  }
}

/**
 * Filter answer, also make the process.
 *
 * @param {Mixed} answer
 * @returns Self.
 */
var filterNoop = function (answer) {
  return answer
}
Base.prototype._filter = function (answer) {
  var filter = colize(this.filter || filterNoop)
  return filter(answer)
}

/**
 * Validate answers
 *
 * @param {Boolean|String} answer
 * @returns {Boolean|String|Promise} True or error message, or Promise when `config.validate` is a generator.
 */
var validateNoop = function () {
  return true
}
Base.prototype._validate = function (answer) {
  var validate = colize(this.validate || validateNoop)
  return validate(answer)
}

/**
 * Print answer.
 *
 * @param {Boolean|String} answer
 */
var chalk = require('chalk')
Base.prototype.renderAnswer = function (answer) {
  this.prompt.write(chalk.cyan(answer + '\n'))
}

/**
* Do something after taking the answer, like clean input, print answer and so on.
*/
Base.prototype.doAfter = function (answer) {
  var len = this.default ? this.default.length : -2
{'fraction_non_alphanumeric': 0.13815939712263073, 'fraction_numerical': 0.0009134505594884677, 'mean_word_length': 3.59601259181532, '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': '3788376', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1330, 'n_words': 406}