void menu_prev(menu_t *menu) { menupage_t *page = menu->current_page; if (page->sibilings) { if (menu->current_posn == 0) menu->current_posn = menu->pages.size - 1; else menu->current_posn--; menu_return(menu); } }
void menu_next(menu_t *menu) { menupage_t *page = menu->current_page; if (page->sibilings) { if (menu->current_posn == menu->pages.size - 1) menu->current_posn = 0; else menu->current_posn++; menu_return(menu); } }
struct menu *menu_return(struct menu *menu) { if (menu->child) return menu_return(menu->child); struct menu *parent = menu->parent; if (!parent || parent->child != menu) return NULL; menu_signal_leave(menu, MENU_SWITCH_RETURN); menu->parent = NULL; parent->child = NULL; menu_signal_enter(parent, MENU_SWITCH_RETURN); return parent; }
static int import_callback(const char *path, void *data) { /* initialize watchfile data */ watchfile_list_data = data; vector_init(&watchfile_entries, sizeof(struct watchfile_entry)); /* parse lines */ const char *err_str = NULL; FILE *f = fopen(path, "r"); char *line = malloc(1024); if (f) { while (1) { if (fgets(line, 1024, f)) { if (strchr(line, '\n') || feof(f)) { if (!parse_line(line, &err_str)) break; } else { err_str = "line overflow"; break; } } else { if (!feof(f)) err_str = strerror(ferror(f)); break; } } } else err_str = strerror(errno); if (f) fclose(f); if (line) free(line); /* show error message or view file */ struct menu *menu_top = menu_get_top(watchfile_list_data->imenu); if (err_str) { watchfile_destroy(); menu_prompt(menu_top, err_str, "return\0", 0, NULL, NULL); } else { menu_return(menu_top); watchfile_view(menu_top); } return 1; }
void menu_initialize() { menu_return(current_menu); status.menu_running = true; }
void menu_telemetry_toggle(void) { telemetry.enabled^=1; menu_return();//immediately return to menu after toggling }
struct menu *menu_return_top(struct menu *menu) { if (menu->parent) return menu_return_top(menu->parent); return menu_return(menu); }