Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xterm reset escape sequence not filtered #63

Open
GoogleCodeExporter opened this issue Sep 1, 2015 · 2 comments
Open

xterm reset escape sequence not filtered #63

GoogleCodeExporter opened this issue Sep 1, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant