Skip to content

Commit 5fbd5e4

Browse files
caberoscaberos
authored andcommitted
new method to fix the table disconfigurate when the text data is very long
1 parent 09e714c commit 5fbd5e4

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

SoftLayer/utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,3 +406,24 @@ def trim_to(string, length=80, tail="..."):
406406
return string[:length] + tail
407407
else:
408408
return string
409+
410+
411+
def format_comment(comment, max_line_length):
412+
"""Return a string that is length long, added a next line and keep the table format.
413+
414+
:param string string: String you want to add next line
415+
:param int length: max length for the string
416+
"""
417+
comment_length = 0
418+
words = comment.split(" ")
419+
formatted_comment = ""
420+
for word in words:
421+
if comment_length + (len(word) + 1) <= max_line_length:
422+
formatted_comment = formatted_comment + word + " "
423+
424+
comment_length = comment_length + len(word) + 1
425+
else:
426+
formatted_comment = formatted_comment + "\n" + word + " "
427+
428+
comment_length = len(word) + 1
429+
return formatted_comment

0 commit comments

Comments
 (0)