Skip to content

A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol

add choice index selection with const array actions

Geocb33ec52a350
diff --git a/src/Managers/UserInputManager.cpp b/src/Managers/UserInputManager.cpp
index e5d5241a..23329d45 100644
--- a/src/Managers/UserInputManager.cpp
+++ b/src/Managers/UserInputManager.cpp
@@ -428,6 +428,46 @@ int UserInputManager::readValidatedChoiceIndex(const std::string& label,
return readValidatedChoiceIndex(label, strChoices, defaultIndex);
}
+int UserInputManager::readValidatedChoiceIndex(const std::string& label,
+ const char* const* choices,
+ size_t count,
+ int defaultIndex)
+{
+ if (!choices || count == 0) {
+ terminalView.println("❌ No choices available.");
+ return -1;
+ }
+
+ if (defaultIndex < 0 || defaultIndex >= (int)count) {
+ defaultIndex = 0;
+ }
+
+ terminalView.println(label + ":");
+ for (size_t i = 0; i < count; ++i) {
+ const char* s = choices[i] ? choices[i] : "";
+ const bool isDef = ((int)i == defaultIndex);
+
+ terminalView.println(
+ " [" + std::to_string(i + 1) + "] " +
+ std::string(isDef ? "* " : " ") +
+ s
+ );
+ }
+
+ terminalView.print("Enter index (default " + std::to_string(defaultIndex + 1) + "): ");
+ std::string input = getLine(true); // only numbers
+
+ if (input.empty()) return defaultIndex;
+
+ int idx = 0;
+ if (!argTransformer.parseInt(input, idx) || idx < 1 || idx > (int)count) {
+ terminalView.println("❌ Invalid choice. Using default.");
+ return defaultIndex;
+ }
+
+ return idx - 1;
+}
+
float UserInputManager::readValidatedFloat(const std::string& label,
float def,
float min,
@@ -448,4 +488,5 @@ float UserInputManager::readValidatedFloat(const std::string& label,
}
terminalView.println("Invalid input. Must be " + std::to_string(min) + " .. " + std::to_string(max));
}
-}
\ No newline at end of file
+}
+
diff --git a/src/Managers/UserInputManager.h b/src/Managers/UserInputManager.h
index 41d134b5..bf6d0e4c 100644
--- a/src/Managers/UserInputManager.h
+++ b/src/Managers/UserInputManager.h
@@ -42,6 +42,7 @@ public:
int readValidatedChoiceIndex(const std::string& label, const std::vector<std::string>& choices, int defaultIndex = 0);
int readValidatedChoiceIndex(const std::string& label, const std::vector<int>& choices, int defaultIndex);
int readValidatedChoiceIndex(const std::string& label, const std::vector<float>& choices, int defaultIndex);
+ int readValidatedChoiceIndex(const std::string& label, const char* const* choices, size_t count, int defaultIndex);
private:
ITerminalView& terminalView;
IInput& terminalInput;