Skip to content

Instantly share code, notes, and snippets.

@wardi wardi/gist:8337153

Created Jan 9, 2014
Embed
What would you like to do?
urwid text layout that fills with underscores on the right (works with wide and combining characters too!)
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
You can’t perform that action at this time.