Fix multiple lines and printer selection
This commit is contained in:
@@ -97,7 +97,7 @@ void PtouchPrint::setupLogger() {
|
|||||||
|
|
||||||
bool PtouchPrint::handleListDrivers() {
|
bool PtouchPrint::handleListDrivers() {
|
||||||
auto driverFactory = std::make_unique<PrinterDriverFactory>();
|
auto driverFactory = std::make_unique<PrinterDriverFactory>();
|
||||||
auto drivers = driverFactory->listAllDrivers();
|
auto drivers = driverFactory->listAllDrivers();
|
||||||
|
|
||||||
fmt::print("Available printer drivers:\n");
|
fmt::print("Available printer drivers:\n");
|
||||||
for (const auto& driver : drivers) {
|
for (const auto& driver : drivers) {
|
||||||
@@ -133,7 +133,7 @@ bool PtouchPrint::handlePrinting() {
|
|||||||
for (const auto& [cmdType, value] : options.commands) {
|
for (const auto& [cmdType, value] : options.commands) {
|
||||||
switch (cmdType) {
|
switch (cmdType) {
|
||||||
case cli::CommandType::Text:
|
case cli::CommandType::Text:
|
||||||
labelBuilder.addText(value + "\n");
|
labelBuilder.addText(value);
|
||||||
break;
|
break;
|
||||||
case cli::CommandType::Font:
|
case cli::CommandType::Font:
|
||||||
spdlog::debug("Setting font to {}", value);
|
spdlog::debug("Setting font to {}", value);
|
||||||
|
|||||||
@@ -54,6 +54,20 @@ std::vector<std::shared_ptr<IPrinterDriver>> PrinterService::detectPrinters() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<IPrinterDriver> PrinterService::selectPrinter(const std::string& printerName) {
|
std::shared_ptr<IPrinterDriver> 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<PrinterDriverFactory>();
|
||||||
|
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()) {
|
if (mDetectedPrinters.empty()) {
|
||||||
detectPrinters();
|
detectPrinters();
|
||||||
}
|
}
|
||||||
@@ -63,24 +77,10 @@ std::shared_ptr<IPrinterDriver> PrinterService::selectPrinter(const std::string&
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto-select first printer
|
// Auto-select first detected printer
|
||||||
if (printerName == "auto") {
|
mCurrentPrinter = mDetectedPrinters.front();
|
||||||
mCurrentPrinter = mDetectedPrinters.front();
|
spdlog::info("Auto-selected printer: {}", mCurrentPrinter->getName());
|
||||||
spdlog::info("Auto-selected printer: {}", mCurrentPrinter->getName());
|
return mCurrentPrinter;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PrinterService::printLabel(std::unique_ptr<graphics::ILabel> label) {
|
bool PrinterService::printLabel(std::unique_ptr<graphics::ILabel> label) {
|
||||||
|
|||||||
Reference in New Issue
Block a user