Skip to content

Instantly share code, notes, and snippets.

@wardi
Created January 9, 2014 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wardi/8337153 to your computer and use it in GitHub Desktop.
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!)
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