sh2png
v1.1.0
Published
Screenshot console output.
Downloads
2
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.
Sample Output
This image was created by passing the result of calling Mocha into sh2png.format
.
See test-format-mocha-output.coffee for the test that produced the output above. See the results of testing sh2png for other examples.
Versioning
As per usual for Node applications, sh2png follows Semantic Versioning. See the CHANGELOG 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
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 of our releases, so you can be notified about new versions.
Installation
Install via NPM.
Don't have NPM? Grab NodeJS or Node Version Manager.
npm install [--save-dev] sh2png
Console Usage
You can pipe text to sh2png
on the command line. See sh2png --help
for more information.
(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.
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? (Example in 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!