two space to split columns and break on conditions
@@ -184,14 +184,24 @@ def print_summary(model, line_length=None, positions=None, print_fn=None):
else:
start_pos = 0
end_pos = positions[col]
- # Leave room for a space to delineate columns
- # we don't need one if we are printing the last column
- space = 1 if col != len(positions) - 1 else 0
- delta = end_pos - start_pos - space
- fit_into_line = left_to_print[col][:delta]
+ # Leave room for 2 spaces to delineate columns
+ # we don't need any if we are printing the last column
+ space = 2 if col != len(positions) - 1 else 0
+ cutoff = end_pos - start_pos - space
+ fit_into_line = left_to_print[col][:cutoff]
+ # For nicer formatting we line-break on seeing end of
+ # tuple/dict etc.
+ line_break_conditions = ("),", "},", "],", "',")
+ candidate_cutoffs = [fit_into_line.find(x) + len(x)
+ for x in line_break_conditions
+ if fit_into_line.find(x) >= 0]
+ if candidate_cutoffs:
+ cutoff = min(candidate_cutoffs)
+ fit_into_line = fit_into_line[:cutoff]
+
line += fit_into_line
- line += ' ' if space else ''
- left_to_print[col] = left_to_print[col][delta:]
+ line += ' '*space if space else ''
+ left_to_print[col] = left_to_print[col][cutoff:]
# Pad out to the next position
line += ' ' * (positions[col] - len(line))
