Skip to content

Commit 72c40f4

Browse files
committed
python: OutputFormat: run pre() only after line is printed
Problem: The `pre` argument to OutputFormat.print_items() is documented as being called before printing each line, but it is called even if an empty line is generated. This can cause problems in tools like flux-jobs(1) which uses a pre() function to colorize lines of output. If a color is set, but the line is then skipped or an exception is thrown, the terminal may be left with the line color enabled. Fix OutputFormat.print_items() to call the pre() function after the line has been formatted, just before printing it. This removes the possibility that pre() will be called without post() due to an empty line or an exception during line formatting. Fixes #5209
1 parent c2964c9 commit 72c40f4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/bindings/python/flux/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,11 +696,11 @@ def print_items(self, items, no_header=False, pre=None, post=None):
696696
if not no_header:
697697
print(formatter.header())
698698
for item in items:
699-
if callable(pre):
700-
pre(item)
701699
line = formatter.format(item)
702700
if not line:
703701
continue
702+
if callable(pre):
703+
pre(item)
704704
try:
705705
print(line)
706706
except UnicodeEncodeError:

0 commit comments

Comments
 (0)