Commit 4db37f29 by devttys0

Fixed bug in terminal line wrapping output.

parent 153a2fc9
...@@ -131,29 +131,45 @@ class Display(object): ...@@ -131,29 +131,45 @@ class Display(object):
Formats a line of text to fit in the terminal window. Formats a line of text to fit in the terminal window.
For Tim. For Tim.
''' '''
delim = '\n'
offset = 0 offset = 0
space_offset = 0
self.string_parts = [] self.string_parts = []
delim = '\n'
if self.fit_to_screen and len(line) > self.SCREEN_WIDTH: if self.fit_to_screen and len(line) > self.SCREEN_WIDTH:
# Split the line into an array of columns, e.g., ['0', '0x00000000', 'Some description here']
line_columns = line.split(None, self.num_columns-1) line_columns = line.split(None, self.num_columns-1)
# Find where the start of the last column (description) starts in the line of text.
if line_columns: # All line wraps need to be aligned to this offset.
delim = '\n' + ' ' * line.rfind(line_columns[-1]) offset = line.rfind(line_columns[-1])
# The delimiter will be a newline followed by spaces padding out the line wrap to the alignment offset.
while len(line[offset:]) > self.SCREEN_WIDTH: delim += ' ' * offset
space_offset = line[offset:offset+self.HEADER_WIDTH].rfind(' ') # Calculate the maximum length that each wrapped line can be
if space_offset == -1 or space_offset == 0: max_line_wrap_length = self.SCREEN_WIDTH - offset
space_offset = self.SCREEN_WIDTH
# Append all but the last column to formatted_line
self._append_to_data_parts(line, offset, offset+space_offset) formatted_line = line[:offset]
offset += space_offset # Loop to split up line into multiple max_line_wrap_length pieces
while len(line[offset:]) > max_line_wrap_length:
self._append_to_data_parts(line, offset, offset+len(line[offset:])) # Find the nearest space to wrap the line at (so we don't split a word across two lines)
split_offset = line[offset:offset+max_line_wrap_length].rfind(' ')
return delim.join(self.string_parts) # If there were no good places to split the line, just truncate it at max_line_wrap_length
if split_offset < 1:
split_offset = max_line_wrap_length
self._append_to_data_parts(line, offset, offset+split_offset)
offset += split_offset
# Add any remaining data (guarunteed to be max_line_wrap_length long or shorter) to self.string_parts
self._append_to_data_parts(line, offset, offset+len(line[offset:]))
# Append self.string_parts to formatted_line; each part seperated by delim
formatted_line += delim.join(self.string_parts)
else:
# Line fits on screen as-is, no need to format it
formatted_line = line
return formatted_line
def _configure_formatting(self): def _configure_formatting(self):
''' '''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment