How to get both live and programmatic output?
Closed this issue ยท 3 comments
I'm trying to print a command's live output, and while also capturing the output, so I can calculate the number of printed lines and erase them from the terminal.
console.log('\x1b[40m') // Black background
const { stdout } = await $({
shell: true, // Error: No overload matches this call.
stdout: ['inherit', 'pipe'],
stderr: 'inherit',
})`${installCommand}`
const lines = (stdout.match(/\n/g) || []).length + 1
console.log('\x1b[49m') // Reset background color
process.stdout.write(cursor.move(-999, -lines))
process.stdout.write(erase.down(lines))
Here's the full error:
No overload matches this call.
The last overload gave the following error.
Object literal may only specify known properties, and 'shell' does not exist in type 'TemplateStringsArray'.
I'm not sure if this is related, but the docs say:
When combining 'inherit' with other values, please note that the subprocess will not be an interactive TTY, even if the current process is one.
How can I both print the live output and capture it programmatically so I can remove it from the console?
Also, any pointers to terminal UI libraries that do this kind of "windowed/boxed output" would be appreciated ๐
Hi @andrecasal,
Thanks for reaching out.
There are four separate questions in your post. Please kindly keep it focused on a single bug per issue. Also, it must be strictly Execa-related, as opposed to general questions about terminals. :)
Also, any pointers to terminal UI libraries that do this kind of "windowed/boxed output" would be appreciated ๐
This is not Execa-related. However, boxen
is an option.
How can I both print the live output and capture it programmatically
Using ['inherit', 'pipe']
as you're doing is the correct way.
so I can remove it from the console?
This is not Execa-related. But clearing the screen is the correct way. readline.clearLine()
, readline.clearScreenDown()
and readline.cursorTo(process.stderr, 0, 0)
might help.
Here's the full error:
This is a type error, not a runtime error, is this correct? If so, I cannot reproduce (see TypeScript playground). Are you using the last Execa version? Can you share a reproducible type error using the TypeScript playground?
A possible reason could be that installCommand
has the wrong type.
As a side note, when passing the install command using ${installCommand}
, please make sure you read the following section of the documentation.
Hey, @ehmicky ๐
My main question was about the type error, everything else was for context which often helps understand nuances in the question.
Updating to the latest version solved the problem, thank you!
Do you know of a library that can present live output and erase it at the end in a cross-platform way, like GitHub Actions for example, where a huge output can, at the end, collapse into a single summary bullet point โ
Do you know of a library that can present live output and erase it at the end in a cross-platform way, like GitHub Actions for example, where a huge output can, at the end, collapse into a single summary bullet point โ
No.
I am glad your problem was solved. ๐