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

On a dumb terminal the table output of keep list now is unreadable and contains the wrong escape sequences. #47

Closed
halloleo opened this issue Jan 13, 2019 · 10 comments
Labels

Comments

@halloleo
Copy link

When using keep on "dump" terminals (TERM=dumb) the command keep list produces a table with the wrong escape sequences:

^[(0lqqqqqqqqqqqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqqqqqqk^[(B
^[(0x^[(B Command    �(0x�(B Description                                       �(0x�(B Alias �(0x�(B
^[(0tqqqqqqqqqqqqnqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqnqqqqqqqu^[(B
^[(0x^[(B $ git      �(0x�(B Get changes from the base of my GitHub fork / How �(0x�(B       �(0x^[(B
^[(0x^[(B fetch      �(0x�(B to sync a fork - Part 1 of 2                      �(0x�(B       �(0x^[(B
^[(0x^[(B upstream   �(0x�(B                                                   �(0x�(B       �(0x^[(B
^[(0tqqqqqqqqqqqqnqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqnqqqqqqqu^[(B

Is it possible to fall back to plain ASCII output (as, I think, it was in older versions)? Or force plain ASCII output with a command line option?

@OrkoHunter
Copy link
Owner

Keep uses a library called terminaltables to produce this table.

Thanks for raising the issue!

@OrkoHunter OrkoHunter added the bug label Jan 13, 2019
@halloleo
Copy link
Author

When I issue in my dumb terminal the sample from the terminaltables project:

from terminaltables import AsciiTable
table_data = [
    ['Heading1', 'Heading2'],
    ['row1 column1', 'row1 column2'],
    ['row2 column1', 'row2 column2'],
    ['row3 column1', 'row3 column2']
]
table = AsciiTable(table_data)
print(table.table)

I get the expected output:

+--------------+--------------+
| Heading1     | Heading2     |
+--------------+--------------+
| row1 column1 | row1 column2 |
| row2 column1 | row2 column2 |
| row3 column1 | row3 column2 |
+--------------+--------------+

So maybe it is related to the way terminaltables is called in keep?

@halloleo
Copy link
Author

Had a quick peek into the code in utils.py: keep uses SingleTable, while the terminaltables sample uses AsciiTable.

I've tested both on dumb terminals: The output from AsciiTable is fine, the output of SingleTable not.

@OrkoHunter
Copy link
Owner

Thank you for looking into it.

I am okay with AsciiTable. Let me push an update.

@OrkoHunter
Copy link
Owner

I have made a new release. Can you please try v2.6 and give an update?

@halloleo
Copy link
Author

Cool! :-) Thx for the quick fix!

It sort of works: The issue with dumb terminals is solved and it displays fine for a list of commands with short descriptions. But when I have a description which will wrap in the table I get the following error:

$ keep list
Traceback (most recent call last):
  File "/Users/halloleo/share/venv/keep/bin/keep", line 11, in <module>
    sys.exit(cli())
  File "/Users/halloleo/share/venv/keep/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Users/halloleo/share/venv/keep/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Users/halloleo/share/venv/keep/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/halloleo/share/venv/keep/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/halloleo/share/venv/keep/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Users/halloleo/share/venv/keep/lib/python3.7/site-packages/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/Users/halloleo/share/venv/keep/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Users/halloleo/share/venv/keep/lib/python3.7/site-packages/keep/commands/cmd_list.py", line 14, in cli
    utils.list_commands(ctx)
  File "/Users/halloleo/share/venv/keep/lib/python3.7/site-packages/keep/utils.py", line 72, in list_commands
    table.table_data[i + 1][j] = '\n'.join(wrap(data, max_widths[j]))
  File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/textwrap.py", line 379, in wrap
    return w.wrap(text)
  File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/textwrap.py", line 354, in wrap
    return self._wrap_chunks(chunks)
  File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/textwrap.py", line 248, in _wrap_chunks
    raise ValueError("invalid width %r (must be > 0)" % self.width)
ValueError: invalid width -19 (must be > 0)

Note: This error seems to be independent of the terminal. It happen with TERM=xterm-256color as well.

@OrkoHunter
Copy link
Owner

terminaltables' max_column_width API is returning negative numbers. This looks like a bug.

They do not have anything for wrapping. Robpol86/terminaltables#5

@OrkoHunter
Copy link
Owner

@halloleo I have pushed a fix. Please update and let me know. v2.6.1

@halloleo
Copy link
Author

Yep, work now.

Strange that terminaltables doesn't do the wrapping - it's certainly a clutch that you have to do the wrapping.

Anyway, thanks for fixing this. :-)

@OrkoHunter
Copy link
Owner

Awesome! 🎉

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

No branches or pull requests

2 participants