From 81b0f25f32c9707024f5094018b7e031edd1f8a8 Mon Sep 17 00:00:00 2001 From: Moritz Martinius Date: Mon, 13 Oct 2025 20:35:58 +0200 Subject: [PATCH] Fix multiple lines and printer selection --- src/PtouchPrint.cpp | 4 ++-- src/core/PrinterService.cpp | 36 ++++++++++++++++++------------------ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/PtouchPrint.cpp b/src/PtouchPrint.cpp index e9e7eb3..bff590f 100644 --- a/src/PtouchPrint.cpp +++ b/src/PtouchPrint.cpp @@ -97,7 +97,7 @@ void PtouchPrint::setupLogger() { bool PtouchPrint::handleListDrivers() { auto driverFactory = std::make_unique(); - auto drivers = driverFactory->listAllDrivers(); + auto drivers = driverFactory->listAllDrivers(); fmt::print("Available printer drivers:\n"); for (const auto& driver : drivers) { @@ -133,7 +133,7 @@ bool PtouchPrint::handlePrinting() { for (const auto& [cmdType, value] : options.commands) { switch (cmdType) { case cli::CommandType::Text: - labelBuilder.addText(value + "\n"); + labelBuilder.addText(value); break; case cli::CommandType::Font: spdlog::debug("Setting font to {}", value); diff --git a/src/core/PrinterService.cpp b/src/core/PrinterService.cpp index a4b226f..91e1519 100644 --- a/src/core/PrinterService.cpp +++ b/src/core/PrinterService.cpp @@ -54,6 +54,20 @@ std::vector> PrinterService::detectPrinters() { } std::shared_ptr PrinterService::selectPrinter(const std::string& printerName) { + // If a specific printer is requested by name (not "auto"), try to create it directly + if (printerName != "auto") { + auto driverFactory = std::make_unique(); + auto printer = driverFactory->createByName(printerName); + if (printer) { + mCurrentPrinter = printer; + spdlog::info("Using explicitly selected printer: {}", printerName); + return mCurrentPrinter; + } + spdlog::error("Printer driver '{}' not found", printerName); + return nullptr; + } + + // Auto mode: detect USB printers if (mDetectedPrinters.empty()) { detectPrinters(); } @@ -63,24 +77,10 @@ std::shared_ptr PrinterService::selectPrinter(const std::string& return nullptr; } - // Auto-select first printer - if (printerName == "auto") { - mCurrentPrinter = mDetectedPrinters.front(); - spdlog::info("Auto-selected printer: {}", mCurrentPrinter->getName()); - return mCurrentPrinter; - } - - // Select printer by name - for (auto& printer : mDetectedPrinters) { - if (printer->getDriverName() == printerName) { - mCurrentPrinter = printer; - spdlog::info("Using explicitly selected printer: {}", printerName); - return mCurrentPrinter; - } - } - - spdlog::error("Printer '{}' not found", printerName); - return nullptr; + // Auto-select first detected printer + mCurrentPrinter = mDetectedPrinters.front(); + spdlog::info("Auto-selected printer: {}", mCurrentPrinter->getName()); + return mCurrentPrinter; } bool PrinterService::printLabel(std::unique_ptr label) {