How to use term-size - 6 common examples

To help you get started, we’ve selected a few term-size examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github EvanBacon / react-native-ink / src / exports / Text / index.ts View on Github external
// return options.dimBorder ? chalk.dim(newBorder) : newBorder;
    // @ts-ignore
    if (borderColors[side]) {
      // @ts-ignore
      border = chalk.rgb(...borderColors[side])(border);
    }
    // if (backgroundColor) {
    //   // @ts-ignore
    //   border = chalk.bgRgb(...backgroundColor)(border);
    // }
    return border;
  };

  const contentWidth = widestLine(children) + padding.left + padding.right;
  const paddingLeft = PAD.repeat(padding.left);
  const { columns } = termSize();
  let marginLeft = PAD.repeat(margin.left);

  if (alignSelf === 'center') {
    const padWidth = Math.max((columns - contentWidth) / 2, 0);
    marginLeft = PAD.repeat(padWidth);
  } else if (alignSelf === 'flex-end') {
    const padWidth = Math.max(columns - contentWidth - margin.right - 2, 0);
    marginLeft = PAD.repeat(padWidth);
  }

  const horizontal = chars.horizontal.repeat(contentWidth);
  const top = hasBorders
    ? colorizeBorder(
        NL.repeat(margin.top) +
          marginLeft +
          chars.topLeft +
github IBM / report-toolkit / packages / cli / src / console-utils.js View on Github external
mergeMap(output =>
      iif(
        () => Boolean(filepath),
        writeFile(filepath, output),
        of(output).pipe(
          tap(res => {
            console.log(res);
          })
        )
      )
    )
  );

export {colors};

export const terminalColumns = termsize().columns;
github milesj / boost / packages / core / src / Reporter.ts View on Github external
size(): { columns: number; rows: number } {
    return cliSize();
  }
github dylang / logging / src / config / get-columns.ts View on Github external
export const getColumns = () => termSize().columns - (process.env.NODE_ENV === 'test' ? 20 : 1) - logConfig.indent;
github maticzav / emma-cli / src / utils.js View on Github external
export const maxCellSize = () => terminal().columns / 4
github kevva / obj-to-table / index.js View on Github external
input = arrify(input);

	const keys = [];
	const vals = [];

	for (const x of input) {
		vals.push(objectValues(x));

		for (const y of Object.keys(x)) {
			if (keys.indexOf(y) === -1) {
				keys.push(y);
			}
		}
	}

	const width = Math.floor(termSize.columns / (keys.length + 1));
	const table = new CliTable(Object.assign({
		head: keys,
		colWidths: fillArray([width], keys.length)
	}, opts));

	for (const x of vals) {
		table.push(x);
	}

	return table;
};

term-size

Reliably get the terminal window size (columns & rows)

MIT
Latest version published 1 year ago

Package Health Score

61 / 100
Full package analysis

Popular term-size functions