seckcoder / prettytable

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

Changes to border line styes [was: Requests for enhancement] #22

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi, this is a request for an enhancement. I would like to be able to print 
these two kind of tables, but as far as I understand this is currently not 
possible with prettytable:

header1   header2  header3
===========================
 x1y1      x2y1     x3y1
 x1y2      x2y2     x3y2
 x1y3      x2y3     x3y3

i.e. only an hrule under the header (possibly, updating the character used)

And also the following syntax is quite common:

+----------------------------+
| header1   header2  header3 |
+============================+
|  x1y1      x2y1     x3y1   |
|  x1y2      x2y2     x3y2   |
|  x1y3      x2y3     x3y3   |
+----------------------------+

i.e. a frame around the table, and a different horizontal rule under the header.

Original issue reported on code.google.com by antonio....@gmail.com on 19 Jan 2013 at 9:40

GoogleCodeExporter commented 9 years ago
Hi, thanks for this suggestion.

I have made changes to the SVN trunk such that it is now partially possible to 
get the styles you want.

The "hrules" attribute, which could previously take values FRAME, ALL or NONE 
can now also be set to HEADER, which prints a hrule only under the header, like 
your first example.

In addition to the old "hrules" attribute, there is now also "vrules", which 
can be take values FRAME, ALL or NONE.

By setting hrules=HEADER and vrules=NONE, along with horizontal_character="=" 
and junction_character="=", it should be possible to achieve the first example 
table you gave.

By setting hrules=FRAME and vrules=FRAME, you can get something close to your 
second example, the only difference being that you still won't have - as the 
horizontal character for the frame and = as the horizontal character for the 
header.

I may add the option for two different kind of horizontal characters, or I may 
not, I am not sure yet.  It seems harmless enough, but if I do that, then 
somebody will want the ability to, e.g, make a table like this:

+=====+=====+
| Foo . Bar |
+-----+-----+
|  1  .  2  |
+=====+=====+

i.e. where the external rules are different from the internal rules, and then 
if I do that somebody will want something else, and before you know it instead 
of just horizontal_char, vertical_char and junction_char there will have to be 
12 different attributes controlling the way lines are drawn to cover all the 
edge cases...

In general I am not opposed to putting in stuff to let people tweak their 
tables in all the little ways they want, but only if that doesn't make it 
difficult for the majority of people to do simple things.  If someone just 
wants to use, say, "=" as their horizontal line everywhere, they should be able 
to do that by setting one attribute, and should not be forced to set 3 or 4 
attributes corresponding to all the different kinds of horizontal line if they 
don't care about the differences.

Original comment by luke@maurits.id.au on 22 Jan 2013 at 12:43

GoogleCodeExporter commented 9 years ago
First of all, thank you very much.

About the way prettytable works, I think that you should distinguish among:

* header line
* frame border
* horizontal rules
* vertical rules

I personally thing that controlling independently if these components of the 
table should be showed or not is more important than using '&' for the 
horizontal lines, which would produce a ugly table, plain and simple :). 

I also think that if vrules==FRAME, then the code should not use the standard 
junction_char but use the horizontal_char instead. The following code, for 
example:

    import prettytable as pt

    p = pt.PrettyTable()
    p.add_row(range(4))
    p.add_row(range(5,9))

    p.hrules=pt.ALL
    p.vrules=pt.FRAME
    print p

should produce the following result:

+---------------------------------------+
| Field 1   Field 2   Field 3   Field 4 |
+---------------------------------------+
|    0         1         2         3    |
+---------------------------------------+
|    5         6         7         8    |
+---------------------------------------+

instead of

+---------+---------+---------+---------+
| Field 1   Field 2   Field 3   Field 4 |
+---------+---------+---------+---------+
|    0         1         2         3    |
+---------+---------+---------+---------+
|    5         6         7         8    |
+---------+---------+---------+---------+

Original comment by antonio....@gmail.com on 22 Jan 2013 at 8:26

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by luke@maurits.id.au on 18 Feb 2013 at 7:12

GoogleCodeExporter commented 9 years ago
I've made changes in trunk which fix the issue with printing spurious junction 
characters as part of the horizontal lines when vrules is set to FRAME.  Thanks 
for pointing out this shortcoming.

Original comment by luke@maurits.id.au on 19 Feb 2013 at 5:38