Skip to content

Commit

Permalink
Merge pull request #97 from maricn/master
Browse files Browse the repository at this point in the history
fix: Don't fail rendering on stderr warnings
  • Loading branch information
faressoft authored Jul 8, 2023
2 parents 8548d79 + 797860e commit d19d0d0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[![Unicorn](https://img.shields.io/badge/nyancat-approved-ff69b4.svg)](https://www.youtube.com/watch?v=QH2-TGUlwu4)
[![Tweet](https://img.shields.io/badge/twitter-share-76abec.svg)](https://goo.gl/QJzJu1)

> Record your terminal and generate animated gif images or share a web player link [terminalizer.com](https://terminalizer.com)
> Record your terminal and generate animated gif images or share a web player link [terminalizer.com](https://terminalizer.com)
<p align="center"><img src="/img/demo.gif?raw=true"/></p>

Expand Down
50 changes: 41 additions & 9 deletions commands/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ function renderFrames(records, options) {
// The number of frames
var framesCount = records.length;

// Track execution time
var start = Date.now();

// Create a progress bar
var progressBar = getProgressBar(
"Rendering",
Expand All @@ -116,24 +119,47 @@ function renderFrames(records, options) {
{ detached: false }
);

render.stderr.on("data", function (error) {
render.kill();
reject(new Error(error));
});
render.stdout.on('data', onData);
render.stderr.on('data', onError);
render.on('close', onClose);

// Track progress of rendering through stdout
function onData(data) {

render.stdout.on("data", function (data) {
// Is not a recordIndex (to skip Electron's logs or new lines)
if (di.is.not.number(parseInt(data.toString()))) {
return;
}

progressBar.tick();
}

// Track rendering errors observed on stderr
function onError(error) {

// If error is Buffer, print it, otherwise reject
if (!!error && error instanceof Buffer) {
console.log(di.chalk.yellow(`[render] ${error.toString('utf8').trim()}`));
} else {
render.kill();
reject(new Error("Unknown error [" + typeof error + "]: " + error));
}
}

// React when rendering process finishes
function onClose(code) {
if (code !== 0) {
reject(new Error("Rendering exited with code " + code));
} else {
if (progressBar.complete) {
console.log(di.chalk.green('[render] Process successfully completed in ' + (Date.now() - start) + 'ms.'));
} else {
console.log(di.chalk.yellow('[render] Process completion unverified'));
}

// Rendering is completed
if (progressBar.complete) {
resolve();
}
});
};
});
}

Expand All @@ -149,6 +175,9 @@ function mergeFrames(records, options, frameDimensions) {
return new Promise(function (resolve, reject) {
// The number of frames
var framesCount = records.length;

// Track execution time
var start = Date.now();

// Used for the step option
var stepsCounter = 0;
Expand Down Expand Up @@ -221,6 +250,9 @@ function mergeFrames(records, options, frameDimensions) {

// Write the footer
gif.finish();

// Finish
console.log(di.chalk.green('[merge] Process successfully completed in ' + (Date.now() - start) + 'ms.'));
resolve();
}
);
Expand Down Expand Up @@ -271,7 +303,7 @@ function command(argv) {

// The path of the output file
var outputFile = di.utility.resolveFilePath(
"render" + new Date().getTime(),
"render" + Date.now(),
"gif"
);

Expand Down

0 comments on commit d19d0d0

Please sign in to comment.