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

fix: Adding Better regex for ansi codes stripping from the string #435

Merged
merged 2 commits into from Feb 15, 2023

Conversation

wmalkin
Copy link
Contributor

@wmalkin wmalkin commented Dec 1, 2022

Modified regex to allow for more variations of ansi codes like '\x1b[38;5m', bolding, etc.

πŸ‘€What is this pr about?

Measurement of string width removes ansi escape codes for color, but only the ansi escape codes produced by the library. This change modifies the regex that strips escape codes for correct string width measurement to include more codes that can be inserted into the content text items by the caller.

πŸš€ Changes

Updated

Width measurement regex

πŸ–Ό Screenshots

before:
β”Œβ”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”
β”‚ a β”‚ c β”‚ b β”‚
β”œβ”€β”€β”€β”Όβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€
β”‚ 1 β”‚ 55 β”‚ β”‚
β”‚ β”‚ β”‚ 1 β”‚
β””β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”˜

after:
β”Œβ”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”
β”‚ a β”‚ c β”‚ b β”‚
β”œβ”€β”€β”€β”Όβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€
β”‚ 1 β”‚ 55 β”‚ β”‚
β”‚ β”‚ β”‚ 1 β”‚
β””β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”˜

πŸ‘Ά The naming of the PR

fix: ansi escape codes stripped better for measurement

Modified regex to allow for more variations of ansi codes like '\x1b[38;5m', bolding, etc.
@ayonious
Copy link
Owner

ayonious commented Dec 5, 2022

This is amazing! Thanks a lot! Could you also add some nice tests in console-utils.test.ts?
@wmalkin

@ayonious ayonious changed the title Measure ansi escape codes correctly fix: Adding Better regex for ansi codes stripping from the string Feb 15, 2023
@ayonious ayonious merged commit a90525f into ayonious:master Feb 15, 2023
ayonious pushed a commit that referenced this pull request Jul 2, 2023
## [2.11.2](v2.11.1...v2.11.2) (2023-07-02)

### Bug Fixes

* Adding Better regex for ansi codes stripping from the string ([#435](#435)) ([a90525f](a90525f))
* Allow empty Column Title ([#451](#451)) ([4323d60](4323d60))
* Remove Crimson as basic color ([#450](#450)) ([ec89482](ec89482))
@ayonious
Copy link
Owner

ayonious commented Jul 2, 2023

πŸŽ‰ This PR is included in version 2.11.2 πŸŽ‰

The release is available on:

Your semantic-release bot πŸ“¦πŸš€

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

Successfully merging this pull request may close these issues.

None yet

2 participants