Page MenuHomePhabricator

D9597.diff
No OneTemporary

D9597.diff

diff --git a/src/utils/__tests__/PhutilUTF8TestCase.php b/src/utils/__tests__/PhutilUTF8TestCase.php
--- a/src/utils/__tests__/PhutilUTF8TestCase.php
+++ b/src/utils/__tests__/PhutilUTF8TestCase.php
@@ -110,6 +110,10 @@
// Combining plus double-width.
"\xe6\x9d\xb1\xCD\xA0y" => 3,
+
+ // Colors and formatting.
+ "\e[1mx\e[m" => 1,
+ "\e[1m\e[31mx\e[m" => 1,
);
foreach ($strings as $str => $expect) {
$this->assertEqual(
diff --git a/src/utils/utf8.php b/src/utils/utf8.php
--- a/src/utils/utf8.php
+++ b/src/utils/utf8.php
@@ -190,6 +190,9 @@
*/
function phutil_utf8_console_strlen($string) {
+ // Formatting and colors don't contribute any width in the console.
+ $string = preg_replace('/\e\[\d*m/', '', $string);
+
// In the common case of an ASCII string, just return the string length.
if (preg_match('/^[\x01-\x7F]*\z/', $string)) {
return strlen($string);

File Metadata

Mime Type
text/plain
Expires
Wed, Mar 19, 9:57 AM (1 d, 6 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7710566
Default Alt Text
D9597.diff (934 B)

Event Timeline