npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

virtual-grid

v2.0.1

Published

A viewport into a virtual grid of text cells

Downloads

13

Readme

virtual-grid

A viewport into a virtual grid of text cells.

Renderes cells in a grid. Each cell contains text that is wrapped and truncated to fit inside the cell. Full support for ANSI colors. Useful as a layout manager for terminal apps.

Build status js-standard-style

Installation

npm install virtual-grid --save

Usage

const Grid = require('virtual-grid')

const grid = new Grid({
  height: 10,
  width: 20,
  rows: [
    [{height: 5, text: 'This is the top cell spanning the entire width'}],
    [{width: '50%', text: 'Left column'}, {width: '50%', text: 'Right column'}]
  ]
})

// Update the text in cell C
grid.update(1, 1, 'This text have been overwritten')

console.log(grid.toString())

Output:

This is the top cell
spanning the entire
width


Left      This text
column    have been
          overwritt…

API

grid = new Grid(options)

Provide an options object as the first argument. The following options are supported:

  • width - The total width of the viewport (defaults to process.stdout.columns)
  • height - The total height of the viewport (defaults to process.stdout.rows)
  • rows - An array of rows. Each row is an array of cell objects

A cell object supports the following properties:

  • width - The width of the cell. If the value is the string auto it will fill out the remaining space in the viewport. If the value is a string containing a percent sign (e.g. 25%), it's treated as a percentage of the total width of the viewport. Otherwise it's treated as an integer representing the width in columns (defaults to auto)
  • height - The height of the cell. If the value is the string auto it will fill out the remaining space in the viewport. If the value is a string containing a percent sign (e.g. 25%), it's treated as a percentage of the total height of the viewport. Otherwise it's treated as an integer representing the height in rows (defaults to auto)
  • text - Default text content of the cell (defaults to an empty string)
  • wrap - Set to false to disable automatic line wrapping (defaults to true)
  • padding - An optional array of cell padding for the top, right, bottom, and left edge of the cell respectively, e.g. [0, 2, 0, 2] for 2 chars of padding on the left and right edge only. If given an integer instead of an array, the padding is applied to all edges

You can use strings instead of objects for cells. This is equivalent to {text: cell}

grid = new Grid(rows)

An alias for:

new Grid({rows: rows})

Event: update

Emitted every time a cell in the grid is updated.

grid.update(row, cell, text)

Update the text content of a cell.

Arguments:

  • row - The row index
  • cell - The cell index inside the row
  • text - The new text content of the cell

grid.resize(width, height)

Resize the viewport to new width and height.

cell = grid.cellAt(row, index)

Return the cell at the gien row and index`.

str = grid.toString()

Render all content in all cells in the grid and return the result as one big string.

License

MIT