Skip to content

New feature: Software columns - #645

Merged
patkan merged 12 commits into
python-escpos:masterfrom
belono:belono/issue27
Jul 11, 2024
Merged

New feature: Software columns#645
patkan merged 12 commits into
python-escpos:masterfrom
belono:belono/issue27

Conversation

@belono

@belono belono commented Jun 2, 2024

Copy link
Copy Markdown
Contributor

Description

This implements software_columns() as a new feature to help in the tricky task of printing texts in columns or aligning multiple texts in different alignments within the same line.

The method receives a list of strings and formats them as horizontal columns by adding spaces between each element. If some text is too long it is wrapped to the column width by adding new lines and even truncating words that are too long by adding a placeholder.
It is also possible to set the width and the text alignment of each column independently. The method is flexible enough to repeat the last width and/or alignment till the last element if there are more text elements than column widths or alignments.

  • Example 1: The user passes a list of 4 text items and wants the first one to be 20 characters wide and 10 for the rest, then he/she only needs to pass the value widths=[20, 10] to the method so it will be expanded to '[20, 10, 10, 10]`.
  • Example 2: The user passes a list of 4 text items and wants all them to be the same size along a maximum total width of 40 characters, then he/she simply passes the value widths=40 so it will be expanded to [10, 10, 10, 10].

This is also true for the alignment parameter:

  • On a list of 4 text items align=['left', 'center', 'right'] would expand to ['left', 'center', 'right', 'right']. Alternatively a single value align='center' would expand to ['center', 'center', 'center', 'center'].

At the moment, the user is responsible for not exceeding the width of the paper when passing the list of widths parameter, but this behavior could be modified by adding a check, an exception or whatever.

As always all suggestions, corrections, etc. are very welcome.

Closes #27
Closes #635

Tested with

  • Epson TM-U210

@codecov

codecov Bot commented Jun 3, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 19.60784% with 41 lines in your changes missing coverage. Please review.

Project coverage is 78.72%. Comparing base (5af0164) to head (7470e58).
Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
src/escpos/escpos.py 19.60% 41 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #645      +/-   ##
==========================================
- Coverage   80.59%   78.72%   -1.87%     
==========================================
  Files          21       21              
  Lines        1618     1669      +51     
  Branches      286      303      +17     
==========================================
+ Hits         1304     1314      +10     
- Misses        233      274      +41     
  Partials       81       81              
Flag Coverage Δ
unittests 78.55% <19.60%> (-1.86%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/escpos/escpos.py 65.83% <19.60%> (-5.50%) ⬇️

@belono
belono marked this pull request as ready for review June 3, 2024 18:24

@patkan patkan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Looks good to me and the CI hasn't found issues.

@patkan
patkan merged commit a8753a1 into python-escpos:master Jul 11, 2024
@belono
belono deleted the belono/issue27 branch July 13, 2024 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tabbed text align left and right on the same line

2 participants