Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add a flag for plain progress #4337

Open
mja00 opened this issue Mar 11, 2025 · 1 comment
Open

Add a flag for plain progress #4337

mja00 opened this issue Mar 11, 2025 · 1 comment
Assignees

Comments

@mja00
Copy link

mja00 commented Mar 11, 2025

Is your feature request related to a problem? Please describe.
Currently this line causes the progress to be sent on the same line. While this works fine for TTYs it causes headaches for programs that spawn a fork for zstd. Since this is rewriting the same line every time it sometimes can cause stderr to not be triggered with the data.

For instance using child_process's spawn from Nodejs.

const spawn = require('node:child_process').spawn;

const exec = spawn('zstd', ['-4', 'test.tar']);

exec.stderr.on((data) => {
    // Only fired once at the end of execution
    console.log(data.toString());
});

This only ever logs the final output of test.tar : 83.16% (1067089920 => 887358325 bytes, test.tar.zst) which is unhelpful for progress tracking.

Describe the solution you'd like
Please add a flag that allows plain progress output. Something that just posts the progress on a new line each update.

Describe alternatives you've considered
I've attempted to use a few tricks, such as using ReadLine.createInterface and a fake TTY.

@Cyan4973 Cyan4973 self-assigned this Mar 11, 2025
@Cyan4973
Copy link
Contributor

Cyan4973 commented Mar 11, 2025

If I understand correctly,
you want to update your user interface with notifications that help your end user visualize progress,
and to do that you are relying on parsing the output of the zstd command line utility.

Now your issue is that the zstd command line program uses in-place updates, aka overwrites the same line, in order to present a stable output for its own console interface. Since it's not a new line, parsing isn't naturally accomplished by baseline NodeJS console parser(s) which mostly expect reacting to new line '\n' events.

The requested option would be to change the behavior of zstd by making it write one new line per update event.

While this is technically possible, it's not a good reason enough: it also matters to look around in the ecosystem to understand what's generally expected in similar circumstances.

In this case, in-place updates are becoming common among command line utilities. One can think of pv, wget, curl, dd, git, rsync, and more. All these command line programs display a compact in-place update interface.
None of them provide a flag to output one line per update event, as requested here.
And that makes me wonder if this is the right thing to do.

As mentioned, it's not that there aren't solutions. There are myriads of solutions. It's more a matter of what's the established convention if there is, which responsibility is supposed to be carried by which layer.

Fortunately, a Graphical overlay on top of a command line tool which uses in-place notifications is not something new.
For example, there are several such overlays for wget.

Looking around, a common approach seems to use node-pty.
For example:

const pty = require('node-pty');

const zstdProcess = pty.spawn('zstd', ['-19', '-T0', 'nodecraft.tar'], {
  name: 'xterm-color',
  cols: 80,
  rows: 30,
  cwd: process.env.HOME,
  env: process.env
});

zstdProcess.on('data', (data) => {
  // 'data' will contain the progress output with carriage returns
  console.log('Progress update:', data);
});

Another approach could be to parse input at character level, looking for the Carriage Return signal, and generating an update event at that point.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants