Summary Files Commits Branches @commit @diff @stats
path: root / src
diff options
context:
space:
mode:
Commitda2ad781fd156e274ad47e38b919b7c19ae8d049 (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-07-23 14:02:57 +0300
Committer
 Syndamia <kamen@syndamia.com>
2025-07-23 14:02:57 +0300
Filesf0dd41799e9596241f3d9f4a1db4094feb65990c /src
screen-generator-nemetschek-da2ad781fd156e274ad47e38b919b7c19ae8d049.tar
screen-generator-nemetschek-da2ad781fd156e274ad47e38b919b7c19ae8d049.tar.gz
screen-generator-nemetschek-da2ad781fd156e274ad47e38b919b7c19ae8d049.zip
Parent11eb7853f38e8074268094c328737369a43dc3e4 (diff)
feat: Move aspect ratio input parsing into cli
2 files changed, 19 insertions, 5 deletions
-rw-r--r--src/LEDVideoWall.cpp11
-rw-r--r--src/cli.hpp13
diff --git a/src/LEDVideoWall.cpp b/src/LEDVideoWall.cpp
index ad3dc3c..fc447bc 100644
--- a/src/LEDVideoWall.cpp
+++ b/src/LEDVideoWall.cpp
@@ -62,11 +62,12 @@ LEDVideoWall* LEDVideoWall::fromCommandLine() {
case LEDVideoWallType::Aspect: {
mm i_width = 0, i_height = 0;
- printf("Enter aspect ratio (in the format 'width:height'): ");
- while (scanf("%d:%d", &i_width, &i_height) != 2) {
- printf("Invalid input, try again!\n");
- printf("Enter aspect ratio (in the format 'width:height'): ");
- }
+ cli::scanTwoValues(
+ "%d:%d",
+ i_width,
+ i_height,
+ "Enter aspect ratio (in the format 'width:height'): ",
+ "Invalid input, try again!");
return LEDVideoWall::Aspect(ipanel_width, ipanel_height, i_width, i_height);
};
diff --git a/src/cli.hpp b/src/cli.hpp
index 21f2ae5..b7d4c30 100644
--- a/src/cli.hpp
+++ b/src/cli.hpp
@@ -3,6 +3,7 @@
#include <iostream>
#include <limits>
+#include <stdio.h>
namespace cli {
template <typename T>
@@ -29,6 +30,18 @@ namespace cli {
readUserInput(outValue, enter_message, error_message);
}
}
+
+ template <typename T, typename U>
+ void scanTwoValues(const char* format, T& outFirst, U& outSecond, const char* enter_message, const char* error_message) {
+ std::cout << enter_message;
+ while (scanf(format, &outFirst, &outSecond) != 2) {
+ std::cerr << error_message << std::endl;
+ std::cout << enter_message;
+
+ std::cin.clear();
+ std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
+ }
+ }
}
#endif /* GS_CLI */