phplucidframe / console-table

ConsoleTable helps you to display tabular data in a terminal/shell/console
Other
99 stars 22 forks source link

Using terminal colors ( \033[0m ) breaks alignment #2

Closed Faexa closed 6 years ago

Faexa commented 7 years ago

Hi, First, thank you for this code ! If you use terminal colors / text decoration for example:

echo "\033[44m\033[7mHi\033[0m";

the table alignment is broken This is probably due to strlen($col) in calculateColumnWidth function, counting everything in the string, wich end up not printed on cli.

You should remove every extra caracters before counting string lengh, with for example

$test = preg_replace('#\x1b[[][^A-Za-z]*[A-Za-z]#', '', $test);

(found here: https://stackoverflow.com/questions/40731273/php-remove-terminal-codes-from-string)

cithukyaw commented 7 years ago

@Faexa Thanks for using this library. I will look into it. PR also welcome.

cithukyaw commented 7 years ago

@Faexa Can you please provide an example usage how to add colors? I mean reproducing step.

dblencowe commented 6 years ago

Resolved in https://github.com/phplucidframe/console-table/pull/9

cithukyaw commented 6 years ago

@dblencowe I've merged your PR. Thanks for your contribution