Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add strwidth(), called by safe_str_pad(). Add unicode/regex.php.#107

Merged
schlessera merged 6 commits into
wp-cli:masterwp-cli/php-cli-tools:masterfrom
gitlost:issue_102gitlost/php-cli-tools:issue_102Copy head branch name to clipboard
Jul 23, 2017
Merged

Add strwidth(), called by safe_str_pad(). Add unicode/regex.php.#107
schlessera merged 6 commits into
wp-cli:masterwp-cli/php-cli-tools:masterfrom
gitlost:issue_102gitlost/php-cli-tools:issue_102Copy head branch name to clipboard

Conversation

@gitlost

@gitlost gitlost commented Jul 23, 2017

Copy link
Copy Markdown
Contributor

Issue #103

Adds strwidth() to calculate the spacing width, and uses it in safe_str_pad(). Uses grapheme_strlen(), preg_match_all( '/\X/u' ), mb_strwidth() or safe_strlen() depending on availability/charset.

To account for East Asian double-width characters, and (in the unlikely case of falling back to mb_strwidth() for UTF-8) for Mark characters, it uses a generated unicode/regex.php file containing regexs, generated using tools/gen_east_asian_width.php and tools/gen_cat_regex_alts.php, which currently reside at https://github.com/gitlost/unfc-normalize as they use a library developed for that plugin, but can be adapted and brought over to php-cli-tools if desired.

Also fixes an issue with printing fields with percents in them when shouldColorize() is disabled (after wp-cli/wp-cli#2458).

Edit: also adds Colors::width() and uses it and strwidth() to calculate table widths, fixing padding.

Comment thread lib/cli/Colors.php Outdated
* @return int
*/
static public function width($string) {
if (isset(self::$_string_cache[md5($string)]['decolorized'])) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The md5($string) should only be computed once.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ta, fixed.

@schlessera schlessera added this to the 0.11.4 milestone Jul 23, 2017
@schlessera schlessera merged commit e02568e into wp-cli:master Jul 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.