A viewport into a virtual grid of text cells
npm install virtual-gridA 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.


```
npm install virtual-grid --save
`js
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…
`
Provide an options object as the first argument. The following options
are supported:
- width - The total width of the viewport (defaults toprocess.stdout.columns
)height
- - The total height of the viewport (defaults toprocess.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 it25%
will fill out the remaining space in the viewport. If the value is a
string containing a percent sign (e.g. ), it's treated as aauto
percentage of the total width of the viewport. Otherwise it's treated
as an integer representing the width in columns (defaults to )height
- - The height of the cell. If the value is the string auto25%
it will fill out the remaining space in the viewport. If the value is
a string containing a percent sign (e.g. ), it's treated as aauto
percentage of the total height of the viewport. Otherwise it's treated
as an integer representing the height in rows (defaults to )text
- - Default text content of the cell (defaults to an emptywrap
string)
- - Set to false to disable automatic line wrapping (defaultstrue
to )padding
- - An optional array of cell padding for the top, right,[0, 2, 0, 2]
bottom, and left edge of the cell respectively, e.g.
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}
An alias for:
`js`
new Grid({rows: rows})
Emitted every time a cell in the grid is updated.
Update the text content of a cell.
Arguments:
- row - The row indexcell
- - The cell index inside the rowtext
- - The new text content of the cell
Resize the viewport to new width and height.
Return the cell at the gien row and index.
Render all content in all cells in the grid and return the result as one
big string.
MIT