Class: Curses::Form

Inherits:
Object
  • Object
show all
Defined in:
ext/curses/curses.c

Instance Method Summary collapse

Constructor Details

#initialize(fields) ⇒ Object

call-seq:

new(fields)

Construct a new Curses::Form.



4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
# File 'ext/curses/curses.c', line 4361

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;
}

Instance Method Details

#driver(command) ⇒ Object

call-seq:

driver(command)

Perform the command on the form.



4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
# File 'ext/curses/curses.c', line 4443

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;
}

#postObject

call-seq:

post

Post the form.



4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
# File 'ext/curses/curses.c', line 4401

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;
}

#scaleObject

call-seq:

scale

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



4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
# File 'ext/curses/curses.c', line 4520

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) ⇒ Object

call-seq:

set_sub=(win)

Set the subwindow of the form.



4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
# File 'ext/curses/curses.c', line 4500

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) ⇒ Object

call-seq:

set_win=(win)

Set the window of the form.



4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
# File 'ext/curses/curses.c', line 4480

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;
}

#unpostObject

call-seq:

unpost

Unpost the form.



4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
# File 'ext/curses/curses.c', line 4422

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;
}