Commit 4c9edc20 authored by Chris's avatar Chris
Browse files

refactor for clear lines logic

parent 22ebd816
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -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");
@@ -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++) {
@@ -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) {