| 2959 | } |
| 2960 | |
| 2961 | String getScriptFromUser() { |
| 2962 | const int MAX_SCRIPTS = 10; |
| 2963 | String scripts[MAX_SCRIPTS]; |
| 2964 | int scriptCount = 0; |
| 2965 | |
| 2966 | scripts[scriptCount++] = "Example: Open Calculator"; |
| 2967 | scripts[scriptCount++] = "Example: Open CMD/Terminal"; |
| 2968 | scripts[scriptCount++] = "Example: WiFi Credentials"; |
| 2969 | scripts[scriptCount++] = "Example: Reverse Shell"; |
| 2970 | scripts[scriptCount++] = "Example: Rickroll"; |
| 2971 | scripts[scriptCount++] = "Load from SD"; |
| 2972 | scripts[scriptCount++] = "Cancel"; |
| 2973 | |
| 2974 | int selected = 0, scrollOffset = 0; |
| 2975 | int lastSelected = -1, lastScrollOffset = -1; |
| 2976 | bool exitMenu = false; |
| 2977 | int menuStartY = 60, menuItemHeight = 25; |
| 2978 | int maxVisibleItems = (tftHeight - menuStartY - 50) / menuItemHeight; |
| 2979 | if (maxVisibleItems > scriptCount) maxVisibleItems = scriptCount; |
| 2980 | |
| 2981 | while (!exitMenu) { |
| 2982 | if (selected != lastSelected || scrollOffset != lastScrollOffset) { |
| 2983 | tft.fillScreen(bruceConfig.bgColor); |
| 2984 | tft.drawRect(5, 5, tftWidth - 10, tftHeight - 10, TFT_WHITE); |
| 2985 | |
| 2986 | tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); |
| 2987 | tft.setTextSize(2); |
| 2988 | tft.setCursor((tftWidth - strlen("SELECT SCRIPT") * 12) / 2, 15); |
| 2989 | tft.print("SELECT SCRIPT"); |
| 2990 | tft.setTextSize(1); |
| 2991 | |
| 2992 | for (int i = 0; i < maxVisibleItems && (scrollOffset + i) < scriptCount; i++) { |
| 2993 | int scriptIdx = scrollOffset + i; |
| 2994 | int yPos = menuStartY + (i * menuItemHeight); |
| 2995 | if (yPos + menuItemHeight > tftHeight - 45) break; |
| 2996 | |
| 2997 | if (scriptIdx == selected) { |
| 2998 | tft.fillRect(20, yPos, tftWidth - 40, menuItemHeight - 3, TFT_WHITE); |
| 2999 | tft.setTextColor(TFT_BLACK, TFT_WHITE); |
| 3000 | tft.setCursor(25, yPos + 8); |
| 3001 | tft.print("> "); |
| 3002 | } else { |
| 3003 | tft.fillRect(20, yPos, tftWidth - 40, menuItemHeight - 3, bruceConfig.bgColor); |
| 3004 | tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); |
| 3005 | tft.setCursor(25, yPos + 8); |
| 3006 | tft.print(" "); |
| 3007 | } |
| 3008 | |
| 3009 | String displayName = scripts[scriptIdx]; |
| 3010 | if (displayName.length() > 28) displayName = displayName.substring(0, 25) + "..."; |
| 3011 | tft.print(displayName); |
| 3012 | } |
| 3013 | |
| 3014 | if (scriptCount > maxVisibleItems) { |
| 3015 | tft.setTextColor(TFT_CYAN, bruceConfig.bgColor); |
| 3016 | tft.setCursor(tftWidth - 25, menuStartY + 5); |
| 3017 | if (scrollOffset > 0) tft.print("^"); |
| 3018 | tft.setCursor(tftWidth - 25, menuStartY + (maxVisibleItems * menuItemHeight) - 20); |
no test coverage detected