thermal 0.1.1 โ†’ 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -20
  3. data/README.md +200 -27
  4. data/data/db.yml +1987 -0
  5. data/data/original.yml +1635 -0
  6. data/lib/thermal/byte_buffer.rb +48 -0
  7. data/lib/thermal/db/charset.rb +36 -0
  8. data/lib/thermal/db/cjk_encoding.rb +46 -0
  9. data/lib/thermal/db/data.rb +77 -0
  10. data/lib/thermal/db/device.rb +79 -0
  11. data/lib/thermal/db/encoding.rb +35 -0
  12. data/lib/thermal/db/loader.rb +65 -0
  13. data/lib/thermal/db.rb +43 -0
  14. data/lib/thermal/dsl.rb +28 -0
  15. data/lib/thermal/escpos/buffer.rb +167 -0
  16. data/lib/thermal/escpos/cmd.rb +11 -0
  17. data/lib/thermal/escpos/writer.rb +93 -0
  18. data/lib/thermal/escpos_star/buffer.rb +38 -0
  19. data/lib/thermal/escpos_star/writer.rb +17 -0
  20. data/lib/thermal/printer.rb +56 -21
  21. data/lib/thermal/profile.rb +71 -0
  22. data/lib/thermal/stargraphic/capped_byte_buffer.rb +20 -0
  23. data/lib/thermal/stargraphic/chunked_byte_buffer.rb +62 -0
  24. data/lib/thermal/stargraphic/writer.rb +318 -0
  25. data/lib/thermal/starprnt/buffer.rb +46 -0
  26. data/lib/thermal/starprnt/writer.rb +81 -0
  27. data/lib/thermal/util.rb +74 -0
  28. data/lib/thermal/version.rb +5 -3
  29. data/lib/thermal/writer_base.rb +122 -0
  30. data/lib/thermal.rb +81 -8
  31. metadata +59 -57
  32. data/.gitignore +0 -3
  33. data/.rspec +0 -2
  34. data/.travis.yml +0 -6
  35. data/Gemfile +0 -3
  36. data/Rakefile +0 -1
  37. data/lib/devices/btpr880.rb +0 -33
  38. data/lib/devices/html.rb +0 -14
  39. data/lib/thermal/parser.rb +0 -30
  40. data/spec/btpr880_spec.rb +0 -36
  41. data/spec/fixtures/receipt.html +0 -6
  42. data/spec/printer_spec.rb +0 -29
  43. data/spec/spec_helper.rb +0 -3
  44. data/spec/thermal_spec.rb +0 -7
  45. data/tasks/console.rake +0 -9
  46. data/tasks/spec.rake +0 -3
  47. data/thermal.gemspec +0 -16
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b18797f5189d89f1f7326ab9eb8a131c1c0a98f37fc76b10469e4a67bddf5c47
4
+ data.tar.gz: 509efa5bfc9b51dd736b30c9f215d36e8f15fc2a578c7039b9bcd60915929554
5
+ SHA512:
6
+ metadata.gz: ecef3e5aba6e5d6b296762f53f6b809a2d4950c32232790138cff89ad8beb49439147cd5da89635f1002664c12fb9b9e4595a453a344ce8db148a0c330e2b0d7
7
+ data.tar.gz: cfb8b73b14a9bc09ad839066f888e35574c8ec00986787f6e0c666cfddd7d2c9eaa295483867b10297ff389c4c7bfc3b67fa06d6ec8db8c4e5b42e78aa55c254
data/LICENSE CHANGED
@@ -1,20 +1,21 @@
1
- Copyright (c) 2012 Tyler Kellen
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Johnny Shields & TableCheck
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,27 +1,200 @@
1
- # thermal
2
- > Convert basic HTML into thermal printer codes.
3
-
4
- This is a work in progress.
5
-
6
- Supported devices:
7
- - BTP-R880NP
8
-
9
- ## Setup
10
-
11
- ```console
12
- gem install thermal
13
- ```
14
-
15
- ## Usage
16
-
17
- ```ruby
18
- require 'thermal'
19
-
20
- parser = Thermal::Parser.new(BTPR880)
21
-
22
- BTPR880.print('192.168.1.200', 9100) do |print|
23
- print.puts parser.process('<strong>bold <u>underline</u></strong>')
24
- end
25
- ```
26
-
27
- > Copyright (c) 2013 Tyler Kellen. See LICENSE for further details.
1
+ # Thermal ๐Ÿ–จ๏ธ
2
+
3
+ Thermal printer support for Ruby. Used to print receipts, chits, tickets, labels, etc.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/thermal.svg)](https://badge.fury.io/rb/thermal)
6
+ [![CI](https://github.com/tablecheck/thermal/actions/workflows/ci.yml/badge.svg)](https://github.com/tablecheck/thermal/actions/workflows/ci.yml)
7
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
9
+
10
+ ## โš ๏ธ WARNING: Gem under active development
11
+
12
+ **All APIs and features should be considered unstable before 1.0.0 release.**
13
+
14
+ ### โœจ Features
15
+
16
+ - ๐ŸŽฏ Simple and opinionated API. **It just worksโ„ข**
17
+ - ๐ŸŽจ Generates **rich text, image, and QR codes** for thermal printers.
18
+ - ๐Ÿญ Supports a broad range of **makers and models** (Epson, Star Micronics, Brother, PBM, Zijiang, etc.)
19
+ - ๐ŸŒ Automatic **multi-lingual** codepage support, including support for **CJK extended character sets**.
20
+ - ๐Ÿ“ **Simple DSL** for rich text output formatting.
21
+ - ๐Ÿฆ‹ **Graceful degradation** of features based on printer capabilities.
22
+
23
+ ### ๐Ÿ”Œ Optional Features
24
+
25
+ - **QR code generation** ๐Ÿ“ฑ
26
+ - Requires [rqrcode](https://github.com/whomwah/rqrcode) gem.
27
+ - Support for **Stargraphic (raster-only format)** using system-side font rendering. ๐Ÿ–ผ๏ธ
28
+ - See requirements below.
29
+
30
+ ### ๐Ÿ“ค Supported Output Formats
31
+
32
+ - Epson ESC/POS
33
+ - Industry standard used by most thermal printers
34
+ - Star Micronics-specific formats
35
+ - Star Micronics Extended ESC/POS (UTF-8)
36
+ - Starprnt
37
+ - Stargraphic
38
+
39
+ ### โŒ Non-Features & Limitations
40
+
41
+ - **HTML-to-text support** (planned, not yet released) ๐Ÿ”„
42
+ - Requires [nokogiri](https://nokogiri.org/) gem.
43
+ - **No support for wire protocols** such as USB, Bluetooth, etc. This gem is intended
44
+ to run on a server; it only generates the instructions/bytes to be sent to the client
45
+ - (browser, iOS, etc.) which should then send it to the end device.
46
+ - **PR welcome** if someone wants to add USB/Bluetooth support.
47
+ - **Pixel-only printer support (Stargraphic) is rudimentary and slow** ๐Ÿข, because
48
+ it uses system-side font rendering ([Pango](https://www.pango.org/)) to generate
49
+ the image data.
50
+ - **PR welcome** to use a different approach and/or make it faster.
51
+ - Table formatting support not yet added. **PR welcome**.
52
+ - Indian ISCII encoding for Escpos is not yet supported. **PR welcome**.
53
+
54
+ ## ๐Ÿš€ How to Use
55
+
56
+ ### ๐Ÿ“ฆ Installation
57
+
58
+ Add this line to your application's Gemfile:
59
+
60
+ ```ruby
61
+ gem 'thermal'
62
+ ```
63
+
64
+ ### ๐Ÿ–จ๏ธ Formatting your Output
65
+
66
+ #### โŒจ๏ธ Procedural code
67
+
68
+ Intended API: (needs to be further extracted)
69
+
70
+ ```ruby
71
+ printer = Thermal::Printer.new(device: :espon_tm_t88v)
72
+ printer.text('Contra felicem vix deus vires habet')
73
+ printer.align_center
74
+ printer.text('Quam vellem nescire litteras!')
75
+ printer.flush # todo: #print!?
76
+ ```
77
+
78
+ #### ๐Ÿงฉ DSL
79
+
80
+ You can also use it as a DSL:
81
+
82
+ ```ruby
83
+ # TODO: Example text should look like an actual receipt
84
+ class MyChitPrinter
85
+ include Thermal::Dsl
86
+
87
+ def initialize
88
+ @printer = Thermal::Printer.new(device: :espon_tm_t88v)
89
+ end
90
+
91
+ def print
92
+ thermal_print do # TODO: does this flush automatically?
93
+ bold do
94
+ text('Contra felicem vix deus vires habet')
95
+ align(:center) do
96
+ text('Quam vellem nescire litteras!')
97
+ end
98
+ # html do
99
+ #
100
+ # end
101
+ # html('<b>foo</b>')
102
+ end
103
+ end
104
+ end
105
+ end
106
+ ```
107
+
108
+ #### ๐Ÿ“ƒ HTML Conversion
109
+
110
+ ```ruby
111
+ # TODO: float/tables?
112
+ # h1
113
+ # h2
114
+ # h3
115
+ #
116
+ ```
117
+
118
+ ### ๐Ÿšข Integrating Thermal into your App
119
+
120
+ - Add details of how to implement a thermal printer config.
121
+
122
+
123
+ ### ๐Ÿ› ๏ธ Advanced Considerations
124
+
125
+ #### ๐Ÿงต Thread-Safety
126
+
127
+ - Thermal's internals are thread-safe in principle.
128
+ - However, don't use the same `Thermal::Printer` object from multiple threads.
129
+ You're gonna have a bad time. ๐Ÿ˜ต
130
+
131
+ ### ๐Ÿ“ TODOs
132
+
133
+ #### โœ… Required before 1.0.0 release
134
+
135
+ - [ ] Add render method instead of flush
136
+ - [ ] Add task to import config from escpos-printer-db
137
+ - [ ] Rename CjkEncoding to RubyEncoding, rename CharmapEncoding, CharsetEncoding, also add IconvEncoding
138
+ - [ ] Encoding classes themselves should validate missing char (move from Escpos::Buffer class)
139
+ - [ ] Iconv config generator rake task.
140
+ - [ ] Set output format for thermal_print (default, base64, bytes, etc.)
141
+ - [ ] Params for escpos: :codepages, escpos: charsets
142
+ - [ ] Copy in Escpos and EscposImage gems (get rid of dependency)
143
+ - [ ] Param pass-thru to EscposImage
144
+ - [ ] Configurability of tmp path -- specific to stargraphic (?) -- Should use Tempfile
145
+ - [ ] Write Readme
146
+ - [ ] DslMixin should include protocol (?), ipp_uri (?) -- why??
147
+ - [ ] Specs for all classes, including base.
148
+ - [ ] StarGraphic needs multiple message buffering. ???
149
+ - [ ] Add QR to DSL
150
+
151
+ #### โœจ Nice to haves
152
+
153
+ - [ ] font support. col_width should be dynamic in the printer (currently depends on font 0)
154
+ - [ ] Copy "Available methods" from https://github.com/escpos/escpos-php
155
+ - [ ] Add HTML command in addition to text. Should be done as an AST (HtmlAst) like [[:text, 'ddd'], [:underline, 2, [[:text, 'foo']]]]
156
+ - [ ] Optional HTML image support
157
+ - [ ] Copy TestReport
158
+ - [ ] Stargraphic needs much better buffer support, including line break splitting + multiple buffers.
159
+ - [ ] Allow pass-in of codepage object.
160
+ - [ ] Allow pass-in of charset object.
161
+ - [ ] Indian ISCII encoding for Escpos (separate gem?).
162
+
163
+ # ๐Ÿ™ Contributing
164
+
165
+ To add support for additional Thermal printers.
166
+ - escpos-printer-db
167
+ - Add new code in `lib/thermal/printer/escpos.rb`
168
+ - Add new code in `lib/thermal/printer/starprnt.rb`
169
+
170
+ # ๐Ÿ’– Acknowledgements
171
+
172
+ ### ๐Ÿ‘จโ€๐Ÿ’ป Maintainers
173
+
174
+ Thermal is maintained and battle-tested by the team at [TableCheck](https://www.tablecheck.com/en/join/)
175
+ based in Tokyo, Japan. ๐Ÿ—ผ We use Thermal to help our restaurant users print chits, receipts, and
176
+ QR codes to serve their guests' reservations. If you are seeking your next career adventure,
177
+ [we're hiring](https://careers.tablecheck.com/)!
178
+
179
+ ### ๐Ÿ“š Data Sources
180
+
181
+ This gem relies on the community-maintained
182
+ [escpos-printer-db](https://github.com/receipt-print-hq/escpos-printer-db)
183
+ to provide a comprehensive list of thermal printers.
184
+
185
+ ### ๐ŸŒŸ Special Thanks
186
+
187
+ This gem draws inspiration from the following libraries.
188
+ Thank you to the authors for their hard work.
189
+ - [escpos-php](https://github.com/escpos/escpos-php)
190
+ - [escpos-printer-db](https://github.com/receipt-print-hq/escpos-printer-db)
191
+ - [EscPosEncoder JS](https://github.com/NielsLeenheer/EscPosEncoder/blob/master/src/esc-pos-encoder.js)
192
+
193
+ ### ยฉ๏ธ Copyright Attribution
194
+
195
+ The vendor manuals in the `doc/vendor` directory are the property of their respective owners.
196
+ They are included here for references purposes only under the fair use doctrine.
197
+
198
+ ### ๐Ÿ“œ License
199
+
200
+ This gem is released under the MIT License. Please see the [LICENSE](LICENSE) file for details.