Release 0.1.2: remove cut-after-print, fix Arch CI, embed CLI help.
Drop cut_after_print metadata; cutting is explicit via @cut only. Run makepkg as non-root user (--asroot removed in current makepkg). Embed platform HELP-CLI in binary; add posprint cli-help subcommand. Co-authored-by: Cursor <cursoragent@cursor.com>
@@ -66,10 +66,11 @@ build:linux-arch:
66
66
wayland libx11 fontconfig freetype2 libglvnd git rsync
67
67
- export PKGVER="${CI_COMMIT_TAG#v}"
68
68
- sed -i "s/^pkgver=.*/pkgver=${PKGVER}/" packaging/arch/PKGBUILD
69
- cd packaging/arch
70
- makepkg -f --noconfirm --asroot
69
- useradd -m builduser
70
- chown -R builduser:builduser "$CI_PROJECT_DIR"
71
- su builduser -c "cd $CI_PROJECT_DIR/packaging/arch && makepkg -f --noconfirm"
71
72
- mkdir -p "$CI_PROJECT_DIR/dist"
72
- cp ./*.pkg.tar.zst "$CI_PROJECT_DIR/dist/"
73
- cp packaging/arch/*.pkg.tar.zst "$CI_PROJECT_DIR/dist/"
73
74
artifacts:
74
75
name: "posprint-arch-$CI_COMMIT_TAG"
75
76
paths:
@@ -66,10 +66,11 @@ build:linux-arch:66
wayland libx11 fontconfig freetype2 libglvnd git rsync
66
wayland libx11 fontconfig freetype2 libglvnd git rsync
67
- export PKGVER="${CI_COMMIT_TAG#v}"
67
- export PKGVER="${CI_COMMIT_TAG#v}"
68
- sed -i "s/^pkgver=.*/pkgver=${PKGVER}/" packaging/arch/PKGBUILD
68
- sed -i "s/^pkgver=.*/pkgver=${PKGVER}/" packaging/arch/PKGBUILD
69
- cd packaging/arch
69
- useradd -m builduser
70
- makepkg -f --noconfirm --asroot
70
- chown -R builduser:builduser "$CI_PROJECT_DIR"
71
- su builduser -c "cd $CI_PROJECT_DIR/packaging/arch && makepkg -f --noconfirm"
71
- mkdir -p "$CI_PROJECT_DIR/dist"
72
- mkdir -p "$CI_PROJECT_DIR/dist"
72
- cp ./*.pkg.tar.zst "$CI_PROJECT_DIR/dist/"
73
- cp packaging/arch/*.pkg.tar.zst "$CI_PROJECT_DIR/dist/"
73
artifacts:
74
artifacts:
74
name: "posprint-arch-$CI_COMMIT_TAG"
75
name: "posprint-arch-$CI_COMMIT_TAG"
75
paths:
76
paths:
@@ -2528,7 +2528,7 @@ checksum = "2f3a9f18d041e6d0e102a0a46750538147e5e8992d3b4873aaafee2520b00ce3"
2528
2528
2529
2529
[[package]]
2530
2530
name = "posprint"
2531
version = "0.1.0"
2531
version = "0.1.2"
2532
2532
dependencies = [
2533
2533
"barcoders",
2534
2534
"chrono",
@@ -2528,7 +2528,7 @@ checksum = "2f3a9f18d041e6d0e102a0a46750538147e5e8992d3b4873aaafee2520b00ce3"2528
2528
2529
[[package]]2529
[[package]]2530
name = "posprint"2530
name = "posprint"2531
version = "0.1.0"2531
version = "0.1.2"2532
dependencies = [2532
dependencies = [2533
"barcoders",2533
"barcoders",2534
"chrono",2534
"chrono",@@ -1,6 +1,6 @@
1
1
[package]
2
2
name = "posprint"
3
version = "0.1.0"
3
version = "0.1.2"
4
4
edition = "2021"
5
5
description = "Designer for POS-print documents"
6
6
license = "MIT"
@@ -1,6 +1,6 @@1
[package]
1
[package]
2
name = "posprint"
2
name = "posprint"
3
version = "0.1.0"
3
version = "0.1.2"
4
edition = "2021"
4
edition = "2021"
5
description = "Designer for POS-print documents"
5
description = "Designer for POS-print documents"
6
license = "MIT"
6
license = "MIT"
@@ -84,8 +84,6 @@ Image paths in `@image` resolve relative to the `.pos` file directory on print.
84
84
3. User selects a USB-serial port from `list_usb_serial_printers()`.
85
85
4. `substitute_document` → `EscPosEncoder::encode_document` → `SerialTransport::open` (9600 baud) → `print_bytes`.
86
86
87
If `metadata.cut_after_print` is true and the template has no `@cut`, a cut command is appended automatically. Add blank lines or `@feed` in the template to control spacing before the cut.
88
89
87
---
90
88
91
89
## Key types
@@ -109,7 +107,7 @@ enum Block {
109
107
110
108
// io/
111
109
struct PosFile { version, metadata: PosMetadata, body }
112
struct PosMetadata { title, page_width_mm, preview_mode, chars_per_line, codepage, cut_after_print }
110
struct PosMetadata { title, page_width_mm, preview_mode, chars_per_line, codepage }
113
111
114
112
// print/
115
113
struct PrinterDevice { id, display_name, port_name }
@@ -84,8 +84,6 @@ Image paths in `@image` resolve relative to the `.pos` file directory on print.84
3. User selects a USB-serial port from `list_usb_serial_printers()`.
84
3. User selects a USB-serial port from `list_usb_serial_printers()`.
85
4. `substitute_document` → `EscPosEncoder::encode_document` → `SerialTransport::open` (9600 baud) → `print_bytes`.
85
4. `substitute_document` → `EscPosEncoder::encode_document` → `SerialTransport::open` (9600 baud) → `print_bytes`.
86
86
87
If `metadata.cut_after_print` is true and the template has no `@cut`, a cut command is appended automatically. Add blank lines or `@feed` in the template to control spacing before the cut.
88
89
---
87
---
90
88
91
## Key types
89
## Key types
@@ -109,7 +107,7 @@ enum Block {109
107
110
// io/
108
// io/
111
struct PosFile { version, metadata: PosMetadata, body }
109
struct PosFile { version, metadata: PosMetadata, body }
112
struct PosMetadata { title, page_width_mm, preview_mode, chars_per_line, codepage, cut_after_print }
110
struct PosMetadata { title, page_width_mm, preview_mode, chars_per_line, codepage }
113
111
114
// print/
112
// print/
115
struct PrinterDevice { id, display_name, port_name }
113
struct PrinterDevice { id, display_name, port_name }
@@ -31,10 +31,8 @@ A `.pos` file stores a POS print template: metadata (page settings, title) plus
31
31
{
32
32
"title": "Sales Receipt",
33
33
"page_width_mm": 80,
34
"preview_mode": "autoscale",
35
34
"chars_per_line": 48,
36
"codepage": "CP437",
37
"cut_after_print": true
35
"codepage": "CP437"
38
36
}
39
37
```
40
38
@@ -45,7 +43,6 @@ A `.pos` file stores a POS print template: metadata (page settings, title) plus
45
43
| `preview_mode` | `"autoscale"` \| `"fixed"` | `"autoscale"` | How preview panel sizes content |
46
44
| `chars_per_line` | `number?` | derived | Override character width for preview; derived from mm if omitted |
47
45
| `codepage` | `string?` | `"CP437"` | Character encoding for ESC/POS text |
48
| `cut_after_print` | `boolean` | `true` | Append cut command when printing if doc has no `@cut` |
49
46
50
47
### Page width derivation
51
48
@@ -66,9 +63,7 @@ A `.pos` file stores a POS print template: metadata (page settings, title) plus
66
63
"metadata": {
67
64
"title": "Standard Receipt",
68
65
"page_width_mm": 80,
69
"preview_mode": "autoscale",
70
"codepage": "CP437",
71
"cut_after_print": true
66
"codepage": "CP437"
72
67
},
73
68
"body": "# ${StoreName}\n:center:\n\nReceipt: ${DocumentNumber}\n\n---\n\n:right:\n**TOTAL: ${GrandTotal}**\n\n@barcode CODE128 ${DocumentNumber}\n@feed 4\n@cut\n"
74
69
}
@@ -97,14 +92,6 @@ If older → run migration chain (none yet).
97
92
98
93
---
99
94
100
## Alternative considered: two-file bundle
101
102
Rejected for v1: `.pos` + sidecar `.pos.json` adds friction. Single JSON file keeps save/load atomic.
103
104
A future `.poszip` could bundle images for portable templates.
105
106
---
107
108
95
## Validation rules
109
96
110
97
On save:
@@ -135,7 +122,6 @@ interface PosMetadata {
135
122
preview_mode: "autoscale" | "fixed";
136
123
chars_per_line?: number;
137
124
codepage?: string;
138
cut_after_print?: boolean;
139
125
}
140
126
```
141
127
@@ -31,10 +31,8 @@ A `.pos` file stores a POS print template: metadata (page settings, title) plus31
{
31
{
32
"title": "Sales Receipt",
32
"title": "Sales Receipt",
33
"page_width_mm": 80,
33
"page_width_mm": 80,
34
"preview_mode": "autoscale",
35
"chars_per_line": 48,
34
"chars_per_line": 48,
36
"codepage": "CP437",
35
"codepage": "CP437"
37
"cut_after_print": true
38
}
36
}
39
```
37
```
40
38
@@ -45,7 +43,6 @@ A `.pos` file stores a POS print template: metadata (page settings, title) plus45
| `preview_mode` | `"autoscale"` \| `"fixed"` | `"autoscale"` | How preview panel sizes content |
43
| `preview_mode` | `"autoscale"` \| `"fixed"` | `"autoscale"` | How preview panel sizes content |
46
| `chars_per_line` | `number?` | derived | Override character width for preview; derived from mm if omitted |
44
| `chars_per_line` | `number?` | derived | Override character width for preview; derived from mm if omitted |
47
| `codepage` | `string?` | `"CP437"` | Character encoding for ESC/POS text |
45
| `codepage` | `string?` | `"CP437"` | Character encoding for ESC/POS text |
48
| `cut_after_print` | `boolean` | `true` | Append cut command when printing if doc has no `@cut` |
49
46
50
### Page width derivation
47
### Page width derivation
51
48
@@ -66,9 +63,7 @@ A `.pos` file stores a POS print template: metadata (page settings, title) plus66
"metadata": {
63
"metadata": {
67
"title": "Standard Receipt",
64
"title": "Standard Receipt",
68
"page_width_mm": 80,
65
"page_width_mm": 80,
69
"preview_mode": "autoscale",
66
"codepage": "CP437"
70
"codepage": "CP437",
71
"cut_after_print": true
72
},
67
},
73
"body": "# ${StoreName}\n:center:\n\nReceipt: ${DocumentNumber}\n\n---\n\n:right:\n**TOTAL: ${GrandTotal}**\n\n@barcode CODE128 ${DocumentNumber}\n@feed 4\n@cut\n"
68
"body": "# ${StoreName}\n:center:\n\nReceipt: ${DocumentNumber}\n\n---\n\n:right:\n**TOTAL: ${GrandTotal}**\n\n@barcode CODE128 ${DocumentNumber}\n@feed 4\n@cut\n"
74
}
69
}
@@ -97,14 +92,6 @@ If older → run migration chain (none yet).97
92
98
---
93
---
99
94
100
## Alternative considered: two-file bundle
101
102
Rejected for v1: `.pos` + sidecar `.pos.json` adds friction. Single JSON file keeps save/load atomic.
103
104
A future `.poszip` could bundle images for portable templates.
105
106
---
107
108
## Validation rules
95
## Validation rules
109
96
110
On save:
97
On save:
@@ -135,7 +122,6 @@ interface PosMetadata {135
preview_mode: "autoscale" | "fixed";
122
preview_mode: "autoscale" | "fixed";
136
chars_per_line?: number;
123
chars_per_line?: number;
137
codepage?: string;
124
codepage?: string;
138
cut_after_print?: boolean;
139
}
125
}
140
```
126
```
141
127
@@ -2,6 +2,8 @@
2
2
3
3
Print a `.pos` template without opening the GUI.
4
4
5
Run `posprint cli-help` to print this section from the binary (no GUI required).
6
5
7
## Syntax
6
8
7
9
```bash
@@ -2,6 +2,8 @@2
2
3
Print a `.pos` template without opening the GUI.
3
Print a `.pos` template without opening the GUI.
4
4
5
Run `posprint cli-help` to print this section from the binary (no GUI required).
6
5
## Syntax
7
## Syntax
6
8
7
```bash
9
```bash
@@ -2,6 +2,8 @@
2
2
3
3
Print a `.pos` template without opening the GUI.
4
4
5
Run `posprint cli-help` to print this section from the binary (no GUI required).
6
5
7
## Syntax
6
8
7
9
```powershell
@@ -2,6 +2,8 @@2
2
3
Print a `.pos` template without opening the GUI.
3
Print a `.pos` template without opening the GUI.
4
4
5
Run `posprint cli-help` to print this section from the binary (no GUI required).
6
5
## Syntax
7
## Syntax
6
8
7
```powershell
9
```powershell
@@ -18,7 +18,7 @@ Built-in reference for the template editor and POS markup language.
18
18
|--------|-------------|
19
19
| **New** | Empty template with defaults |
20
20
| **Open** | Load a `.pos` file |
21
| **Save / Save As** | Write JSON `.pos` file (metadata + body) |
21
| **Save / Save As** | Write `.pos` file (metadata + body) |
22
22
| **Insert** | Menu to insert images, barcodes, QR codes, `@feed`, `@cut` |
23
23
| **Print** | Substitute parameters, pick USB printer, send ESC/POS bytes |
24
24
@@ -32,9 +32,6 @@ Built-in reference for the template editor and POS markup language.
32
32
| Setting | Description |
33
33
|---------|-------------|
34
34
| **Page width (mm)** | Paper width, typically `58` or `80` |
35
| **Preview mode** | `Auto-scale` fits preview to panel; `Fixed` uses exact mm width |
36
| **Code page** | Character encoding sent to printer (default `CP437`) |
37
| **Cut after print** | Append paper feed + cut if template has no `@cut` |
38
35
39
36
---
40
37
@@ -18,7 +18,7 @@ Built-in reference for the template editor and POS markup language.18
|--------|-------------|
18
|--------|-------------|
19
| **New** | Empty template with defaults |
19
| **New** | Empty template with defaults |
20
| **Open** | Load a `.pos` file |
20
| **Open** | Load a `.pos` file |
21
| **Save / Save As** | Write JSON `.pos` file (metadata + body) |
21
| **Save / Save As** | Write `.pos` file (metadata + body) |
22
| **Insert** | Menu to insert images, barcodes, QR codes, `@feed`, `@cut` |
22
| **Insert** | Menu to insert images, barcodes, QR codes, `@feed`, `@cut` |
23
| **Print** | Substitute parameters, pick USB printer, send ESC/POS bytes |
23
| **Print** | Substitute parameters, pick USB printer, send ESC/POS bytes |
24
24
@@ -32,9 +32,6 @@ Built-in reference for the template editor and POS markup language.32
| Setting | Description |
32
| Setting | Description |
33
|---------|-------------|
33
|---------|-------------|
34
| **Page width (mm)** | Paper width, typically `58` or `80` |
34
| **Page width (mm)** | Paper width, typically `58` or `80` |
35
| **Preview mode** | `Auto-scale` fits preview to panel; `Fixed` uses exact mm width |
36
| **Code page** | Character encoding sent to printer (default `CP437`) |
37
| **Cut after print** | Append paper feed + cut if template has no `@cut` |
38
35
39
---
36
---
40
37
@@ -29,7 +29,7 @@ Target **Epson ESC/POS** compatible printers (58 mm / 80 mm thermal).
29
29
| Double size | GS ! | Heading level 1 |
30
30
| Alignment | ESC a | Paragraphs, images, barcodes, QR |
31
31
| Line feed | LF, ESC d | Text lines, `@feed` |
32
| Partial cut | GS V 66 0 | `@cut`, auto-cut after print |
32
| Partial cut | GS V 66 0 | `@cut` in template |
33
33
| Barcode | GS k | CODE128, EAN13, EAN8, CODE39 |
34
34
| QR Code | GS ( k | Model 2 |
35
35
| Raster image | GS v 0 | `@image` via `image` crate → threshold |
@@ -29,7 +29,7 @@ Target **Epson ESC/POS** compatible printers (58 mm / 80 mm thermal).29
| Double size | GS ! | Heading level 1 |
29
| Double size | GS ! | Heading level 1 |
30
| Alignment | ESC a | Paragraphs, images, barcodes, QR |
30
| Alignment | ESC a | Paragraphs, images, barcodes, QR |
31
| Line feed | LF, ESC d | Text lines, `@feed` |
31
| Line feed | LF, ESC d | Text lines, `@feed` |
32
| Partial cut | GS V 66 0 | `@cut`, auto-cut after print |
32
| Partial cut | GS V 66 0 | `@cut` in template |
33
| Barcode | GS k | CODE128, EAN13, EAN8, CODE39 |
33
| Barcode | GS k | CODE128, EAN13, EAN8, CODE39 |
34
| QR Code | GS ( k | Model 2 |
34
| QR Code | GS ( k | Model 2 |
35
| Raster image | GS v 0 | `@image` via `image` crate → threshold |
35
| Raster image | GS v 0 | `@image` via `image` crate → threshold |
@@ -26,6 +26,9 @@ pub struct Cli {
26
26
27
27
#[derive(Subcommand, Debug)]
28
28
pub enum Commands {
29
/// Show command-line printing help (also in the GUI Help tab)
30
#[command(name = "cli-help")]
31
CliHelp,
29
32
/// Print a .pos file to a USB-serial printer (all parameters required)
30
33
Print {
31
34
/// Path to the `.pos` template file
@@ -41,6 +44,10 @@ pub enum Commands {
41
44
42
45
pub fn run(cli: Cli) -> i32 {
43
46
match cli.command {
47
Some(Commands::CliHelp) => {
48
println!("{}", crate::HELP_CLI_MARKDOWN);
49
0
50
}
44
51
Some(Commands::Print { file, printer, set }) => match run_print(&file, &printer, &set) {
45
52
Ok(()) => 0,
46
53
Err(e) => {
@@ -99,4 +106,13 @@ mod tests {
99
106
assert!(cli.print);
100
107
assert_eq!(cli.file.as_ref().unwrap().to_str().unwrap(), "doc.pos");
101
108
}
109
110
#[test]
111
fn cli_help_subcommand_prints_docs() {
112
assert_eq!(run(Cli {
113
command: Some(Commands::CliHelp),
114
print: false,
115
file: None,
116
}), 0);
117
}
102
118
}
@@ -26,6 +26,9 @@ pub struct Cli {26
26
27
#[derive(Subcommand, Debug)]
27
#[derive(Subcommand, Debug)]
28
pub enum Commands {
28
pub enum Commands {
29
/// Show command-line printing help (also in the GUI Help tab)
30
#[command(name = "cli-help")]
31
CliHelp,
29
/// Print a .pos file to a USB-serial printer (all parameters required)
32
/// Print a .pos file to a USB-serial printer (all parameters required)
30
Print {
33
Print {
31
/// Path to the `.pos` template file
34
/// Path to the `.pos` template file
@@ -41,6 +44,10 @@ pub enum Commands {41
44
42
pub fn run(cli: Cli) -> i32 {
45
pub fn run(cli: Cli) -> i32 {
43
match cli.command {
46
match cli.command {
47
Some(Commands::CliHelp) => {
48
println!("{}", crate::HELP_CLI_MARKDOWN);
49
0
50
}
44
Some(Commands::Print { file, printer, set }) => match run_print(&file, &printer, &set) {
51
Some(Commands::Print { file, printer, set }) => match run_print(&file, &printer, &set) {
45
Ok(()) => 0,
52
Ok(()) => 0,
46
Err(e) => {
53
Err(e) => {
@@ -99,4 +106,13 @@ mod tests {99
assert!(cli.print);
106
assert!(cli.print);
100
assert_eq!(cli.file.as_ref().unwrap().to_str().unwrap(), "doc.pos");
107
assert_eq!(cli.file.as_ref().unwrap().to_str().unwrap(), "doc.pos");
101
}
108
}
109
110
#[test]
111
fn cli_help_subcommand_prints_docs() {
112
assert_eq!(run(Cli {
113
command: Some(Commands::CliHelp),
114
print: false,
115
file: None,
116
}), 0);
117
}
102
}
118
}
@@ -43,9 +43,6 @@ impl EscPosEncoder {
43
43
for block in &document.blocks {
44
44
self.encode_block(block)?;
45
45
}
46
if self.metadata.cut_after_print && !document.blocks.iter().any(|b| matches!(b, Block::Cut)) {
47
self.cut();
48
}
49
46
Ok(&self.buffer)
50
47
}
51
48
@@ -437,7 +434,6 @@ mod tests {
437
434
fn encodes_cut_directive() {
438
435
let doc = parse("@cut").unwrap();
439
436
let mut enc = EscPosEncoder::new(PosMetadata {
440
cut_after_print: false,
441
437
..Default::default()
442
438
});
443
439
let bytes = enc.encode_document(&doc).unwrap();
@@ -445,10 +441,10 @@ mod tests {
445
441
}
446
442
447
443
#[test]
448
fn auto_cut_when_enabled() {
444
fn does_not_auto_cut_without_directive() {
449
445
let doc = parse("x").unwrap();
450
446
let mut enc = EscPosEncoder::new(PosMetadata::default());
451
447
let bytes = enc.encode_document(&doc).unwrap();
452
assert!(bytes.ends_with(&[0x1D, b'V', 66, 0]));
448
assert!(!bytes.windows(3).any(|w| w == [0x1D, b'V', 66]));
453
449
}
454
450
}
@@ -43,9 +43,6 @@ impl EscPosEncoder {43
for block in &document.blocks {
43
for block in &document.blocks {
44
self.encode_block(block)?;
44
self.encode_block(block)?;
45
}
45
}
46
if self.metadata.cut_after_print && !document.blocks.iter().any(|b| matches!(b, Block::Cut)) {
47
self.cut();
48
}
49
Ok(&self.buffer)
46
Ok(&self.buffer)
50
}
47
}
51
48
@@ -437,7 +434,6 @@ mod tests {437
fn encodes_cut_directive() {
434
fn encodes_cut_directive() {
438
let doc = parse("@cut").unwrap();
435
let doc = parse("@cut").unwrap();
439
let mut enc = EscPosEncoder::new(PosMetadata {
436
let mut enc = EscPosEncoder::new(PosMetadata {
440
cut_after_print: false,
441
..Default::default()
437
..Default::default()
442
});
438
});
443
let bytes = enc.encode_document(&doc).unwrap();
439
let bytes = enc.encode_document(&doc).unwrap();
@@ -445,10 +441,10 @@ mod tests {445
}
441
}
446
442
447
#[test]
443
#[test]
448
fn auto_cut_when_enabled() {
444
fn does_not_auto_cut_without_directive() {
449
let doc = parse("x").unwrap();
445
let doc = parse("x").unwrap();
450
let mut enc = EscPosEncoder::new(PosMetadata::default());
446
let mut enc = EscPosEncoder::new(PosMetadata::default());
451
let bytes = enc.encode_document(&doc).unwrap();
447
let bytes = enc.encode_document(&doc).unwrap();
452
assert!(bytes.ends_with(&[0x1D, b'V', 66, 0]));
448
assert!(!bytes.windows(3).any(|w| w == [0x1D, b'V', 66]));
453
}
449
}
454
}
450
}
@@ -16,12 +16,6 @@ pub struct PosMetadata {
16
16
pub chars_per_line: Option<u32>,
17
17
#[serde(skip_serializing_if = "Option::is_none")]
18
18
pub codepage: Option<String>,
19
#[serde(default = "default_cut_after_print")]
20
pub cut_after_print: bool,
21
}
22
23
fn default_cut_after_print() -> bool {
24
true
25
19
}
26
20
27
21
impl Default for PosMetadata {
@@ -31,7 +25,6 @@ impl Default for PosMetadata {
31
25
page_width_mm: 80.0,
32
26
chars_per_line: None,
33
27
codepage: Some("CP437".into()),
34
cut_after_print: true,
35
28
}
36
29
}
37
30
}
@@ -146,10 +139,7 @@ mod tests {
146
139
let json = r#"{
147
140
"version": 1,
148
141
"metadata": {
149
"page_width_mm": 80.0,
150
"preview_mode": "autoscale",
151
"cut_after_print": true,
152
"default_feed_before_cut": 4
142
"page_width_mm": 80.0
153
143
},
154
144
"body": "hello"
155
145
}"#;
@@ -162,6 +152,32 @@ mod tests {
162
152
.unwrap()
163
153
.contains("default_feed_before_cut")
164
154
);
155
assert!(
156
!loaded
157
.to_json_pretty()
158
.unwrap()
159
.contains("cut_after_print")
160
);
161
}
162
163
#[test]
164
fn ignores_legacy_cut_after_print_field() {
165
let json = r#"{
166
"version": 1,
167
"metadata": {
168
"page_width_mm": 80.0,
169
"cut_after_print": true
170
},
171
"body": "hello"
172
}"#;
173
let loaded = PosFile::from_json(json).unwrap();
174
assert_eq!(loaded.body, "hello");
175
assert!(
176
!loaded
177
.to_json_pretty()
178
.unwrap()
179
.contains("cut_after_print")
180
);
165
181
}
166
182
167
183
#[test]
@@ -16,12 +16,6 @@ pub struct PosMetadata {16
pub chars_per_line: Option<u32>,
16
pub chars_per_line: Option<u32>,
17
#[serde(skip_serializing_if = "Option::is_none")]
17
#[serde(skip_serializing_if = "Option::is_none")]
18
pub codepage: Option<String>,
18
pub codepage: Option<String>,
19
#[serde(default = "default_cut_after_print")]
20
pub cut_after_print: bool,
21
}
22
23
fn default_cut_after_print() -> bool {
24
true
25
}
19
}
26
20
27
impl Default for PosMetadata {
21
impl Default for PosMetadata {
@@ -31,7 +25,6 @@ impl Default for PosMetadata {31
page_width_mm: 80.0,
25
page_width_mm: 80.0,
32
chars_per_line: None,
26
chars_per_line: None,
33
codepage: Some("CP437".into()),
27
codepage: Some("CP437".into()),
34
cut_after_print: true,
35
}
28
}
36
}
29
}
37
}
30
}
@@ -146,10 +139,7 @@ mod tests {146
let json = r#"{
139
let json = r#"{
147
"version": 1,
140
"version": 1,
148
"metadata": {
141
"metadata": {
149
"page_width_mm": 80.0,
142
"page_width_mm": 80.0
150
"preview_mode": "autoscale",
151
"cut_after_print": true,
152
"default_feed_before_cut": 4
153
},
143
},
154
"body": "hello"
144
"body": "hello"
155
}"#;
145
}"#;
@@ -162,6 +152,32 @@ mod tests {162
.unwrap()
152
.unwrap()
163
.contains("default_feed_before_cut")
153
.contains("default_feed_before_cut")
164
);
154
);
155
assert!(
156
!loaded
157
.to_json_pretty()
158
.unwrap()
159
.contains("cut_after_print")
160
);
161
}
162
163
#[test]
164
fn ignores_legacy_cut_after_print_field() {
165
let json = r#"{
166
"version": 1,
167
"metadata": {
168
"page_width_mm": 80.0,
169
"cut_after_print": true
170
},
171
"body": "hello"
172
}"#;
173
let loaded = PosFile::from_json(json).unwrap();
174
assert_eq!(loaded.body, "hello");
175
assert!(
176
!loaded
177
.to_json_pretty()
178
.unwrap()
179
.contains("cut_after_print")
180
);
165
}
181
}
166
182
167
#[test]
183
#[test]
@@ -13,6 +13,12 @@ pub mod raster;
13
13
pub mod text_wrap;
14
14
pub mod undo;
15
15
16
#[cfg(windows)]
17
pub const HELP_CLI_MARKDOWN: &str = include_str!("../docs/HELP-CLI-WINDOWS.md");
18
19
#[cfg(not(windows))]
20
pub const HELP_CLI_MARKDOWN: &str = include_str!("../docs/HELP-CLI-LINUX.md");
21
16
22
#[cfg(windows)]
17
23
pub const HELP_MARKDOWN: &str = concat!(
18
24
include_str!("../docs/HELP.md"),
@@ -26,3 +32,15 @@ pub const HELP_MARKDOWN: &str = concat!(
26
32
"\n\n",
27
33
include_str!("../docs/HELP-CLI-LINUX.md")
28
34
);
35
36
#[cfg(test)]
37
mod tests {
38
use super::*;
39
40
#[test]
41
fn help_markdown_includes_cli_section() {
42
assert!(HELP_MARKDOWN.contains("posprint print"));
43
assert!(!HELP_CLI_MARKDOWN.is_empty());
44
assert!(HELP_MARKDOWN.contains(HELP_CLI_MARKDOWN));
45
}
46
}
@@ -13,6 +13,12 @@ pub mod raster;13
pub mod text_wrap;
13
pub mod text_wrap;
14
pub mod undo;
14
pub mod undo;
15
15
16
#[cfg(windows)]
17
pub const HELP_CLI_MARKDOWN: &str = include_str!("../docs/HELP-CLI-WINDOWS.md");
18
19
#[cfg(not(windows))]
20
pub const HELP_CLI_MARKDOWN: &str = include_str!("../docs/HELP-CLI-LINUX.md");
21
16
#[cfg(windows)]
22
#[cfg(windows)]
17
pub const HELP_MARKDOWN: &str = concat!(
23
pub const HELP_MARKDOWN: &str = concat!(
18
include_str!("../docs/HELP.md"),
24
include_str!("../docs/HELP.md"),
@@ -26,3 +32,15 @@ pub const HELP_MARKDOWN: &str = concat!(26
"\n\n",
32
"\n\n",
27
include_str!("../docs/HELP-CLI-LINUX.md")
33
include_str!("../docs/HELP-CLI-LINUX.md")
28
);
34
);
35
36
#[cfg(test)]
37
mod tests {
38
use super::*;
39
40
#[test]
41
fn help_markdown_includes_cli_section() {
42
assert!(HELP_MARKDOWN.contains("posprint print"));
43
assert!(!HELP_CLI_MARKDOWN.is_empty());
44
assert!(HELP_MARKDOWN.contains(HELP_CLI_MARKDOWN));
45
}
46
}
@@ -1,73 +1,73 @@
1
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
2
3
mod app;
4
mod print_dialog;
5
mod print_only_app;
6
mod shell_integration;
7
8
use std::sync::Arc;
9
10
use clap::Parser;
11
12
fn load_viewport_icon() -> Option<Arc<eframe::egui::IconData>> {
13
eframe::icon_data::from_png_bytes(include_bytes!("../pos-logo.png"))
14
.ok()
15
.map(Arc::new)
16
}
17
18
fn main() -> eframe::Result<()> {
19
shell_integration::ensure_print_context_menu();
20
21
let cli = posprint::cli::Cli::parse();
22
if cli.command.is_some() {
23
std::process::exit(posprint::cli::run(cli));
24
}
25
26
if cli.print {
27
let Some(path) = cli.file else {
28
eprintln!("--print requires a .pos file path");
29
std::process::exit(1);
30
};
31
return run_print_only(path);
32
}
33
34
let open_file = cli.file;
35
36
let mut viewport = eframe::egui::ViewportBuilder::default().with_inner_size([1200.0, 750.0]);
37
if let Some(icon) = load_viewport_icon() {
38
viewport = viewport.with_icon(icon);
39
}
40
41
let options = eframe::NativeOptions {
42
viewport,
43
..Default::default()
44
};
45
eframe::run_native(
46
"posprint",
47
options,
48
Box::new(move |_cc| {
49
Ok(Box::new(app::PosPrintApp::new_with_file(open_file)) as Box<dyn eframe::App>)
50
}),
51
)
52
}
53
54
fn run_print_only(path: std::path::PathBuf) -> eframe::Result<()> {
55
let mut viewport = eframe::egui::ViewportBuilder::default()
56
.with_inner_size([440.0, 420.0])
57
.with_min_inner_size([380.0, 320.0]);
58
if let Some(icon) = load_viewport_icon() {
59
viewport = viewport.with_icon(icon);
60
}
61
62
let options = eframe::NativeOptions {
63
viewport,
64
..Default::default()
65
};
66
eframe::run_native(
67
"posprint",
68
options,
69
Box::new(move |_cc| {
70
Ok(Box::new(print_only_app::PrintOnlyApp::new(path)) as Box<dyn eframe::App>)
71
}),
72
)
73
}
1
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
2
3
mod app;
4
mod print_dialog;
5
mod print_only_app;
6
mod shell_integration;
7
8
use std::sync::Arc;
9
10
use clap::Parser;
11
12
fn load_viewport_icon() -> Option<Arc<eframe::egui::IconData>> {
13
eframe::icon_data::from_png_bytes(include_bytes!("../pos-logo.png"))
14
.ok()
15
.map(Arc::new)
16
}
17
18
fn main() -> eframe::Result<()> {
19
shell_integration::ensure_print_context_menu();
20
21
let cli = posprint::cli::Cli::parse();
22
if cli.command.is_some() {
23
std::process::exit(posprint::cli::run(cli));
24
}
25
26
if cli.print {
27
let Some(path) = cli.file else {
28
eprintln!("--print requires a .pos file path");
29
std::process::exit(1);
30
};
31
return run_print_only(path);
32
}
33
34
let open_file = cli.file;
35
36
let mut viewport = eframe::egui::ViewportBuilder::default().with_inner_size([1200.0, 750.0]);
37
if let Some(icon) = load_viewport_icon() {
38
viewport = viewport.with_icon(icon);
39
}
40
41
let options = eframe::NativeOptions {
42
viewport,
43
..Default::default()
44
};
45
eframe::run_native(
46
"posprint",
47
options,
48
Box::new(move |_cc| {
49
Ok(Box::new(app::PosPrintApp::new_with_file(open_file)) as Box<dyn eframe::App>)
50
}),
51
)
52
}
53
54
fn run_print_only(path: std::path::PathBuf) -> eframe::Result<()> {
55
let mut viewport = eframe::egui::ViewportBuilder::default()
56
.with_inner_size([440.0, 420.0])
57
.with_min_inner_size([380.0, 320.0]);
58
if let Some(icon) = load_viewport_icon() {
59
viewport = viewport.with_icon(icon);
60
}
61
62
let options = eframe::NativeOptions {
63
viewport,
64
..Default::default()
65
};
66
eframe::run_native(
67
"posprint",
68
options,
69
Box::new(move |_cc| {
70
Ok(Box::new(print_only_app::PrintOnlyApp::new(path)) as Box<dyn eframe::App>)
71
}),
72
)
73
}
@@ -1,73 +1,73 @@1
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
1
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
2
2
3
mod app;
3
mod app;
4
mod print_dialog;
4
mod print_dialog;
5
mod print_only_app;
5
mod print_only_app;
6
mod shell_integration;
6
mod shell_integration;
7
7
8
use std::sync::Arc;
8
use std::sync::Arc;
9
9
10
use clap::Parser;
10
use clap::Parser;
11
11
12
fn load_viewport_icon() -> Option<Arc<eframe::egui::IconData>> {
12
fn load_viewport_icon() -> Option<Arc<eframe::egui::IconData>> {
13
eframe::icon_data::from_png_bytes(include_bytes!("../pos-logo.png"))
13
eframe::icon_data::from_png_bytes(include_bytes!("../pos-logo.png"))
14
.ok()
14
.ok()
15
.map(Arc::new)
15
.map(Arc::new)
16
}
16
}
17
17
18
fn main() -> eframe::Result<()> {
18
fn main() -> eframe::Result<()> {
19
shell_integration::ensure_print_context_menu();
19
shell_integration::ensure_print_context_menu();
20
20
21
let cli = posprint::cli::Cli::parse();
21
let cli = posprint::cli::Cli::parse();
22
if cli.command.is_some() {
22
if cli.command.is_some() {
23
std::process::exit(posprint::cli::run(cli));
23
std::process::exit(posprint::cli::run(cli));
24
}
24
}
25
25
26
if cli.print {
26
if cli.print {
27
let Some(path) = cli.file else {
27
let Some(path) = cli.file else {
28
eprintln!("--print requires a .pos file path");
28
eprintln!("--print requires a .pos file path");
29
std::process::exit(1);
29
std::process::exit(1);
30
};
30
};
31
return run_print_only(path);
31
return run_print_only(path);
32
}
32
}
33
33
34
let open_file = cli.file;
34
let open_file = cli.file;
35
35
36
let mut viewport = eframe::egui::ViewportBuilder::default().with_inner_size([1200.0, 750.0]);
36
let mut viewport = eframe::egui::ViewportBuilder::default().with_inner_size([1200.0, 750.0]);
37
if let Some(icon) = load_viewport_icon() {
37
if let Some(icon) = load_viewport_icon() {
38
viewport = viewport.with_icon(icon);
38
viewport = viewport.with_icon(icon);
39
}
39
}
40
40
41
let options = eframe::NativeOptions {
41
let options = eframe::NativeOptions {
42
viewport,
42
viewport,
43
..Default::default()
43
..Default::default()
44
};
44
};
45
eframe::run_native(
45
eframe::run_native(
46
"posprint",
46
"posprint",
47
options,
47
options,
48
Box::new(move |_cc| {
48
Box::new(move |_cc| {
49
Ok(Box::new(app::PosPrintApp::new_with_file(open_file)) as Box<dyn eframe::App>)
49
Ok(Box::new(app::PosPrintApp::new_with_file(open_file)) as Box<dyn eframe::App>)
50
}),
50
}),
51
)
51
)
52
}
52
}
53
53
54
fn run_print_only(path: std::path::PathBuf) -> eframe::Result<()> {
54
fn run_print_only(path: std::path::PathBuf) -> eframe::Result<()> {
55
let mut viewport = eframe::egui::ViewportBuilder::default()
55
let mut viewport = eframe::egui::ViewportBuilder::default()
56
.with_inner_size([440.0, 420.0])
56
.with_inner_size([440.0, 420.0])
57
.with_min_inner_size([380.0, 320.0]);
57
.with_min_inner_size([380.0, 320.0]);
58
if let Some(icon) = load_viewport_icon() {
58
if let Some(icon) = load_viewport_icon() {
59
viewport = viewport.with_icon(icon);
59
viewport = viewport.with_icon(icon);
60
}
60
}
61
61
62
let options = eframe::NativeOptions {
62
let options = eframe::NativeOptions {
63
viewport,
63
viewport,
64
..Default::default()
64
..Default::default()
65
};
65
};
66
eframe::run_native(
66
eframe::run_native(
67
"posprint",
67
"posprint",
68
options,
68
options,
69
Box::new(move |_cc| {
69
Box::new(move |_cc| {
70
Ok(Box::new(print_only_app::PrintOnlyApp::new(path)) as Box<dyn eframe::App>)
70
Ok(Box::new(print_only_app::PrintOnlyApp::new(path)) as Box<dyn eframe::App>)
71
}),
71
}),
72
)
72
)
73
}
73
}