Add methods for simpler newlines (#246)
This commit is contained in:
parent
81426ab6dc
commit
b64b534394
|
@ -460,6 +460,28 @@ class Escpos(object):
|
|||
txt = six.text_type(txt)
|
||||
self.magic.write(txt)
|
||||
|
||||
def textln(self, txt=''):
|
||||
"""Print alpha-numeric text with a newline
|
||||
|
||||
The text has to be encoded in the currently selected codepage.
|
||||
The input text has to be encoded in unicode.
|
||||
|
||||
:param txt: text to be printed with a newline
|
||||
:raises: :py:exc:`~escpos.exceptions.TextError`
|
||||
"""
|
||||
self.text('{}\n'.format(txt))
|
||||
|
||||
def ln(self, count=1):
|
||||
"""Print a newline or more
|
||||
|
||||
:param count: number of newlines to print
|
||||
:raises: :py:exc:`ValueError` if count < 0
|
||||
"""
|
||||
if count < 0:
|
||||
raise ValueError('Count cannot be lesser than 0')
|
||||
if count > 0:
|
||||
self.text('\n' * count)
|
||||
|
||||
def block_text(self, txt, font=None, columns=None):
|
||||
""" Text is printed wrapped to specified columns
|
||||
|
||||
|
|
|
@ -39,3 +39,27 @@ def test_block_text():
|
|||
"All the presidents men were eating falafel for breakfast.", font='a')
|
||||
assert printer.output == \
|
||||
b'All the presidents men were eating falafel\nfor breakfast.'
|
||||
|
||||
|
||||
def test_textln():
|
||||
printer = get_printer()
|
||||
printer.textln('hello, world')
|
||||
assert printer.output == b'hello, world\n'
|
||||
|
||||
|
||||
def test_textln_empty():
|
||||
printer = get_printer()
|
||||
printer.textln()
|
||||
assert printer.output == b'\n'
|
||||
|
||||
|
||||
def test_ln():
|
||||
printer = get_printer()
|
||||
printer.ln()
|
||||
assert printer.output == b'\n'
|
||||
|
||||
|
||||
def test_multiple_ln():
|
||||
printer = get_printer()
|
||||
printer.ln(3)
|
||||
assert printer.output == b'\n\n\n'
|
||||
|
|
Loading…
Reference in New Issue