github-pages-deploy-action/node_modules/prompts/dist/util/clear.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-03-31 20:42:07 +08:00
'use strict';
const strip = require('./strip');
const _require = require('sisteransi'),
erase = _require.erase,
cursor = _require.cursor;
const width = str => [...strip(str)].length;
module.exports = function (prompt, perLine = process.stdout.columns) {
if (!perLine) return erase.line + cursor.to(0);
let rows = 0;
const lines = prompt.split(/\r?\n/);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = lines[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
let line = _step.value;
rows += 1 + Math.floor(Math.max(width(line) - 1, 0) / perLine);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return erase.lines(rows);
};