Skip to content

Commit 26d72a6

Browse files
braveheuelpatkan
authored andcommitted
Feature/clear content in dummy printer (#271)
Add Function to Dummy Printer for Clearing Buffer If you are using the dummy printer, you may want to use the printer again after sending the output to a physical printer. This method empties the list of the output buffer.
1 parent 01e28bb commit 26d72a6

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/escpos/printer.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,5 +312,13 @@ def output(self):
312312
""" Get the data that was sent to this printer """
313313
return b''.join(self._output_list)
314314

315+
def clear(self):
316+
""" Clear the buffer of the printer
317+
318+
This method can be called if you send the contents to a physical printer
319+
and want to use the Dummy printer for new output.
320+
"""
321+
del self._output_list[:]
322+
315323
def close(self):
316324
pass

test/test_function_dummy_clear.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from nose.tools import assert_raises
2+
from escpos.printer import Dummy
3+
4+
def test_printer_dummy_clear():
5+
printer = Dummy()
6+
printer.text("Hello")
7+
printer.clear()
8+
assert(printer.output == b'')

0 commit comments

Comments
 (0)