How to use readline

Comprehensive readline code examples:

How to use readline.default:

4
5
6
7
8
9
10
11
12
13
Object.defineProperty(exports, "__esModule", { value: true });
const recordService_1 = __importDefault(require("../services/recordService"));
const readline_1 = __importDefault(require("readline"));
const handleKeypress = () => {
    console.log("Press r to start recording");
    readline_1.default.emitKeypressEvents(process.stdin);
    process.stdin.setRawMode(true);
    process.stdin.on('keypress', (_str, key) => {
        if (key.name === 'r' && !recordService_1.default.getIsRecording() && !recordService_1.default.getIsBeingNamed()) {
            recordService_1.default.startRecording();

How to use readline.close:

188
189
190
191
192
193
194
195


  }
  else {
    throw "Exit";
  }
  readline.close();
});

How to use readline.emitKeypressEvents:

1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
    this.value = this._value.value;
  }
};
function aD({ input: t = import_node_process.stdin, output: u2 = import_node_process.stdout, overwrite: F2 = true, hideCursor: e2 = true } = {}) {
  const s = f.createInterface({ input: t, output: u2, prompt: "", tabSize: 1 });
  f.emitKeypressEvents(t, s), t.isTTY && t.setRawMode(true);
  const C2 = (D2, { name: i }) => {
    if (String(D2) === "" && process.exit(0), !F2)
      return;
    let E2 = i === "return" ? 0 : -1, a2 = i === "return" ? -1 : 0;

How to use readline.clearScreenDown:

241
242
243
244
245
246
247
248
249
250
// source: https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-shared-utils/lib/logger.js
if (process.stdout.isTTY) {
  const blank = '\n'.repeat(process.stdout.rows);
  console.log(blank);
  readline.cursorTo(process.stdout, 0, 0);
  readline.clearScreenDown(process.stdout);
  if (msg) {
    console.log(msg);
  }
}

How to use readline.prompt:

33
34
35
36
37
38
39
40
41
42
        },
      };
      for (let val of veganIterable) {
        console.log(val.name);
      }
      readline.prompt();
    });
  }
  break;
case 'log':

How to use readline.moveCursor:

1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
f.emitKeypressEvents(t, s), t.isTTY && t.setRawMode(true);
const C2 = (D2, { name: i }) => {
  if (String(D2) === "" && process.exit(0), !F2)
    return;
  let E2 = i === "return" ? 0 : -1, a2 = i === "return" ? -1 : 0;
  f.moveCursor(u2, E2, a2, () => {
    f.clearLine(u2, 1, () => {
      t.once("keypress", C2);
    });
  });

How to use readline.clearLine:

210
211
212
213
214
215
216
217
218
219
220
 * @param {string} message The message to write.
 * @api public
 */


ProgressBar.prototype.interrupt = function (message, draw) {
  readline.clearLine(this.stream, 0)
  readline.cursorTo(this.stream, 0)
  // // write the message text
  this.stream.write(message)
  // // re-display the progress bar with its lastDraw

How to use readline.cursorTo:

240
241
242
243
244
245
246
247
248
249
function clearScreen(msg) {
  // source: https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-shared-utils/lib/logger.js
  if (process.stdout.isTTY) {
    const blank = '\n'.repeat(process.stdout.rows);
    console.log(blank);
    readline.cursorTo(process.stdout, 0, 0);
    readline.clearScreenDown(process.stdout);
    if (msg) {
      console.log(msg);
    }

How to use readline.question:

72
73
74
75
76
77
78
79
80
81
  },
  actions: [askForServingSize, displayCalories],
};

function askForServingSize(food) {
  readline.question(
    `How many servings did you eat? ( as a decimal: 1, 0.5, 1.25, etc.. ) `,
    servingSize => {
      if (servingSize === 'nevermind' || servingSize === 'n') {
        actionIt.return();

How to use readline.createInterface:

324
325
326
327
328
329
330
331
332
333
},

_parseGeoNamesAlternateNamesCsv: function (pathToCsv, callback) {
  var that = this;
  that._alternateNames = {};
  var lineReader = readline.createInterface({
    input: fs.createReadStream(pathToCsv),
  });
  lineReader.on('line', function (line) {
    line = line.split('\t');