How to use window-size - 10 common examples

To help you get started, we’ve selected a few window-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 sparkswap / broker / broker-cli / commands / orderbook.js View on Github external
function createUI (market, asks, bids) {
  console.clear()
  const baseCurrencySymbol = market.split('/')[0].toUpperCase()
  const windowWidth = size.get().width
  const { mainTableWidth, innerTableWidth } = calculateTableWidths(windowWidth)
  const table = new Table({
    head: ['ASKS', 'BIDS'],
    style: { head: ['gray'] },
    colWidths: [mainTableWidth, mainTableWidth]
  })

  // The extensive options are required because the default for cli-table is to have
  // borders between every row and column.
  const innerTableOptions = {
    head: ['Price', `Depth (${baseCurrencySymbol})`],
    style: { head: ['gray'] },
    colWidths: [innerTableWidth, innerTableWidth],
    chars: {
      'top': '',
      'top-mid': '',
github sparkswap / broker-cli / commands / orderbook.js View on Github external
function createUI (market, asks, bids) {
  console.clear()
  const windowHeight = size.get().height

  // Fill as many orders as the screen allows less other info displayed
  const maxLengthPerSide = Math.floor((windowHeight - NON_MARKET_INFO) / 2)
  const baseCurrencySymbol = market.split('/')[0].toUpperCase()

  const parentTable = new Table({
    head: [],
    chars: {
      'top-mid': '',
      'bottom-mid': '',
      'left-mid': '',
      'mid': '',
      'mid-mid': '',
      'right-mid': '',
      'middle': ''
    },
github sparkswap / broker / broker-cli / commands / orderbook.js View on Github external
function createUI (market, asks, bids) {
  const baseCurrencySymbol = market.split('/')[0].toUpperCase()
  const windowWidth = size.get().width
  const { mainTableWidth, innerTableWidth } = calculateTableWidths(windowWidth)
  const table = new Table({
    head: ['ASKS', 'BIDS'],
    style: { head: ['gray'] },
    colWidths: [mainTableWidth, mainTableWidth]
  })

  // The extensive options are required because the default for cli-table is to have
  // borders between every row and column.
  const innerTableOptions = {
    head: ['Price', `Depth (${baseCurrencySymbol})`],
    style: { head: ['gray'] },
    colWidths: [innerTableWidth, innerTableWidth],
    chars: {
      'top': '',
      'top-mid': '',
github cats-oss / scaffdog / src / commands / generate.ts View on Github external
import globby from 'globby';
import * as inquirer from 'inquirer';
import inquirerAutocomplete from 'inquirer-autocomplete-prompt';
import symbols from 'log-symbols';
import mkdirp from 'mkdirp';
import { emojify } from 'node-emoji';
import * as path from 'path';
import * as windowSize from 'window-size';
import { commonFlags } from '../flags';
import { Compiler } from '../template/compiler';
import { createContext } from '../template/context';
import { Reader, Resource } from '../template/reader';
import { fileExists } from '../utils';
import { Reporter } from '../template/reporter';

const LIST_PAGE_SIZE = windowSize.height - 10;

const searchDir = (directories: string[]) => (_: any, input = ''): Promise => {
  return new Promise((resolve) => {
    const fuzzyResult = fuzzy.filter(input, directories);
    resolve(fuzzyResult.map((el) => el.original));
  });
};

// inquirer can fuzzy search
inquirer.registerPrompt('autocomplete', inquirerAutocomplete);

export default class GenerateCommand extends Command {
  public static description =
    'Scaffold using the specified template. If you do not specify the template name and execute it, interactively select the template.';

  public static args = [{ name: 'templateName' }];
github ajay-gandhi / asciify-image / index.js View on Github external
Jimp.read(path, function(err, image) {
    if (err) return callback('Error loading image: ' + err);

    // Percentage based widths
    if (opts.width && opts.width.substr(-1) === '%') {
      opts.width = Math.floor((parseInt(opts.width.slice(0, -1)) / 100) * (windowSize.width * terminalCharWidth));
    }

    // Percentage based heights
    if (opts.height && opts.height.substr(-1) === '%') {
      opts.height = Math.floor((parseInt(opts.height.slice(0, -1)) / 100) * windowSize.height);
    }

    // Setup options
    var options = {
      fit:     opts.fit     ? opts.fit               : 'original',
      width:   opts.width   ? parseInt(opts.width)   : image.bitmap.width,
      height:  opts.height  ? parseInt(opts.height)  : image.bitmap.height,
      c_ratio: opts.c_ratio ? parseInt(opts.c_ratio) : 2,

      color:      opts.color  == false    ? false : true,
      as_string:  opts.format === 'array' ? false : true
    }

    var new_dims = calculate_dims(image, options);

    // Resize to requested dimensions
github dominikwilkowski / cfonts / index.js View on Github external
outOption += '\n  Options.' + key + ': ' + CFonts.OPTIONS[key];
				}

				CFonts.debugging.report(outOption, 2);
			}

			if (CFonts.OPTIONS.font === 'console') {
				//console fontface is pretty easy to process
				var outputLines = INPUT.replace('\\', '').split('|'); //remove escape characters and split into each line

				CFonts.FONTFACE.colors = 1; //console defaults
				CFonts.FONTFACE.lines = 1;

				for (var line in outputLines) {
					//each line needs to be pushed into the output array
					lines += Math.ceil(outputLines[line].length / WinSize.width); //count each line even when they overflow

					if (CFonts.OPTIONS.colors[0] === "candy") {
						//if the color is candy
						var character = '';

						for (var i = 0; i < outputLines[line].length; i++) {
							//iterate through the message
							character += Colorize(outputLines[line][i]); //and colorize each character individually
						}

						output.push(character); //push each line to the output array
					} else {
						output.push(Colorize(outputLines[line])); //colorize line
					}

					output = AlignText(output, outputLines[line].length); //calculate alignment based on lineLength
github ProboCI / probo / cli-subcommands / help.js View on Github external
output = output.map(function(element) {
      var name = element.name;
      var output = '    ' + name + self.buildSpaces(spaces - name.length);
      var wrap = wordwrap(output.length, windowsize.width);
      var description = wrap(element.description);
      output += description.substring(output.length);
      return output;
    });
    console.log(output.join('\n'));
github MrRio / vtop / run.js View on Github external
var Canvas = require('drawille');
var line = require('bresenham');

var size = require('window-size');

var width = Math.floor(size.width / 2) * 4;
var height = Math.floor((size.height) / 16) * 36;


var c = new Canvas(width, height);
var m = new Canvas(width, height);


var i = 0;

String.prototype.repeat = function(num) {
  return new Array(num + 1).join(this);
};

var drawHeader = function(left, right) {
  console.log(left + ' '.repeat(size.width - (left.length + right.length)) + right);
};
github microsoft / botbuilder-tools / packages / QnAMaker / lib / help.js View on Github external
module.exports = async function help(args, output) {
    if (!output)
        output = process.stderr;

    output.write('QnA Maker Command line interface - © 2018 Microsoft Corporation\n\n');
    const helpContents = await getHelpContents(args, output);
    let width = windowSize ? windowSize.width : 250;

    let leftColWidth = 0;
    for (let hc of helpContents) {
        if (hc.table && hc.table[0].length > 0) {
            for (let row in hc.table) {
                let len = hc.table[row][0].length;
                if (len > leftColWidth) {
                    leftColWidth = Math.min(len, Math.floor(width / 3));
                }
            }
        }
    }

    helpContents.forEach(helpContent => {
        output.write(chalk.white.bold(helpContent.head + '\n'));
        if (helpContent.table && helpContent.table[0].length > 0) {

window-size

Reliable way to get the height and width of terminal/console, since it's not calculated or updated the same way on all platforms, environments and node.js versions.

MIT
Latest version published 6 years ago

Package Health Score

71 / 100
Full package analysis