Created
January 9, 2014 16:30
-
-
Save wardi/8337153 to your computer and use it in GitHub Desktop.
urwid text layout that fills with underscores on the right (works with wide and combining characters too!)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urwid | |
class UnderscoreRight(urwid.StandardTextLayout): | |
def layout(self, text, width, align, wrap): | |
s = urwid.StandardTextLayout.layout(self, text, width, align, wrap) | |
out = [] | |
last_offset = 0 | |
for row in s: | |
used = 0 | |
for seg in row: | |
used += seg[0] | |
if len(seg) == 3: | |
last_offset = seg[2] | |
if used == width: | |
out.append(row) | |
continue | |
fill = width - used | |
out.append(row + [(fill, last_offset, '_'*fill)]) | |
return out | |
urwid.MainLoop(urwid.Filler( | |
urwid.Edit( | |
'stuff: ', | |
'edit here', | |
layout=UnderscoreRight(), | |
multiline=True, | |
) | |
)).run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment