Exemplo n.º 1
0
	def __init__(self, width=80):
		""" Sets up the class and configures the utilized Textwrapper-object"""
		self.width = width
		wrapper = TextWrapper()
		wrapper.width = width	
		wrapper.replace_whitespace = False	
		wrapper.drop_whitespace = False	
		self.wrapper = wrapper
Exemplo n.º 2
0
def draw_body(card, raw_text, center_y, card_width, chars_per_line):
	text = raw_text.decode('utf-8')
	wrapper = TextWrapper()
	wrapper.width = chars_per_line
	wrapper.replace_whitespace = True
	wrapper.drop_whitespace = False
	lines = wrapper.wrap(text)
	line_width, line_height = body_font.getsize(lines[0])
	y = center_y - (line_height * (float(len(lines)) / 2.0))
	for line in lines:
		line_width, line_height = body_font.getsize(line)
		draw = ImageDraw.Draw(card)
		draw.text(((card_width - line_width) / 2, y), line, font = body_font, fill = (0, 0, 0))
		y += line_height
Exemplo n.º 3
0
def DisassemblyPrinter( instructions, fifoname='', width=int(ExtensionSettings.getValue('main_termal_width')), wrap=False):
	if (fifoname):
		output=fifoname
	else:
		output=sys.stdout
	print >>output, "=" * 16
	data = gdb.execute("x/" + str(instructions) + "i $pc", False, True)
	if wrap:
		print >>output, data
	else:
		wrapper = TextWrapper() # use TextWrapper to properly deal with tab lengths in output
		wrapper.width = width
		wrapper.drop_whitespace = False
		for line in data.split('\n'):
			out = wrapper.wrap(line)
			if len(out) > 0:
				print >>output, wrapper.wrap(line)[0]
Exemplo n.º 4
0
def report_to_display(display, banner, banner_color, hint, hint_wrap,
                      group_index, group_items):
    gutter = '[R:{0}] '.format(group_index + 1)
    indent = ' '.ljust(len(gutter))

    display.display('{0}{1}\n'.format(gutter, banner), color=banner_color)

    for item in group_items:
        display.display('{0}  - {1}'.format(indent, item['path']),
                        color=C.COLOR_HIGHLIGHT)

    if hint and not hint_wrap:
        display.display('\n{0}HINT: {1}\n'.format(indent, hint),
                        color=C.COLOR_HIGHLIGHT)
    elif hint:
        wrapper = TextWrapper()
        wrapper.initial_indent = indent
        wrapper.subsequent_indent = indent
        wrapper.drop_whitespace = False
        wrapper.width = 70 - len(indent)
        wrapped = '\n'.join(wrapper.wrap('HINT: {0}'.format(hint)))

        display.display('\n{0}\n'.format(wrapped), color=C.COLOR_HIGHLIGHT)
Exemplo n.º 5
0
def wordWrap(lines, rows, cols):
    """ Format an array of text to a specific number of 
        visible rows and columns """
    wrapped = []

    # Set up a TextWrapper
    wrapper = TextWrapper()
    wrapper.width = cols
    wrapper.expand_tabs = False
    wrapper.replace_whitespace = False
    wrapper.drop_whitespace = False

    for line in lines:
        if len(line) > cols:
            wrapped.extend(wrapper.wrap(line))
        else:
            wrapped.append(line)

        if len(wrapped) >= rows:
            break

    # Return only "rows" in case a word wrap added extra
    return wrapped[:rows]