Skip to content

Commit 1d8ccbb

Browse files
committed
Suppress repeated newlines
1 parent ccea571 commit 1d8ccbb

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

gbmi/utils/images.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,16 @@ def forward_output(
5555
stream: io.BufferedReader,
5656
write_func: Callable[[str], None],
5757
trim_func: Optional[Callable[[str], Optional[str]]] = None,
58+
suppress_repeated_newlines: bool = True,
5859
) -> None:
5960
buffer = ""
61+
prev_newline = False
6062
for char in iter(lambda: stream.read(1), b""):
6163
decoded_char = char.decode()
64+
cur_newline = decoded_char == "\n"
65+
if suppress_repeated_newlines and prev_newline and cur_newline:
66+
continue
67+
prev_newline = cur_newline
6268
if trim_func is None:
6369
write_func(decoded_char, end="")
6470
else:

0 commit comments

Comments
 (0)