Skip to content

Commit

Permalink
ensure terminating separator line when chunks are discarded
Browse files Browse the repository at this point in the history
  • Loading branch information
huettenhain committed Apr 1, 2024
1 parent 63efe5a commit 38151f9
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions refinery/units/sinks/peek.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import os
import textwrap
import codecs
import itertools
import collections

from refinery.units.sinks import Arg, HexViewer
from refinery.lib.meta import ByteStringWrapper, metavars, CustomStringRepresentation, SizeInt
from refinery.lib.types import INF
from refinery.lib.tools import get_terminal_size, isbuffer, lookahead
from refinery.lib.tools import get_terminal_size, isbuffer
from refinery.lib.environment import environment


Expand Down Expand Up @@ -291,11 +293,26 @@ def filter(self, chunks):
except ImportError:
pass
discarded = 0
for final, item in lookahead(chunks):
item.temp = final
if not item.visible and self.isatty:
it = iter(chunks)
buffer = collections.deque(itertools.islice(it, 0, 2))
buffer.reverse()

while buffer:
if self.isatty and not buffer[0].visible:
buffer.popleft()
discarded += 1
else:
yield item
item = buffer.pop()
last = not bool(buffer)
item.temp = last
if not item.visible and self.isatty:
discarded += 1
else:
yield item
try:
buffer.appendleft(next(it))
except StopIteration:
pass

if discarded:
self.log_warn(F'discarded {discarded} invisible chunks to prevent them from leaking into the terminal.')

0 comments on commit 38151f9

Please sign in to comment.