Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Terminal.write() & console ANSI escape sequences #135

Closed
emmercm opened this issue Feb 6, 2023 · 5 comments
Closed

Terminal.write() & console ANSI escape sequences #135

emmercm opened this issue Feb 6, 2023 · 5 comments
Labels
bug validated issue validated by maintainer

Comments

@emmercm
Copy link

emmercm commented Feb 6, 2023

I have a custom format function that makes heavy use of chalk coloring:

https://github.com/emmercm/igir/blob/1ba176d54877dc01aafe13df2abe57ddd6fb2926/src/console/singleBarFormatted.ts#L30

(see the Asciicast in the project's readme for a video of how it renders)

The default formatter takes into account ANSI escape sequences by using string-width to calculate the true width of a string, but this is only for alignment. Terminal.write() doesn't use string-width and instead trims all lines to process.stdout.columns.

@emmercm emmercm changed the title GenericBar formatter maxWidth & console ANSI escape sequences Terminal.write() & console ANSI escape sequences Feb 6, 2023
@emmercm
Copy link
Author

emmercm commented Feb 6, 2023

I think it's because MultiBar, which has its own Terminal instance, sets linewrap: false:

// disable line wrapping ?
if (this.options.linewrap === false){
this.terminal.lineWrapping(false);
}

but when it spawns new GenericBars:

// create new bar element
const bar = new _BarElement(Object.assign({}, this.options, barOptions));

those each get their own Terminal instance which default to linewrap: true:

this.terminal = (this.options.terminal) ? this.options.terminal : new _Terminal(this.options.stream);

@AndiDittrich
Copy link
Member

the hard-trimming within terminal.write was required to avoid issues on different platforms .. i know this might cause such issues - atm i've no "real "solution without adding a heavy library (slow!) which take the ascii sequences into account.

regarding the terminal instances: you're right, that looks weak .. i'm not shure why i've didn't passed the "global" instance to the generic bars. i've to take a look into

@AndiDittrich AndiDittrich added bug validated issue validated by maintainer labels Feb 7, 2023
@emmercm
Copy link
Author

emmercm commented Feb 7, 2023

You're right, I think my original post is incorrect here. I think it's because the linewrap setting isn't being respected for multi-bars.

@AndiDittrich
Copy link
Member

i've applied the fix which uses the same terminal instance for all bars

@emmercm
Copy link
Author

emmercm commented Mar 17, 2023

Confirmed that this fixed my issue! Sorry for the slow feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug validated issue validated by maintainer
Projects
None yet
Development

No branches or pull requests

2 participants