|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
489 bytes
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | const strip = require('./strip');
|
|---|
| 4 | const { erase, cursor } = require('sisteransi');
|
|---|
| 5 |
|
|---|
| 6 | const width = str => [...strip(str)].length;
|
|---|
| 7 |
|
|---|
| 8 | /**
|
|---|
| 9 | * @param {string} prompt
|
|---|
| 10 | * @param {number} perLine
|
|---|
| 11 | */
|
|---|
| 12 | module.exports = function(prompt, perLine) {
|
|---|
| 13 | if (!perLine) return erase.line + cursor.to(0);
|
|---|
| 14 |
|
|---|
| 15 | let rows = 0;
|
|---|
| 16 | const lines = prompt.split(/\r?\n/);
|
|---|
| 17 | for (let line of lines) {
|
|---|
| 18 | rows += 1 + Math.floor(Math.max(width(line) - 1, 0) / perLine);
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | return erase.lines(rows);
|
|---|
| 22 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.