improve printer format, reduce some logs

This commit is contained in:
Sean Sube 2025-06-18 20:31:10 -05:00
parent 7d680e469f
commit 02d4bae997
No known key found for this signature in database
GPG Key ID: 3EED7B957D362AF1
6 changed files with 53 additions and 16 deletions

View File

@ -0,0 +1,35 @@
import { Image, Printer } from "@node-escpos/core";
import USB from "@node-escpos/usb-adapter";
import { join } from "path";
async function printImage(path: string) {
const device = new USB();
await new Promise<void>((resolve,reject) => {
device.open(async function(err){
if(err){
reject(err);
return
}
let printer = new Printer(device, {});
const tux = path; // join(__dirname, '../assets/tux.png');
const image = await Image.load(tux);
// inject image to printer
printer = await printer.image(image, "d24")
printer
.cut()
.close()
.finally(resolve)
});
});
}
console.log(process.argv);
printImage(process.argv[2] || join(__dirname, 'tux.png'))
.then(() => console.log('done'))
.catch((err) => console.error(err));

BIN
server/scripts/tux.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

View File

@ -14,11 +14,11 @@ export class StepRepository extends BaseRepository<Step> {
.orderBy('order')
.select('*');
logger.info(`Retrieved ${steps.length} steps for task ${taskId}`);
/*logger.info(`Retrieved ${steps.length} steps for task ${taskId}`);
for (const step of steps) {
logger.info(`Step ${step.id}: name="${step.name}", instructions="${step.instructions}"`);
logger.info(`Full step data:`, JSON.stringify(step, null, 2));
}
}*/
return steps;
}

View File

@ -60,13 +60,14 @@ async function startServer() {
// YAML Import endpoint
app.post('/api/yaml/import', async (req, res) => {
try {
const { yamlContent } = req.body;
const yamlContent = req.body;
console.log('loading YAML:', yamlContent);
if (!yamlContent || typeof yamlContent !== 'string') {
if (!yamlContent || typeof yamlContent !== 'object') {
return res.status(400).json({ error: 'YAML content is required' });
}
await yamlService.importFromYaml(yamlContent);
await yamlService.importFromYaml(JSON.stringify(yamlContent));
res.json({ message: 'Database imported successfully' });
} catch (error) {
logger.error('Error importing YAML:', error);

View File

@ -126,7 +126,9 @@ export class SerialCommandExecutor implements CommandExecutor {
break;
case Command.CHECKBOX:
await this.printer.text(formatUtils.getCheckboxText(formatUtils.checkbox(params[0] as string)));
const text = params[0] as string;
const checkbox = `[ ] ${text}`;
await this.printer.text(checkbox);
break;
case Command.LIST:

View File

@ -5,7 +5,7 @@ import { StepRepository, PrintHistoryRepository } from '../db/repositories';
import { Knex } from 'knex';
import logger from '../logger';
import { formatUtils } from './format-utils';
import { CommandBuilder } from './printer-commands';
import { Command, CommandBuilder } from './printer-commands';
import { SerialCommandExecutor } from './command-executor';
import {
PRINTER_CONFIG,
@ -111,17 +111,15 @@ export class SerialPrinter implements PrinterInterface {
const step = taskSteps[i];
logger.info(`Printing step ${step.id}: name="${step.name}", instructions="${step.instructions}"`);
const headerText = formatUtils.getCheckboxText(formatUtils.stepHeader(step.name, i + 1, task.name, true));
commands.push(
CommandBuilder.fontSize(FONT_SIZES.NORMAL),
CommandBuilder.text(headerText),
...formatUtils.section(
'',
formatUtils.stepHeader(step.name, i + 1, task.name, true),
CommandBuilder.banner('-', PAPER_CONFIG.BANNER_LENGTH),
CommandBuilder.text(
step.instructions || 'No instructions provided',
'-'
),
CommandBuilder.newline(),
...CommandBuilder.stepBarcodeWithAlignment(step.id),
// ...CommandBuilder.stepBarcodeWithAlignment(step.id),
CommandBuilder.newline()
);
}
@ -170,7 +168,8 @@ export class SerialPrinter implements PrinterInterface {
CommandBuilder.align(ALIGNMENT.CENTER),
CommandBuilder.style(STYLE.BOLD),
CommandBuilder.fontSize(FONT_SIZES.NORMAL),
CommandBuilder.text(headerText),
formatUtils.stepHeader(step.name, stepNumber, task?.name),
// CommandBuilder.text(headerText),
CommandBuilder.newline(),
CommandBuilder.align(ALIGNMENT.LEFT),
CommandBuilder.fontSize(FONT_SIZES.NORMAL),