Add cli options for formatting
All checks were successful
Build ptprnt / build (push) Successful in 1m11s
All checks were successful
Build ptprnt / build (push) Successful in 1m11s
This commit is contained in:
@@ -23,33 +23,42 @@
|
||||
#include <spdlog/common.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "CLI/Option.hpp"
|
||||
#include "P700Printer.hpp"
|
||||
#include "graphics/Bitmap.hpp"
|
||||
#include "libusbwrap/UsbDeviceFactory.hpp"
|
||||
|
||||
namespace ptprnt {
|
||||
|
||||
PtouchPrint::PtouchPrint(const char* versionString) : mVersionString{versionString} {}
|
||||
|
||||
int PtouchPrint::init(int argc, char** argv) {
|
||||
setupCliParser();
|
||||
if (mVerboseFlag) {
|
||||
setupLogger(spdlog::level::debug);
|
||||
} else {
|
||||
setupLogger(spdlog::level::critical);
|
||||
}
|
||||
|
||||
try {
|
||||
mApp.parse(argc, argv);
|
||||
} catch (const CLI::ParseError& e) {
|
||||
return mApp.exit(e);
|
||||
mApp.exit(e);
|
||||
return -1;
|
||||
}
|
||||
|
||||
mUsbDeviceFactory.init();
|
||||
if (mVerboseFlag) {
|
||||
setupLogger(spdlog::level::trace);
|
||||
} else {
|
||||
setupLogger(spdlog::level::critical);
|
||||
}
|
||||
|
||||
if (!mUsbDeviceFactory.init()) {
|
||||
spdlog::error("Could not initialize libusb");
|
||||
return -1;
|
||||
}
|
||||
mCompatiblePrinters = {std::make_shared<ptprnt::printer::P700Printer>()};
|
||||
return 0;
|
||||
}
|
||||
|
||||
int PtouchPrint::run() {
|
||||
|
||||
auto numFoundPrinters = getCompatiblePrinters();
|
||||
if (numFoundPrinters == 0) {
|
||||
spdlog::error(
|
||||
@@ -71,9 +80,13 @@ int PtouchPrint::run() {
|
||||
auto status = printer->getPrinterStatus();
|
||||
spdlog::info("Detected tape width is {}mm", status.tapeWidthMm);
|
||||
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(512, 128);
|
||||
printer->printBitmap(bm);
|
||||
//printer->printBitmap(bm);
|
||||
//printer->printText("wurst", 1);
|
||||
|
||||
for (auto& cmd : mCommands) {
|
||||
std::cout << cmd.second << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -105,5 +118,39 @@ void PtouchPrint::setupLogger(spdlog::level::level_enum lvl) {
|
||||
}
|
||||
|
||||
void PtouchPrint::setupCliParser() {
|
||||
mApp.add_option("-v,--verbose", mVerboseFlag, "Enable verbose output");
|
||||
}
|
||||
auto printVersion = [this](std::size_t) {
|
||||
std::cout << "ptprnt version: " << mVersionString << std::endl;
|
||||
};
|
||||
|
||||
mApp.add_flag("-v,--verbose", mVerboseFlag, "Enable verbose output");
|
||||
mApp.add_flag("-V,--version", printVersion, "Prints the ptprnt's version");
|
||||
mApp.add_option("-t,--text",
|
||||
"Text to print (can be used multple times, use formatting options before to "
|
||||
"influence text layout)")
|
||||
->group("Printing")
|
||||
->multi_option_policy(CLI::MultiOptionPolicy::TakeAll)
|
||||
->trigger_on_parse()
|
||||
->each([this](std::string text) { mCommands.emplace_back(CliCmdType::Text, text); });
|
||||
mApp.add_option("-f,--font", "Font used for the following text occurences")
|
||||
->group("Printing")
|
||||
->multi_option_policy(CLI::MultiOptionPolicy::TakeAll)
|
||||
->trigger_on_parse()
|
||||
->each([this](std::string font) { mCommands.emplace_back(CliCmdType::Font, font); });
|
||||
mApp.add_option("-s,--fontsize", "Font size of the following text occurences")
|
||||
->group("Printing")
|
||||
->multi_option_policy(CLI::MultiOptionPolicy::TakeAll)
|
||||
->trigger_on_parse()
|
||||
->each([this](std::string size) { mCommands.emplace_back(CliCmdType::FontSize, size); });
|
||||
mApp.add_option("--valign", "Vertical alignment of the following text occurences")
|
||||
->group("Printing")
|
||||
->multi_option_policy(CLI::MultiOptionPolicy::TakeAll)
|
||||
->trigger_on_parse()
|
||||
->each([this](std::string valign) { mCommands.emplace_back(CliCmdType::VAlign, valign); });
|
||||
mApp.add_option("--halign", "Vertical alignment of the following text occurences")
|
||||
->group("Printing")
|
||||
->multi_option_policy(CLI::MultiOptionPolicy::TakeAll)
|
||||
->trigger_on_parse()
|
||||
->each([this](std::string halign) { mCommands.emplace_back(CliCmdType::HAlign, halign); });
|
||||
}
|
||||
|
||||
} // namespace ptprnt
|
||||
Reference in New Issue
Block a user