Skip to content

Commit

Permalink
Fix interaction between Console capture and record
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed Jun 15, 2022
1 parent 30498f5 commit 051dd04
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions rich/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -1959,11 +1959,11 @@ def _check_buffer(self) -> None:
del self._buffer[:]
return
with self._lock:
if self._buffer_index == 0:
if self.record:
with self._record_buffer_lock:
self._record_buffer.extend(self._buffer[:])

if self.record:
with self._record_buffer_lock:
self._record_buffer.extend(self._buffer[:])
if self._buffer_index == 0:

if self.is_jupyter: # pragma: no cover
from .jupyter import display
Expand Down
14 changes: 14 additions & 0 deletions tests/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,20 @@ def test_capture():
assert capture.get() == "Hello\n"


def test_capture_and_record():
recorder = Console(record=True)
recorder.print("ABC")

with recorder.capture() as capture:
recorder.print("Hello")

assert capture.get() == "Hello\n"

text = recorder.export_text()
assert text == "ABC\nHello\n"
assert capture.get() == "Hello\n"


def test_input(monkeypatch, capsys):
def fake_input(prompt=""):
console.file.write(prompt)
Expand Down

0 comments on commit 051dd04

Please sign in to comment.