seckcoder / prettytable

Automatically exported from code.google.com/p/prettytable
Other
0 stars 0 forks source link

table.align["xyz"] = "l" doesn't work when color is added ('\033[34mxyz\033[0m') to the header fields. #33

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Set header field to left table.align["xyz"] = "l"
2. Wrap header field with ansi colors table.header(['\033[34mxyz\033[0m']) 
3. Print table

What is the expected output? What do you see instead?
All the values under field xyz should be aligned to the left, but they're 
instead aligned at the center.

What version of the product are you using? On what operating system?
Python 2.7.2 OS X 10.8.4 prettytable (0.7.2)

Please provide any additional information below.
It would be a nice feature to be able to add color to fields and values.

Original issue reported on code.google.com by SShagin...@gmail.com on 21 Aug 2013 at 4:26

GoogleCodeExporter commented 9 years ago
Hi there, sorry for the slow response.

Your step 2, table.header(['\033[34mxyz\033[0m']), is not a valid use of the 
PrettyTable API.  The header attribute is a boolean flag, not a callable 
function.

I assume you meant maybe something like table.field_names = 
['\033[34mxyz\033[0m'], i.e. you want one of the field names to be in colour.

I can't replicate your problem, I've included ANSI color codes in a field name 
and the alignment continues to work as expected.

Could you please paste some valid code which runs and demonstrates your issue?

Thank you for the report.

Original comment by luke@maurits.id.au on 5 Oct 2013 at 10:26

GoogleCodeExporter commented 9 years ago
I'm also having the same problem here except it only happens over ssh. If I run 
my program locally the formatting is just fine. 

Original comment by creiganw...@gmail.com on 22 Feb 2014 at 11:58

GoogleCodeExporter commented 9 years ago
This shall reproduce it. I think the issue 54 I opened is related to this one:

#!/usr/bin/python
from prettytable import PrettyTable

x = PrettyTable(["City name", "Area", "Population", "Annual Rainfall"])
x.align["City name"] = "l" # Left align city names
x.padding_width = 1 # One space between column edges and contents (default)
x.add_row(["Adelaide",1295, 1158259, 600.5])
x.add_row(["Brisbane",5905, 1857594, "\033[94m1146.4\033[0m"])
x.add_row(["Darwin", 112, 120900, 1714.7])
x.add_row(["Hobart", 1357, 205556, 619.5])
x.add_row(["Sydney", 2058, 4336374, 1214.8])
x.add_row(["Melbourne", 1566, 3806092, 646.9])
x.add_row(["Perth", 5386, 1554769, 869.4])
print x

Original comment by obaidmus...@gmail.com on 6 Jun 2014 at 10:50