Last change
on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
907 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | exports = module.exports = cliWidth;
|
---|
| 4 |
|
---|
| 5 | function normalizeOpts(options) {
|
---|
| 6 | let defaultOpts = {
|
---|
| 7 | defaultWidth: 0,
|
---|
| 8 | output: process.stdout,
|
---|
| 9 | tty: require("tty"),
|
---|
| 10 | };
|
---|
| 11 |
|
---|
| 12 | if (!options) {
|
---|
| 13 | return defaultOpts;
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | Object.keys(defaultOpts).forEach(function (key) {
|
---|
| 17 | if (!options[key]) {
|
---|
| 18 | options[key] = defaultOpts[key];
|
---|
| 19 | }
|
---|
| 20 | });
|
---|
| 21 |
|
---|
| 22 | return options;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | function cliWidth(options) {
|
---|
| 26 | let opts = normalizeOpts(options);
|
---|
| 27 |
|
---|
| 28 | if (opts.output.getWindowSize) {
|
---|
| 29 | return opts.output.getWindowSize()[0] || opts.defaultWidth;
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | if (opts.tty.getWindowSize) {
|
---|
| 33 | return opts.tty.getWindowSize()[1] || opts.defaultWidth;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | if (opts.output.columns) {
|
---|
| 37 | return opts.output.columns;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | if (process.env.CLI_WIDTH) {
|
---|
| 41 | let width = parseInt(process.env.CLI_WIDTH, 10);
|
---|
| 42 |
|
---|
| 43 | if (!isNaN(width) && width !== 0) {
|
---|
| 44 | return width;
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | return opts.defaultWidth;
|
---|
| 49 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.