Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

clear.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict';
  2. function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
  3. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  4. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
  5. const strip = require('./strip');
  6. const _require = require('sisteransi'),
  7. erase = _require.erase,
  8. cursor = _require.cursor;
  9. const width = str => [...strip(str)].length;
  10. /**
  11. * @param {string} prompt
  12. * @param {number} perLine
  13. */
  14. module.exports = function (prompt, perLine) {
  15. if (!perLine) return erase.line + cursor.to(0);
  16. let rows = 0;
  17. const lines = prompt.split(/\r?\n/);
  18. var _iterator = _createForOfIteratorHelper(lines),
  19. _step;
  20. try {
  21. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  22. let line = _step.value;
  23. rows += 1 + Math.floor(Math.max(width(line) - 1, 0) / perLine);
  24. }
  25. } catch (err) {
  26. _iterator.e(err);
  27. } finally {
  28. _iterator.f();
  29. }
  30. return erase.lines(rows);
  31. };