{"id":31762373,"url":"https://github.com/patamigo0/lib-custommenuinc","last_synced_at":"2025-10-09T22:18:35.458Z","repository":{"id":304819570,"uuid":"1020073829","full_name":"PatAmigo0/Lib-CustomMenuInC","owner":"PatAmigo0","description":"This lightweight library provides a simple, easy-to-use menu system for Windows console applications. It features customizable menus, keyboard and mouse navigation, and a clean abstraction layer.","archived":false,"fork":false,"pushed_at":"2025-09-07T14:13:02.000Z","size":352,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-07T16:12:18.866Z","etag":null,"topics":["c","gui-console","gui-library","windows-10","windows-console"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PatAmigo0.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-15T09:50:52.000Z","updated_at":"2025-09-07T14:13:05.000Z","dependencies_parsed_at":"2025-07-16T02:53:28.510Z","dependency_job_id":"b066b9a9-d649-4432-9439-332f47b3369c","html_url":"https://github.com/PatAmigo0/Lib-CustomMenuInC","commit_stats":null,"previous_names":["patamigo0/lib-custommenuinc"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/PatAmigo0/Lib-CustomMenuInC","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PatAmigo0%2FLib-CustomMenuInC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PatAmigo0%2FLib-CustomMenuInC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PatAmigo0%2FLib-CustomMenuInC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PatAmigo0%2FLib-CustomMenuInC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PatAmigo0","download_url":"https://codeload.github.com/PatAmigo0/Lib-CustomMenuInC/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PatAmigo0%2FLib-CustomMenuInC/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002119,"owners_count":26083307,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","gui-console","gui-library","windows-10","windows-console"],"created_at":"2025-10-09T22:18:23.502Z","updated_at":"2025-10-09T22:18:35.450Z","avatar_url":"https://github.com/PatAmigo0.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Windows Console Menu Library\n\nThis lightweight library provides a simple, high-performance menu system for Windows console applications. It features a highly optimized rendering engine, customizable menus, keyboard and mouse navigation, and a clean abstraction layer.\n\n## Version\n\n`0.9.4 STABLE`\n\n-----\n\n## ✨ NEW IN VERSION 0.9.4 STABLE ✨\n\n  - **Optimized Rendering Engine**: A new partial redraw system dramatically improves performance by only updating changed elements, eliminating flickering on selection changes. 🚀\n  - **Efficient Memory Management**: The library now pre-allocates memory for menus and options more efficiently, reducing expensive `realloc` calls and improving speed when adding options dynamically.\n  - **Robust Text Alignment**: Added support for **UTF-8** character counting, ensuring menu elements are perfectly centered and aligned, even with non-ASCII characters.\n  - **Refactored Color API**: The color management API has been modernized for better type safety and clarity.\n  - **Improved Input Stability**: Enhanced input handling to prevent missed or ghost inputs, especially on menu initialization.\n\n-----\n\n## Features\n\n  - **Windows-only implementation** (uses Windows API)\n  - Customizable headers and footers\n  - Colorful menu options with highlighting (VT100 \u0026 Legacy)\n  - Keyboard navigation (arrow keys + Enter)\n  - Mouse navigation (toggleable)\n  - Advanced color customization with macros / RGB colors\n  - Double buffering for smooth, flicker-free rendering\n  - **NEW**: Optimized partial screen redraws for maximum performance\n  - **NEW**: UTF-8 support for accurate text alignment\n  - Dynamically centers the menu in the console\n  - Legacy console support (Windows 7/8 compatibility) with automatic VT100 detection\n\n-----\n\n## Installation\n\n1.  Add `menu.h` and `menu.c` to your project.\n2.  Include the header in your code:\n    ```c\n    #include \"menu.h\"\n    ```\n\n-----\n\n## Requirements\n\n  - Windows operating system (Windows 7+)\n  - C99 compatible compiler\n  - Standard Windows libraries\n\n-----\n\n## Usage\n\n### Basic Setup\n\n```c\n#include \"menu.h\"\n\nvoid menu_callback(MENU menu, dpointer data)\n{\n    char* message = (char*)data;\n    printf(\"Selected: %s\\n\", message);\n    getchar();\n}\n\nint main()\n{\n    MENU main_menu = create_menu();\n\n    // Create menu items with associated data\n    add_option(main_menu, create_menu_item(\"Option 1\", menu_callback, \"First option\"));\n    add_option(main_menu, create_menu_item(\"Option 2\", menu_callback, \"Second option\"));\n    add_option(main_menu, create_menu_item(\"Exit\", menu_callback, \"Exiting...\"));\n\n    change_header(main_menu, \"MAIN MENU\");\n    change_footer(main_menu, \"Navigate with arrow keys or mouse\");\n\n    // Enable mouse support\n    toggle_mouse(main_menu);\n\n    enable_menu(main_menu);\n    \n    // Use clear_menu() or clear_menus() if menus are no more need\n    // clear_menus_and_exit(); \n    return 0;\n}\n```\n\n### Advanced Color \u0026 Legacy Mode Example\n\n```c\n#include \"menu.h\"\n\nvoid callback(MENU menu, void* data)\n{\n    printf(\"Callback executed!\\n\");\n    getchar();\n    // To close the menu after callback, you can call clear_menu()\n    // clear_menu(menu);\n}\n\nint main()\n{\n    // === Global Settings Configuration ===\n\n    // Create a new settings object to force legacy mode\n    MENU_SETTINGS settings = create_new_settings();\n    settings.force_legacy_mode = 1; // Force legacy color system and rendering (e.g., for Win 7 or win 10 old consoles)\n    set_default_menu_settings(settings);\n\n    // --- VT100 Color Settings (WILL BE IGNORED in legacy mode) ---\n    MENU_COLOR modern_colors = create_color_object();\n    modern_colors.headerColor = new_full_rgb_color(mrgb(255, 255, 255), mrgb(90, 0, 157)); // White on Purple\n    modern_colors.footerColor = new_full_rgb_color(mrgb(255, 255, 255), mrgb(90, 0, 157));\n    modern_colors.optionColor = new_full_rgb_color(mrgb(0, 0, 0), mrgb(200, 200, 200));   // Black on Light Gray\n    set_default_color_object(modern_colors);\n    \n    // --- Legacy Color Settings (WILL BE USED because of force_legacy_mode) ---\n    LEGACY_MENU_COLOR legacy_colors = create_legacy_color_object();\n    legacy_colors.headerColor = BRIGHT_MAGENTA;\n    legacy_colors.footerColor = BRIGHT_MAGENTA;\n    legacy_colors.optionColor = HIGHLIGHT_COLOR; // White on Blue\n    set_default_legacy_color_object(legacy_colors);\n\n    // === Menu Creation ===\n    MENU menu = create_menu();\n    add_option(menu, create_menu_item(\"Options\", callback, NULL));\n    add_option(menu, create_menu_item(\"Exit\", callback, NULL));\n    \n    enable_menu(menu);\n    return 0;\n}\n```\n\n-----\n\n## Core Functions Reference\n\n### Menu Creation \u0026 Management\n\n1.  **`MENU create_menu()`** Creates and returns a new menu object.\n2.  **`void enable_menu(MENU menu)`** Activates and displays the menu, entering its main loop.\n3.  **`void clear_menu(MENU menu)`** Frees all resources for a specific menu.\n4.  **`void clear_menus()`** Destroys all created menus.\n5.  **`void clear_menus_and_exit()`** Destroys all menus and exits the program with code 0.\n\n### Menu Item Management\n\n6.  **`MENU_ITEM create_menu_item(const char* text, __menu_callback callback, void* data)`** Creates a menu item with text, a callback function, and associated user data.\n7.  **`void add_option(MENU menu, const MENU_ITEM item)`** Adds a menu item to a menu.\n8.  **`void clear_option(MENU menu, MENU_ITEM option)`** Removes and frees a specific menu item from a menu.\n\n### Appearance Customization\n\n9.  **`void change_header(MENU menu, const char* text)`** Sets the menu header text.\n10. **`void change_footer(MENU menu, const char* text)`** Sets the menu footer text.\n11. **`void change_menu_policy(MENU menu, int header_policy, int footer_policy)`** Controls header/footer visibility (1 = show, 0 = hide).\n\n### Input Settings\n\n12. **`void toggle_mouse(MENU menu)`** Toggles mouse input support for a specific menu.\n\n### Configuration\n\n13. **`MENU_SETTINGS create_new_settings()`** Creates a new settings object with default values.\n14. **`void set_menu_settings(MENU menu, MENU_SETTINGS settings)`** Applies custom settings to a specific menu.\n15. **`void set_default_menu_settings(MENU_SETTINGS settings)`** Sets the default settings for all newly created menus.\n\n### VT100 / RGB Color Management\n\n16. **`MENU_COLOR create_color_object()`** Creates a new color object with default colors.\n17. **`void set_color_object(MENU menu, MENU_COLOR color_object)`** Applies a color scheme to a specific menu.\n18. **`void set_default_color_object(MENU_COLOR color_object)`** Sets the default color scheme for new menus.\n\n### Legacy Color Management\n\n19. **`LEGACY_MENU_COLOR create_legacy_color_object()`** Creates a new legacy color object.\n20. **`void set_legacy_color_object(MENU menu, LEGACY_MENU_COLOR color_object)`** Applies a legacy color scheme to a specific menu.\n21. **`void set_default_legacy_color_object(LEGACY_MENU_COLOR color_object)`** Sets the default legacy color scheme for new menus.\n\n### RGB Color Helpers\n\n22. **`MENU_RGB_COLOR mrgb(short r, short g, short b)`** Creates an RGB color structure.\n23. **`COLOR_OBJECT_PROPERTY new_rgb_color(int text_color, MENU_RGB_COLOR color)`** Returns a color property for either foreground (`text_color = 1`) or background (`text_color = 0`).\n24. **`COLOR_OBJECT_PROPERTY new_full_rgb_color(MENU_RGB_COLOR fg, MENU_RGB_COLOR bg)`** Returns a color property for a complete foreground and background pair.\n\n-----\n\n## Building\n\nCompile your application source file with `menu.c`:\n\n```bash\ngcc your_app.c menu.c -o your_app.exe\n```\n\n-----\n\n## Important Notes\n\n1.  **API Changes in 0.9.4 STABLE** The color management API has been refactored. Instead of passing char buffers, functions like `new_full_rgb_color` now return a `COLOR_OBJECT_PROPERTY` struct, which should be assigned directly (e.g., `my_colors.headerColor = new_full_rgb_color(...)`).\n\n2.  **Memory Management** - Use `clear_menu()` to free a menu's resources if you need to close it from a callback.\n\n      - `clear_menus_and_exit()` is a convenient way to clean up before program termination.\n      - The library now manages memory for options in blocks, making `add_option` more efficient.\n\n3.  **Performance** - The new rendering engine is extremely fast and avoids redrawing the entire screen on simple updates like selection changes.\n\n      - Mouse input is well-optimized.\n\n4.  **Compatibility** - **VT100 mode** (with full RGB color) requires Windows 10/11.\n\n      - **Legacy mode** works on Windows 7 and newer.\n      - The library automatically detects VT100 support but can be overridden with `settings.force_legacy_mode = 1;`.\n      - It's good practice to define both a modern `MENU_COLOR` and a `LEGACY_MENU_COLOR` scheme for your application to ensure it looks great on all target systems.\n\n5.  **Error Handling** - The library automatically handles console resizing and displays a user-friendly message if the window is too small, pausing until it's resized appropriately.\n\n-----\n\n## Contributing\n\nContributions are welcome\\! Please submit pull requests or open issues on GitHub.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatamigo0%2Flib-custommenuinc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatamigo0%2Flib-custommenuinc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatamigo0%2Flib-custommenuinc/lists"}