Skip to content

Commit a71ee7d

Browse files
committed
Improve smart-word-wrap when printing Translation API results
1 parent 266bdc1 commit a71ee7d

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

seleniumbase/translate/translator.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,14 +493,14 @@ def main():
493493

494494
new_sb_lines = []
495495
for line in seleniumbase_lines:
496-
line_length = len(line)
497-
line_length2 = len(line)
498-
line_length = get_width(line)
496+
line_length2 = len(line) # Normal Python string length used
497+
line_length = get_width(line) # Special characters count 2X
499498
if line_length > code_width:
500499
code_width = line_length
501500

502501
if console_width:
503-
# If line is larger than console_width, try to optimize it
502+
# If line is larger than console_width, try to optimize it.
503+
# Smart Python word wrap to be used with valid indentation.
504504
if line_length + w > console_width: # 5 is line number ws
505505
if line.count(' # ') == 1: # Has comments like this
506506
if get_width(
@@ -582,6 +582,38 @@ def main():
582582
else:
583583
new_sb_lines.append(line)
584584
continue
585+
elif line.count('= "') == 1 and line.count('://') == 1:
586+
whitespace = line_length2 - len(line.lstrip())
587+
new_ws = line[0:whitespace] + " "
588+
line1 = line.split('://')[0] + '://" \\'
589+
line2 = new_ws + '"' + line.split('://')[1]
590+
new_sb_lines.append(line1)
591+
if get_width(line2) + w > console_width:
592+
if line2.count('/') > 0:
593+
slash_one = line2.find('/')
594+
line2a = line2[:slash_one+1] + '" \\'
595+
line2b = new_ws + '"' + line2[slash_one+1:]
596+
new_sb_lines.append(line2a)
597+
new_sb_lines.append(line2b)
598+
continue
599+
new_sb_lines.append(line2)
600+
continue
601+
elif line.count("= '") == 1 and line.count('://') == 1:
602+
whitespace = line_length2 - len(line.lstrip())
603+
new_ws = line[0:whitespace] + " "
604+
line1 = line.split('://')[0] + '://" \\'
605+
line2 = new_ws + "'" + line.split('://')[1]
606+
new_sb_lines.append(line1)
607+
if get_width(line2) + w > console_width:
608+
if line2.count('/') > 0:
609+
slash_one = line2.find('/')
610+
line2a = line2[:slash_one+1] + "' \\"
611+
line2b = new_ws + "'" + line2[slash_one+1:]
612+
new_sb_lines.append(line2a)
613+
new_sb_lines.append(line2b)
614+
continue
615+
new_sb_lines.append(line2)
616+
continue
585617
new_sb_lines.append(line)
586618

587619
if new_sb_lines:

0 commit comments

Comments
 (0)