* Crop a (possibly ANSI-colored) single line to `width` visible columns so * it does not wrap on narrow terminals. ANSI escapes are copied through * without counting toward the width, and a reset is appended after the * ellipsis so the truncation cannot leak color into following output.
(str, width)
| 522 | * ellipsis so the truncation cannot leak color into following output. |
| 523 | */ |
| 524 | function cropToWidth(str, width) { |
| 525 | var out = '', visible = 0, i = 0; |
| 526 | while (i < str.length) { |
| 527 | if (str[i] === '\x1b') { |
| 528 | var m = str.slice(i).match(/^\x1b\[[0-9;]*m/); |
| 529 | if (m) { out += m[0]; i += m[0].length; continue; } |
| 530 | } |
| 531 | if (visible >= width - 1) |
| 532 | return out + '\u2026\x1b[0m'; |
| 533 | out += str[i]; visible++; i++; |
| 534 | } |
| 535 | return out; |
| 536 | } |
| 537 | |
| 538 | Common.printOut = function() { |
| 539 | if (process.env.PM2_SILENT === 'true' || process.env.PM2_PROGRAMMATIC === 'true') return false; |