Loading menu.c +11 −4 Original line number Diff line number Diff line Loading @@ -70,10 +70,19 @@ int menu_prompt(const menu_item *items, unsigned int num_menu_items, const char printf("\033[A"); // move cursor up one line printf("\033[2K"); // clear entire line } printf("\r"); // move cursor to beginning of line (probably unnecessary) return selected_action; } void clear_lines(unsigned int num_menu_items) { for (unsigned int i = 0; i < num_menu_items; i++) { printf("\033[A"); // move cursor up one line printf("\033[2K"); // clear entire line } printf("\r"); // move cursor to beginning of line (probably unnecessary) } void menu_prompt_multi_select(menu_item *items, unsigned int num_menu_items, const char *title, const char *item_disabled_label) { printf("%s\n", title); printf("Press SPACE to select an item. Press ENTER to make your selection.\n"); Loading @@ -87,10 +96,7 @@ void menu_prompt_multi_select(menu_item *items, unsigned int num_menu_items, con do { // return cursor to menu top position if (hovered_item_changed) { for (unsigned int i = 0; i < num_menu_items; i++) { printf("\033[A"); // move cursor up one line printf("\033[2K"); // clear entire line } clear_lines(num_menu_items); // print menu items, showing selection for (unsigned int i = 0; i < num_menu_items; i++) { Loading Loading @@ -146,6 +152,7 @@ void menu_prompt_multi_select(menu_item *items, unsigned int num_menu_items, con printf("\033[A"); // move cursor up one line printf("\033[2K"); // clear entire line } printf("\r"); // move cursor to beginning of line (probably unnecessary) } MENU_DIRECTION get_direction(void) { Loading Loading
menu.c +11 −4 Original line number Diff line number Diff line Loading @@ -70,10 +70,19 @@ int menu_prompt(const menu_item *items, unsigned int num_menu_items, const char printf("\033[A"); // move cursor up one line printf("\033[2K"); // clear entire line } printf("\r"); // move cursor to beginning of line (probably unnecessary) return selected_action; } void clear_lines(unsigned int num_menu_items) { for (unsigned int i = 0; i < num_menu_items; i++) { printf("\033[A"); // move cursor up one line printf("\033[2K"); // clear entire line } printf("\r"); // move cursor to beginning of line (probably unnecessary) } void menu_prompt_multi_select(menu_item *items, unsigned int num_menu_items, const char *title, const char *item_disabled_label) { printf("%s\n", title); printf("Press SPACE to select an item. Press ENTER to make your selection.\n"); Loading @@ -87,10 +96,7 @@ void menu_prompt_multi_select(menu_item *items, unsigned int num_menu_items, con do { // return cursor to menu top position if (hovered_item_changed) { for (unsigned int i = 0; i < num_menu_items; i++) { printf("\033[A"); // move cursor up one line printf("\033[2K"); // clear entire line } clear_lines(num_menu_items); // print menu items, showing selection for (unsigned int i = 0; i < num_menu_items; i++) { Loading Loading @@ -146,6 +152,7 @@ void menu_prompt_multi_select(menu_item *items, unsigned int num_menu_items, con printf("\033[A"); // move cursor up one line printf("\033[2K"); // clear entire line } printf("\r"); // move cursor to beginning of line (probably unnecessary) } MENU_DIRECTION get_direction(void) { Loading