UNPKG

686 BJavaScriptView Raw
1/**
2 * print() : print(str)
3 * Prints the given string `str` to the terminal. If it is too long, it is ran
4 * through a pager.
5 */
6
7exports.print = function (str) {
8 var count = str.split("\n").length;
9 var max = 24;
10 if (max && count > max) {
11 exports.page(str);
12 } else {
13 process.stdout.write(str);
14 }
15};
16
17exports.lessOpts = [
18 '-R', // raw control chars
19 '-S' // squeeze long lines
20];
21
22/**
23 * page() : page(str)
24 * (private) Prints the `str` through a pager.
25 */
26
27exports.page = function (str) {
28 var spawn = require('child_process').spawn;
29 var child = spawn('less', exports.lessOpts, { stdio: [ 'pipe', 1, 2 ] });
30 child.stdin.write(str);
31 child.stdin.end();
32};