# ansi-scrollbox

> a basic scrollable area for terminal apps

Latest version **0.2.1** (published 2019-07-11) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install ansi-scrollbox
pnpm add ansi-scrollbox
yarn add ansi-scrollbox
bun add ansi-scrollbox
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2019-07-11 |
| First published | 2018-04-18 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 9.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Renée Kooi |
| Maintainers | goto-bus-stop |
| Keywords | ansi, cli, command-line, scroll, scrollable, scrollbox, terminal |

## Links

- npm: https://www.npmjs.com/package/ansi-scrollbox
- Repository: https://github.com/goto-bus-stop/ansi-scrollbox
- Issues: https://github.com/goto-bus-stop/ansi-scrollbox/issues
- npm.io page: https://npm.io/package/ansi-scrollbox

## Dependencies (1)

- [wrap-ansi](https://npm.io/package/wrap-ansi.md) ^3.0.1

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 0.2.1 (latest) — 2019-07-11
- 0.2.0 — 2018-04-20
- 0.1.0 — 2018-04-18

## README

# ansi-scrollbox

a basic scrollable area for terminal apps

[![npm][npm-image]][npm-url]
[![travis][travis-image]][travis-url]
[![standard][standard-image]][standard-url]

[npm-image]: https://img.shields.io/npm/v/ansi-scrollbox.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/ansi-scrollbox
[travis-image]: https://img.shields.io/travis/goto-bus-stop/ansi-scrollbox.svg?style=flat-square
[travis-url]: https://travis-ci.org/goto-bus-stop/ansi-scrollbox
[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square
[standard-url]: http://npm.im/standard

## Install

```
npm install ansi-scrollbox
```

## Usage

```js
var scrollbox = require('ansi-scrollbox')
var differ = require('ansi-diff')()
var lorem = require('@jamen/lorem')

var box = scrollbox({
  width: 20,
  height: 20
})

box.setContent(lorem(6000))

function render () {
  process.stdout.write(differ.update(box.toString()))
}
setInterval(render, 100)

require('keypress')(process.stdin)
process.stdin.setRawMode(true)
process.stdin.resume()
// Optionally add default scroll keybindings (things like up, down, home, end)
process.stdin.on('keypress', box.keypress)
```

## API

### `box = scrollbox(opts={})`

Prepare a new scrollbox.

- `opts.width` - Width in columns of the scrollbox.
- `opts.height` - Height in rows of the scrollbox.

### `box.setContent(content)`, `box.content = content`

Set the content of the scrollbox.

### `box.content`

Get the content of the scrollbox.

### `box.scroll(offset)`

Set the scroll position. `offset` is the number of rows from the start of the content. When `offset` is negative, it's the number of rows from the end of the content. Use -1 to scroll to the very end; -1 is "sticky" so it will stay at the end when the content updates.

### `box.resize(opts)`

Update the size of the scrollbox.

- `opts.width` - Width in columns of the scrollbox.
- `opts.height` - Height in rows of the scrollbox.

### `box.toString()`

Get the visible contents of the box. Use with something like [ansi-diff](https://github.com/mafintosh/ansi-diff) for efficient updates on screene.

### `unsub = box.subscribe(listener)`

Call `listener` whenever the box's content, size, or scroll position change. Do `unsub()` to stop listening.

### `box.keypress`

An event listener that implements basic keyboard controls:

- `up` or `k` to scroll 1 row up
- `down` or `j` to scroll 1 row down
- `home` to scroll to the start
- `end` to scroll to the start

Use it with the [keypress](https://github.com/TooTallNate/keypress) module:

```js
require('keypress')(process.stdin)
process.stdin.on('keypress', box.keypress)
```

## License

[Apache-2.0](LICENSE.md)

---
_Source: https://npm.io/package/ansi-scrollbox · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
