File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -62,23 +62,36 @@ def measure(text):
62
62
swidth = measure (" " )
63
63
firstword = True
64
64
for line_in_input in string .split ("\n " ):
65
+ newline = True
65
66
for index , word in enumerate (line_in_input .split (" " )):
66
67
wwidth = measure (word )
67
68
word_parts = []
68
69
cur_part = ""
69
70
70
71
if wwidth > max_width :
71
72
for char in word :
73
+ if newline :
74
+ extraspace = 0
75
+ else :
76
+ extraspace = swidth
72
77
if (
73
78
measure ("" .join (partial ))
74
79
+ measure (cur_part )
75
80
+ measure (char )
76
81
+ measure ("-" )
82
+ + extraspace
77
83
> max_width
78
84
):
79
- word_parts .append ("" .join (partial ) + cur_part + "-" )
85
+ if cur_part :
86
+ if newline :
87
+ word_parts .append ("" .join (partial ) + cur_part + "-" )
88
+ else :
89
+ word_parts .append ("" .join (partial ) + " " + cur_part + "-" )
90
+ else :
91
+ word_parts .append ("" .join (partial ))
80
92
cur_part = char
81
93
partial = [indent1 ]
94
+ newline = True
82
95
else :
83
96
cur_part += char
84
97
if cur_part :
@@ -103,6 +116,8 @@ def measure(text):
103
116
lines .append ("" .join (partial ))
104
117
partial = [indent1 , word ]
105
118
width = measure (indent1 ) + wwidth
119
+ if newline :
120
+ newline = False
106
121
107
122
lines .append ("" .join (partial ))
108
123
partial = [indent1 ]
You can’t perform that action at this time.
0 commit comments