fix(display): alternate spaces and dashes (#6119)

* fix(display): alternate spaces and dashes

* add comment
This commit is contained in:
sydneyli 2018-06-15 15:03:58 -07:00 committed by Brad Warren
parent 3316eac178
commit adc07ef933

View file

@ -29,6 +29,10 @@ HELP = "help"
ESC = "esc"
"""Display exit code when the user hits Escape (UNUSED)"""
# Display constants
SIDE_FRAME = ("- " * 39) + "-"
"""Display boundary (alternates spaces, so when copy-pasted, markdown doesn't interpret
it as a heading)"""
def _wrap_lines(msg):
"""Format lines nicely to 80 chars.
@ -111,12 +115,11 @@ class FileDisplay(object):
because it won't cause any workflow regressions
"""
side_frame = "-" * 79
if wrap:
message = _wrap_lines(message)
self.outfile.write(
"{line}{frame}{line}{msg}{line}{frame}{line}".format(
line=os.linesep, frame=side_frame, msg=message))
line=os.linesep, frame=SIDE_FRAME, msg=message))
self.outfile.flush()
if pause:
if self._can_interact(force_interactive):
@ -208,12 +211,10 @@ class FileDisplay(object):
if self._return_default(message, default, cli_flag, force_interactive):
return default
side_frame = ("-" * 79) + os.linesep
message = _wrap_lines(message)
self.outfile.write("{0}{frame}{msg}{0}{frame}".format(
os.linesep, frame=side_frame, msg=message))
os.linesep, frame=SIDE_FRAME + os.linesep, msg=message))
self.outfile.flush()
while True:
@ -386,8 +387,7 @@ class FileDisplay(object):
# Write out the message to the user
self.outfile.write(
"{new}{msg}{new}".format(new=os.linesep, msg=message))
side_frame = ("-" * 79) + os.linesep
self.outfile.write(side_frame)
self.outfile.write(SIDE_FRAME + os.linesep)
# Write out the menu choices
for i, desc in enumerate(choices, 1):
@ -397,7 +397,7 @@ class FileDisplay(object):
# Keep this outside of the textwrap
self.outfile.write(os.linesep)
self.outfile.write(side_frame)
self.outfile.write(SIDE_FRAME + os.linesep)
self.outfile.flush()
def _get_valid_int_ans(self, max_):
@ -482,12 +482,11 @@ class NoninteractiveDisplay(object):
:param bool wrap: Whether or not the application should wrap text
"""
side_frame = "-" * 79
if wrap:
message = _wrap_lines(message)
self.outfile.write(
"{line}{frame}{line}{msg}{line}{frame}{line}".format(
line=os.linesep, frame=side_frame, msg=message))
line=os.linesep, frame=SIDE_FRAME, msg=message))
self.outfile.flush()
def menu(self, message, choices, ok_label=None, cancel_label=None,