int ui_browser__show(struct ui_browser *self, const char *title, const char *helpline, ...) { va_list ap; if (self->form != NULL) { newtFormDestroy(self->form); newtPopWindow(); } ui_browser__refresh_dimensions(self); newtCenteredWindow(self->width, self->height, title); self->form = newt_form__new(); if (self->form == NULL) return -1; self->sb = newtVerticalScrollbar(self->width, 0, self->height, HE_COLORSET_NORMAL, HE_COLORSET_SELECTED); if (self->sb == NULL) return -1; newtFormAddHotKey(self->form, NEWT_KEY_UP); newtFormAddHotKey(self->form, NEWT_KEY_DOWN); newtFormAddHotKey(self->form, NEWT_KEY_PGUP); newtFormAddHotKey(self->form, NEWT_KEY_PGDN); newtFormAddHotKey(self->form, NEWT_KEY_HOME); newtFormAddHotKey(self->form, NEWT_KEY_END); newtFormAddHotKey(self->form, ' '); newtFormAddComponent(self->form, self->sb); va_start(ap, helpline); ui_helpline__vpush(helpline, ap); va_end(ap); return 0; }
int ui__popup_menu(int argc, char * const argv[]) { struct newtExitStruct es; int i, rc = -1, max_len = 5; newtComponent listbox, form = newt_form__new(); if (form == NULL) return -1; listbox = newtListbox(0, 0, argc, NEWT_FLAG_RETURNEXIT); if (listbox == NULL) goto out_destroy_form; newtFormAddComponent(form, listbox); for (i = 0; i < argc; ++i) { int len = strlen(argv[i]); if (len > max_len) max_len = len; if (newtListboxAddEntry(listbox, argv[i], (void *)(long)i)) goto out_destroy_form; } newtCenteredWindow(max_len, argc, NULL); newtFormRun(form, &es); rc = newtListboxGetCurrent(listbox) - NULL; if (es.reason == NEWT_EXIT_HOTKEY) rc = -1; newtPopWindow(); out_destroy_form: newtFormDestroy(form); return rc; }
int ui__help_window(const char *text) { struct newtExitStruct es; newtComponent tb, form = newt_form__new(); int rc = -1; int max_len = 0, nr_lines = 0; const char *t; if (form == NULL) return -1; t = text; while (1) { const char *sep = strchr(t, '\n'); int len; if (sep == NULL) sep = strchr(t, '\0'); len = sep - t; if (max_len < len) max_len = len; ++nr_lines; if (*sep == '\0') break; t = sep + 1; } tb = newtTextbox(0, 0, max_len, nr_lines, 0); if (tb == NULL) goto out_destroy_form; newtTextboxSetText(tb, text); newtFormAddComponent(form, tb); newtCenteredWindow(max_len, nr_lines, NULL); newtFormRun(form, &es); newtPopWindow(); rc = 0; out_destroy_form: newtFormDestroy(form); return rc; }