2

urwid has a number of different widgets that allow text to be displayed, and a few ways to format the text to the window size. How can I format the text of a widget to wrap the first line and truncate the second? To be specific:

`a rather long string that is wrapped on the first line and clipped on the second'

           (window boundary)
|-------------------------------------|
|a rather long string that is wrapped |
|on the first line and clipped on t...|
|-------------------------------------|

Of course this could be done manually by counting chars, but that would get ugly quickly, esp. with window resizing.

anon01
  • 10,618
  • 8
  • 35
  • 58
  • interesting question... can you share a sample code w/ what you've tried? – Elias Dorneles Mar 20 '18 at 14:42
  • If you're on Python 3, maybe you could get away using text processing stuff available in [textwrap](https://docs.python.org/3.4/library/textwrap.html) ? – Elias Dorneles Mar 20 '18 at 14:45
  • I think `textwrap` is a good suggestion. I'll post sample code later. – anon01 Mar 20 '18 at 17:07
  • An interesting note: if your original string contains newline characters, these *don't* get stripped by `wrap='clip'` and the rendered `Text` will extend several lines. For multiline string input it then maybe stripping all but the first `\n` and `wrap='clip'` would be a more reasonable solution. I haven't tried this yet. – anon01 Mar 20 '18 at 17:09

0 Answers0