How to use the window-size.height function in window-size

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 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 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 noffle / osm-tty / render.js View on Github external
function nodeToTermCoords (camera, node) {
  var horizScale = 1//0.55
  var vertScale = 1

  var w = camera.bbox[1][1] - camera.bbox[1][0]
  var h = camera.bbox[0][1] - camera.bbox[0][0]
  var x = Math.round(((node.lon - camera.bbox[1][0]) / w) * termsize.width * horizScale)
  var y = termsize.height - Math.round(((node.lat - camera.bbox[0][0]) / h) * termsize.height * vertScale)
  return [x, y]
}
github noffle / osm-tty / render.js View on Github external
function visible (x, y) {
  return x >= 0 && y >= 0 && y < termsize.height && x < termsize.width
}
github noffle / osm-tty / render.js View on Github external
function addLabel (screen, state, x, y, col, label) {
  if (y < 0 || y >= termsize.height) return
  if (x < 0) return
  if (x + label.length >= termsize.width) label = label.substring(0, label.length - x)

  state.labels.push({
    x: x,
    y: y,
    label: label,
    color: col
  })
}
github dominikwilkowski / cfonts / src / lib.js View on Github external
/**
 * Abstraction for windows size
 *
 * @type {object}
 */
const Size = {
	width: WinSize
		? WinSize.width > 0
			? WinSize.width
			: 80
		: 80,
	height: WinSize
		? WinSize.height > 0
			? WinSize.height
			: 24
		: 24,
};


/**
 * Calculate the spaces to be added to the left of each line to align them either center or right
 *
 * @param  {array}   output         - The output array the line shall be appended to
 * @param  {integer} lineLength     - The current line length
 * @param  {integer} characterLines - The amount of line breaks in one character
 * @param  {string}  align          - The alignment of the text, only `center` and `right` will do anything
 * @param  {object}  size           - The size of the terminal as an object, default: Size
 * @param  {integer} size.width     - The width of the terminal
 * @param  {integer} size.height    - The height of the terminal
 *
github dominikwilkowski / cfonts / src / lib.js View on Github external
};


/**
 * Abstraction for windows size
 *
 * @type {object}
 */
const Size = {
	width: WinSize
		? WinSize.width > 0
			? WinSize.width
			: 80
		: 80,
	height: WinSize
		? WinSize.height > 0
			? WinSize.height
			: 24
		: 24,
};


/**
 * Calculate the spaces to be added to the left of each line to align them either center or right
 *
 * @param  {array}   output         - The output array the line shall be appended to
 * @param  {integer} lineLength     - The current line length
 * @param  {integer} characterLines - The amount of line breaks in one character
 * @param  {string}  align          - The alignment of the text, only `center` and `right` will do anything
 * @param  {object}  size           - The size of the terminal as an object, default: Size
 * @param  {integer} size.width     - The width of the terminal
 * @param  {integer} size.height    - The height of the terminal
github govau / pancake / bin / pancake-cream.js View on Github external
if (function (lines) {
		return Size.height - 3;
	}) {
		lines = Size.height - 3;
github noffle / osm-tty / ex.js View on Github external
ts.once('end', function () {
    charm.position(0, termsize.height)
  })
})(require('fs').createReadStream('./data.xml'))

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