| 153 | } |
| 154 | |
| 155 | void JsonConsole::parseCommand(const fl::string& command) FL_NOEXCEPT { |
| 156 | FL_WARN("JsonConsole::parseCommand: Parsing command '" << command.c_str() << "'"); |
| 157 | |
| 158 | // Look for pattern: "name: value" |
| 159 | i16 colonPos = command.find(':'); |
| 160 | FL_WARN("JsonConsole::parseCommand: Colon position: " << colonPos); |
| 161 | |
| 162 | if (colonPos == -1) { |
| 163 | writeOutput("Error: Command format should be 'name: value'"); |
| 164 | return; |
| 165 | } |
| 166 | |
| 167 | // Work around fl::string::substring bug - it includes the end index when it shouldn't |
| 168 | fl::string name = command.substring(0, static_cast<fl::size>(colonPos - 1)); |
| 169 | fl::string valueStr = command.substring(static_cast<fl::size>(colonPos + 1), command.size()); |
| 170 | |
| 171 | FL_WARN("JsonConsole::parseCommand: Raw name: '" << name.c_str() << "'"); |
| 172 | FL_WARN("JsonConsole::parseCommand: Raw valueStr: '" << valueStr.c_str() << "'"); |
| 173 | |
| 174 | // Trim whitespace from name and value |
| 175 | while (!name.empty() && name[name.size()-1] == ' ') { |
| 176 | name = name.substring(0, name.size()-1); |
| 177 | } |
| 178 | while (!valueStr.empty() && valueStr[0] == ' ') { |
| 179 | valueStr = valueStr.substring(1, valueStr.size()); |
| 180 | } |
| 181 | |
| 182 | FL_WARN("JsonConsole::parseCommand: Trimmed name: '" << name.c_str() << "'"); |
| 183 | FL_WARN("JsonConsole::parseCommand: Trimmed valueStr: '" << valueStr.c_str() << "'"); |
| 184 | |
| 185 | if (name.empty() || valueStr.empty()) { |
| 186 | writeOutput("Error: Both name and value are required"); |
| 187 | return; |
| 188 | } |
| 189 | |
| 190 | // Try to parse value as float |
| 191 | float value = 0.0f; |
| 192 | const char* cstr = valueStr.c_str(); |
| 193 | char* endptr; |
| 194 | double parsed = strtod(cstr, &endptr); |
| 195 | if (endptr == cstr || *endptr != '\0') { |
| 196 | writeOutput("Error: Invalid numeric value"); |
| 197 | return; |
| 198 | } |
| 199 | value = static_cast<float>(parsed); |
| 200 | |
| 201 | // Try to set the slider value |
| 202 | if (setSliderValue(name, value)) { |
| 203 | fl::string response = "Set "; |
| 204 | response += name; |
| 205 | response += " to "; |
| 206 | response += valueStr; |
| 207 | writeOutput(response); |
| 208 | } else { |
| 209 | fl::string error = "Error: Component '"; |
| 210 | error += name; |
| 211 | error += "' not found"; |
| 212 | writeOutput(error); |