An open API service indexing awesome lists of open source software.

https://github.com/codelenny/sh2png

Screenshot console output
https://github.com/codelenny/sh2png

Last synced: 2 months ago
JSON representation

Screenshot console output

Awesome Lists containing this project

README

          

# Shell to PNG
Tools exist to screenshot websites, but why aren't there tools to screenshot console contents?

Add sample usage to your README as part of your build system, keep a tutorial's command line examples updated, or easily create a bug report without as much copy/paste.

And yes, the tool is compatible with all shells and many image formats, despite it's misleading name.

[![npm](https://img.shields.io/npm/v/sh2png.svg)](https://www.npmjs.com/package/sh2png)
[![Build Status](https://travis-ci.org/CodeLenny/sh2png.svg?branch=master)](https://travis-ci.org/CodeLenny/sh2png)

## Sample Output

![Mocha's output](test/sample/format-mocha.png)

This image was created by passing the result of calling [Mocha](https://mochajs.org/) into `sh2png.format`.

See [test-format-mocha-output.coffee](test/test-format-mocha-output.coffee) for the test that produced the output above.
See the [results](test/sample/) of testing sh2png for other examples.

## Versioning

As per usual for Node applications, sh2png follows [Semantic Versioning](http://semver.org/).
See the [CHANGELOG](./CHANGELOG.md) for information about each release.

For stability, minor versions are used if either
- internal (private) methods are altered to have a different API
- bugs are fixed that people [might rely on](https://github.com/expressjs/express/issues/1794)

What does this mean? Lock down your minor number for sh2png in `package.json` if you:
- Use images outputted sh2png in testing, where us fixing a pixel will break your test
- Extend the sh2png class, and depend on the internal method signatures
- Are building a core utility, which might have users in one of the above categories.

Otherwise, upgrading to the latest minor version or patch should be safe, as the public API should remain the same.

Either way, consider subscribing to an [ATOM feed](https://github.com/CodeLenny/sh2png/releases.atom) of our releases,
so you can be notified about new versions.

## Installation

Install via [NPM](https://www.npmjs.com/).

Don't have NPM? Grab [NodeJS](https://nodejs.org/en/download/) or [Node Version Manager](https://github.com/creationix/nvm).

```sh
npm install [--save-dev] sh2png
```

## Console Usage

You can pipe text to `sh2png` on the command line. See `sh2png --help` for more information.

![`sh2png --help`](test/sample/console-format-stdout.png)

(Created via `sh2png --help | sh2png - > help.png`)

Install the CLI utility globally across your entire computer via `npm install -g sh2png`, or access a locally installed
binary via `$(npm bin)/sh2png`.

## Node.js Usage

### Formatting Strings

Got some text from the console? Call `sh2png.format` to turn a string of console text into an image. `format` returns a [Promise].

Don't want to use Promises? Here's some standard NodeJS code.

```js
sh2png = require("sh2png");
exec = require("child_process").exec;
env = process.env;
env.force_color_prompt = "yes";

exec("mocha", {env: env}, function (err, stdout, stderr) {
// handle error
sh2png
.format(stdout)
.then(function (img) {
img.write(__dirname + "mocha_output.png", function(err) {
// handle error
});
})
.catch(function (err) {
// handle error
});
});
```

Want to use [Promises][Promise]? (Example in CoffeeScript)

```coffeescript
sh2png = require "sh2png"
{exec} = require "child-process-promise"
env = process.env
env.force_color_prompt = "yes"

exec "mocha", {env}
.then ({stdout}) ->
sh2png.format stdout
.then (img) ->
img.writeAsync "#{__dirname}/mocha_output.png"
.then ->
# image written
.catch (err) ->
console.log err
```

See documentation for [sh2png.format] for more information.

## Extending sh2png

If you want to extend sh2png, you're in luck. The source is object oriented, with documentation for each method.
Simply override the methods you want to replace, and you're good to go!

[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
[sh2png.format]: https://codelenny.github.io/sh2png/docs/#https://codelenny.github.io/sh2png/docs/class/sh2png.html#format-static