Skip to content

Commit

Permalink
Suppress repeated newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGross committed Nov 6, 2024
1 parent ccea571 commit 1d8ccbb
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gbmi/utils/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ def forward_output(
stream: io.BufferedReader,
write_func: Callable[[str], None],
trim_func: Optional[Callable[[str], Optional[str]]] = None,
suppress_repeated_newlines: bool = True,
) -> None:
buffer = ""
prev_newline = False
for char in iter(lambda: stream.read(1), b""):
decoded_char = char.decode()
cur_newline = decoded_char == "\n"
if suppress_repeated_newlines and prev_newline and cur_newline:
continue
prev_newline = cur_newline
if trim_func is None:
write_func(decoded_char, end="")
else:
Expand Down

0 comments on commit 1d8ccbb

Please sign in to comment.