Conversation
- Introduce new methods for adding raw commands to the document. - Implement safety checks for potentially dangerous commands in safe mode. - Enhance the executor to handle raw command execution with format support. - Add comprehensive documentation for raw command usage and limitations. - Include tests for raw command handling and validation. Signed-off-by: Adrián Constante <ad_con.reload@proton.me>
Contributor
|
👋 Thanks for opening this PR, @adcondev! Here's what will happen next:
Please make sure:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces comprehensive support for sending raw ESC/POS commands directly to POS printers, enabling advanced manufacturer-specific operations beyond the standard command set. The implementation includes safety mechanisms to prevent dangerous commands in safe mode, multiple input format support (hex, base64), and extensive documentation with practical examples.
Key changes:
- Added raw command handler with safety validation for dangerous command patterns
- Implemented builder methods for raw command construction with convenience wrappers (cash drawer pulse, beeper)
- Comprehensive test coverage for hex parsing, command validation, and execution scenarios
Reviewed changes
Copilot reviewed 14 out of 18 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
pkg/document/raw_handler.go |
Core raw command handler with format parsing, safety checks, and bidirectional command detection |
pkg/document/raw_handler_test.go |
Extensive test suite covering hex parsing, validation, safe mode, and edge cases |
pkg/document/converter.go |
Builder methods for adding raw commands with safety mode options and convenience methods |
pkg/document/executor.go |
Handler registration for raw commands with debug logging |
pkg/document/handlers.go |
Added TODO comment for improving cut feed calculation |
internal/testutils/handler_helpers.go |
Mock connector and test utilities for raw command testing |
pkg/service/escpos_printer.go |
Added commented beep configuration for printer initialization |
docs/RAW_COMMAND.md |
Comprehensive documentation on raw command usage, limitations, and security |
api/v1/document.schema.json |
JSON schema definition for raw command type |
api/v1/DOCUMENT_V1.md |
API documentation for raw command with examples |
examples/beeper/beeper_example.go |
Go example demonstrating manufacturer-specific beeper command |
examples/document/raw/*.json |
JSON examples for simple beeper, advanced features, and kiosk turnos |
examples/document/tickets/*.json |
Sample ticket documents (not related to raw commands) |
.gitignore |
Updated to allow new documentation files |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Adrián Constante <ad_con.reload@proton.me>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Adrián Constante <ad_con.reload@proton.me>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Adrián Constante <ad_con.reload@proton.me>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request introduces support for sending raw commands directly to POS printers, enabling advanced and manufacturer-specific operations that are not covered by standard ESC/POS commands. The changes include updates to the API documentation and JSON schema, new code for handling raw commands, convenience methods for common raw operations, and several example documents and usage guides. The implementation also adds a dedicated handler for raw commands and includes new test utilities.
Raw Command Feature Implementation:
rawcommand type in the API and JSON schema, allowing users to send arbitrary bytes to the printer with options for format, safety checks, and documentation. [1] [2] [3] [4]converter.gofor adding raw commands, including convenience functions for cash drawer pulses and beeps, and safety mode enforcement.Documentation and Examples:
RAW_COMMAND.md) explaining raw command usage, security modes, supported formats, and example escape sequences for common hardware features.beeper_example.go) showing how to send manufacturer-specific raw commands for hardware features not covered by the standard.Core Handler and Test Utilities:
rawcommands in the document executor, with debug logging for handler registration and improved organization of handler setup.Minor Improvements:
These changes collectively make the library more flexible and suitable for advanced use cases, while also providing safety mechanisms and clear documentation for developers.
Type of Change
Component(s) Affected
composer- ESC/POS protocol composerconnection- Printer connectionscommands- ESC/POS command implementationsdocument- Document processinggraphics- Image processingprinter- Barcode generationprofile- Printer profilesservice- High-level printer servicegithub- GitHub related files and workflowsHow Has This Been Tested?
Test Configuration
Checklist
Screenshots/Examples
Breaking Changes
Additional Notes