1
0
Fork 0
mirror of https://github.com/actions/setup-python.git synced 2024-11-30 03:45:17 +00:00
setup-python/node_modules/prompts/dist/util/clear.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-06-27 01:12:00 +00: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.line + cursor.prevLine()).repeat(rows - 1) + erase.line + cursor.to(0);
};