Skip to content

Commit

Permalink
Merge pull request #25 from jhshi/print_stdout_if_not_empty
Browse files Browse the repository at this point in the history
Print std_output if it's not empty
  • Loading branch information
chishui authored Sep 6, 2017
2 parents 6edfcff + 5a817c5 commit 88a3c80
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion leetcode/views/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ def __init__(self, quiz, host_view, result, loop = None):
urwid.Divider()])
urwid.Frame.__init__(self, self.overlay, footer=footer)

def _append_stdout_if_non_empty(self, list_items):
std_output = self.result.get('std_output', '')
if len(std_output) > 0:
blank = urwid.Divider()
stdout_header = urwid.Text('Stdout:')
if len(std_output) > 100:
std_output = '%s...%s\n(output trimmed due to its length)' %\
(std_output[:90], std_output[-10:])
stdout = urwid.Text(std_output)
list_items.extend([blank, stdout_header, stdout])

def make_success_view(self):
blank = urwid.Divider()
status_header = urwid.AttrWrap(urwid.Text('Run Code Status: '), 'body')
Expand All @@ -57,6 +68,7 @@ def make_success_view(self):
blank, columns,
blank, runtime
]
self._append_stdout_if_non_empty(list_items)
return urwid.Padding(urwid.ListBox(urwid.SimpleListWalker(list_items)), left=2, right=2)

def make_failed_view(self):
Expand All @@ -82,6 +94,7 @@ def make_failed_view(self):
blank, your_answer_header, your_answer,
blank, expected_answer_header, expected_answer
]
self._append_stdout_if_non_empty(list_items)
return urwid.Padding(urwid.ListBox(urwid.SimpleListWalker(list_items)), left=2, right=2)

def make_compile_error_view(self):
Expand All @@ -104,6 +117,7 @@ def make_compile_error_view(self):
blank, your_answer_header, your_answer,
blank, expected_answer_header, expected_answer
]
self._append_stdout_if_non_empty(list_items)
return urwid.Padding(urwid.ListBox(urwid.SimpleListWalker(list_items)), left=2, right=2)

def make_runtime_error_view(self):
Expand All @@ -123,6 +137,7 @@ def make_runtime_error_view(self):
blank, error_header, error_message,
blank, your_input_header, your_input,
]
self._append_stdout_if_non_empty(list_items)
return urwid.Padding(urwid.ListBox(urwid.SimpleListWalker(list_items)), left=2, right=2)

def make_unified_error_view(self, error_title):
Expand All @@ -145,7 +160,7 @@ def make_unified_error_view(self, error_title):
result_header,
blank, column_wrap,
]

self._append_stdout_if_non_empty(list_items)
return urwid.Padding(urwid.ListBox(urwid.SimpleListWalker(list_items)), left=2, right=2)


Expand Down

0 comments on commit 88a3c80

Please sign in to comment.