seckcoder / prettytable

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

xterm reset escape sequence not filtered #63

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
#!/usr/bin/python
import prettytable.v0_7_2 as prettytable

x = prettytable.PrettyTable(["City name", "Area", "Population", "Annual 
Rainfall"])
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(B\033[m"])
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

What is the expected output?
  +-----------+------+------------+-----------------+
  | City name | Area | Population | Annual Rainfall |
  +-----------+------+------------+-----------------+
  |  Adelaide | 1295 |  1158259   |      600.5      |
  |  Brisbane | 5905 |  1857594   |      1146.4     |
  |   Darwin  | 112  |   120900   |      1714.7     |
  |   Hobart  | 1357 |   205556   |      619.5      |
  |   Sydney  | 2058 |  4336374   |      1214.8     |
  | Melbourne | 1566 |  3806092   |      646.9      |
  |   Perth   | 5386 |  1554769   |      869.4      |
  +-----------+------+------------+-----------------+

What do you see instead?
  +-----------+------+------------+-----------------+
  | City name | Area | Population | Annual Rainfall |
  +-----------+------+------------+-----------------+
  |  Adelaide | 1295 |  1158259   |      600.5      |
  |  Brisbane | 5905 |  1857594   |    1146.4    |
  |   Darwin  | 112  |   120900   |      1714.7     |
  |   Hobart  | 1357 |   205556   |      619.5      |
  |   Sydney  | 2058 |  4336374   |      1214.8     |
  | Melbourne | 1566 |  3806092   |      646.9      |
  |   Perth   | 5386 |  1554769   |      869.4      |
  +-----------+------+------------+-----------------+

What version of the product are you using? On what operating system?
v0.7.2

Please provide any additional information below.
The regular expression _re = re.compile("\033\[[0-9;]*m") doesn't match the 
xterm escape sequence for reset:

$ TERM=xterm tput sgr0 | od -xa
0000000    281b    1b42    6d5b
        esc   (   B esc   [   m
0000006

It can be fixed by tweaking the regexp a little:
_re = re.compile("\033(\[[0-9;]*m|\(B)")

Original issue reported on code.google.com by dan...@lbe.rs on 9 Dec 2014 at 4:50

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
rxvt and screen are affected in the same way:

$ for TERM in rxvt screen screen-256color; do echo -n $TERM:\ ; tput sgr0 | cat 
-A; echo; done | sortrxvt: ^[[m^O
screen-256color: ^[[m^O
screen: ^[[m^O

Using a regex like
  _re = re.compile("\033(\[[0-9;]*m\017?|\(B)")
fixes these as well.

Original comment by dan...@lbe.rs on 13 May 2015 at 2:48