class Curses::Form

Public Class Methods

new(fields) click to toggle source

Construct a new Curses::Form.

static VALUE
form_initialize(VALUE obj, VALUE fields)
{
    struct formdata *formp;
    FIELD **form_fields;
    int i;

    Check_Type(fields, T_ARRAY);
    curses_init_screen(Qnil);
    TypedData_Get_Struct(obj, struct formdata, &formdata_type, formp);
    if (formp->form) {
        rb_raise(rb_eRuntimeError, "already initialized form");
    }
    formp->fields = rb_ary_new();
    form_fields = ALLOC_N(FIELD *, RARRAY_LEN(fields) + 1);
    for (i = 0; i < RARRAY_LEN(fields); i++) {
        VALUE field = RARRAY_AREF(fields, i);
        struct fielddata *fieldp;

        GetFIELD(field, fieldp);
        form_fields[i] = fieldp->field;
        rb_ary_push(formp->fields, field);
    }
    form_fields[RARRAY_LEN(fields)] = NULL;
    formp->form = new_form(form_fields);
    if (formp->form == NULL) {
        check_curses_error(errno);
    }

    return obj;
}

Public Instance Methods

driver(command) click to toggle source

Perform the command on the form.

static VALUE
form_driver_m(VALUE obj, VALUE command)
{
    struct formdata *formp;
    int error, c;

    GetFORM(obj, formp);
    if (FIXNUM_P(command)) {
        c = NUM2INT(command);
    }
    else {
        ID id_ord;

        StringValue(command);
        CONST_ID(id_ord, "ord");
        c = NUM2INT(rb_funcall(command, id_ord, 0));
    }
#ifdef HAVE_FORM_DRIVER_W
    error = form_driver_w(formp->form,
                          FIXNUM_P(command) ? KEY_CODE_YES : OK,
                          c);
#else
    error = form_driver(formp->form, c);
#endif
    check_curses_error(error);

    return obj;
}
post click to toggle source

Post the form.

static VALUE
form_post(VALUE obj)
{
    struct formdata *formp;
    int error;

    GetFORM(obj, formp);
    error = post_form(formp->form);
    check_curses_error(error);

    return obj;
}
scale click to toggle source

Return the minimum rows and columns required for the subwindow of the form.

static VALUE
form_scale(VALUE obj)
{
    struct formdata *formp;
    int error, rows, columns;

    GetFORM(obj, formp);
    error = scale_form(formp->form, &rows, &columns);
    check_curses_error(error);
    return rb_assoc_new(INT2NUM(rows), INT2NUM(columns));
}
set_sub=(win) click to toggle source

Set the subwindow of the form.

static VALUE
form_set_sub(VALUE obj, VALUE win)
{
    struct formdata *formp;
    struct windata *winp;

    GetFORM(obj, formp);
    GetWINDOW(win, winp);
    set_form_sub(formp->form, winp->window);
    return win;
}
set_win=(win) click to toggle source

Set the window of the form.

static VALUE
form_set_win(VALUE obj, VALUE win)
{
    struct formdata *formp;
    struct windata *winp;

    GetFORM(obj, formp);
    GetWINDOW(win, winp);
    set_form_win(formp->form, winp->window);
    return win;
}
unpost click to toggle source

Unpost the form.

static VALUE
form_unpost(VALUE obj)
{
    struct formdata *formp;
    int error;

    GetFORM(obj, formp);
    error = unpost_form(formp->form);
    check_curses_error(error);

    return obj;
}