Hobocamp

 view release on metacpan or  search on metacpan

Dialog.xs  view on Meta::CPAN

    SV **name_key = hv_fetch((HV *)SvRV(*name_hash), key, strlen(key), NULL);

    if (!name_key) {
        croak("item from hv_fetch is NULL");
    }

    return *name_key;
}

MODULE = Hobocamp::Dialog        PACKAGE = Hobocamp::Dialog

INCLUDE: const-xs.inc

# -------- util --------

void
init(in = stdin, out = stderr)
    FILE *in
    FILE *out
    PROTOTYPE: $$
    CODE:
        init_dialog(in, out);

void
end_dialog();

void
destroy()
    PROTOTYPE:
    CODE:
        end_dialog();

void
dlg_put_backtitle()

void
dlg_clr_result()

const char *
dialog_version()

void
dlg_clear()

void
_set_ascii_lines_state(int state = 1)
     PROTOTYPE: $
     CODE:
         if (state) {
             dialog_vars.ascii_lines = TRUE;
             dialog_vars.no_lines = FALSE;
         }
         else {
             dialog_vars.ascii_lines = FALSE;
             dialog_vars.no_lines = TRUE;
        }

# -------- widgets --------

int
dialog_calendar(const char *title, const char *subtitle, int height, int width, int day = 1, int month = 1, int year = 1970)

int
dialog_checklist(title, prompt, height, width, list_height = 1, items_list, checklist_or_radio_flag = 1)
    const char *title
    const char *prompt
    int height
    int width
    int list_height
    SV *items_list
    int checklist_or_radio_flag
    PROTOTYPE: $$$$$$$
    PREINIT:
        I32 i;
        I32 items_amount = 0;
        int current_item = 0;
        DIALOG_LISTITEM *listitems;
        int dialog_return_code;
    INIT:
        items_amount = av_len((AV *)SvRV(items_list)) + 1;
    PPCODE:
        listitems = dlg_calloc(DIALOG_LISTITEM, (size_t) items_amount);

        for (i = 0; i < items_amount; i++) {
            listitems[i].name = SvPV_nolen(_get_hash_key_sv_from_array(items_list, i, "name"));
            listitems[i].text = SvPV_nolen(_get_hash_key_sv_from_array(items_list, i, "text"));

            if (dialog_vars.item_help) {
                listitems[i].help = SvPV_nolen(_get_hash_key_sv_from_array(items_list, i, "help"));
            }
            else {
                listitems[i].help = dlg_strempty();
            }
            listitems[i].state = hv_exists((HV *)SvRV(*av_fetch((AV *)SvRV(items_list), i, 0)),
                                           "on",
                                           strlen("on")) ? 1 : 0;
        }

        dlg_align_columns(&listitems[0].text, sizeof(DIALOG_LISTITEM), items_amount);

	dialog_return_code = dlg_checklist(title,
                                           prompt,
                                           height,
                                           width,
                                           list_height,
                                           items_amount,
                                           listitems,
                                           NULL,
                                           checklist_or_radio_flag,
                                           &current_item);


        dlg_free_columns(&listitems[0].text, sizeof(DIALOG_LISTITEM), items_amount);
        free(listitems);

        if (G_ARRAY) {
            mXPUSHi(dialog_return_code);
            for (i = 0; i < items_amount; i++) {
                if (listitems[i].state) {
                    mXPUSHi(i);
                }



( run in 1.757 second using v1.01-cache-2.11-cpan-99c4e6809bf )