Class: Curses::Menu

Inherits:
Data
  • Object
show all
Defined in:
ext/curses/curses.c,
lib/curses.rb

Instance Method Summary collapse

Constructor Details

#initialize(items) ⇒ Object

call-seq:

new(name, description)

Construct a new Curses::Menu.



3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
# File 'ext/curses/curses.c', line 3212

static VALUE
menu_initialize(VALUE obj, VALUE items)
{
    struct menudata *menup;
    ITEM **menu_items;
    int i;

    Check_Type(items, T_ARRAY);
    curses_init_screen();
    TypedData_Get_Struct(obj, struct menudata, &menudata_type, menup);
    if (menup->menu) {
	rb_raise(rb_eRuntimeError, "already initialized menu");
    }
    menu_items = ALLOC_N(ITEM *, RARRAY_LEN(items) + 1);
    for (i = 0; i < RARRAY_LEN(items); i++) {
	struct itemdata *itemp;

	GetITEM(RARRAY_AREF(items, i), itemp);
	menu_items[i] = itemp->item;
    }
    menu_items[RARRAY_LEN(items)] = NULL;
    menup->menu = new_menu(menu_items);
    if (menup->menu == NULL) {
	check_curses_error(errno);
    }
    menup->items = rb_ary_dup(items);

    return obj;
}

Instance Method Details

#back_patternObject



83
84
85
# File 'lib/curses.rb', line 83

def back_pattern
  driver(Curses::REQ_BACK_PATTERN)
end

#clear_patternObject



79
80
81
# File 'lib/curses.rb', line 79

def clear_pattern
  driver(Curses::REQ_CLEAR_PATTERN)
end

#current_itemObject

call-seq:

current_item

Returns the current item.



3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
# File 'ext/curses/curses.c', line 3395

static VALUE
menu_get_current_item(VALUE obj)
{
    struct menudata *menup;
    ITEM *item;

    GetMENU(obj, menup);
    item = current_item(menup->menu);
    if (item == NULL) {
	return Qnil;
    }
    return item_new(item);
}

#current_item=(item) ⇒ Object

call-seq:

current_item=(item)

Sets the current item.



3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
# File 'ext/curses/curses.c', line 3417

static VALUE
menu_set_current_item(VALUE obj, VALUE item)
{
    struct menudata *menup;
    struct itemdata *itemp;

    GetMENU(obj, menup);
    GetITEM(item, itemp);
    set_current_item(menup->menu, itemp->item);
    return item;
}

#down_itemObject



39
40
41
# File 'lib/curses.rb', line 39

def down_item
  driver(Curses::REQ_DOWN_ITEM)
end

#driver(command) ⇒ Object

call-seq:

driver(command)

Perform the command on the menu.



3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
# File 'ext/curses/curses.c', line 3292

static VALUE
menu_driver_m(VALUE obj, VALUE command)
{
    struct menudata *menup;
    int error;

    GetMENU(obj, menup);
    error = menu_driver(menup->menu, NUM2INT(command));
    check_curses_error(error);

    return obj;
}

#first_itemObject



59
60
61
# File 'lib/curses.rb', line 59

def first_item
  driver(Curses::REQ_FIRST_ITEM)
end

#item_countObject

call-seq:

item_count

Returns the count of items in the menu.



3313
3314
3315
3316
3317
3318
3319
3320
# File 'ext/curses/curses.c', line 3313

static VALUE
menu_item_count(VALUE obj)
{
    struct menudata *menup;

    GetMENU(obj, menup);
    return INT2NUM(item_count(menup->menu));
}

#itemsObject

call-seq:

items

Returns the items of the menu.



3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
# File 'ext/curses/curses.c', line 3330

static VALUE
menu_get_items(VALUE obj)
{
    struct menudata *menup;
    ITEM **items;
    int count, i;
    VALUE ary;

    GetMENU(obj, menup);
    items = menu_items(menup->menu);
    if (items == NULL) {
	return Qnil;
    }
    count = item_count(menup->menu);
    ary = rb_ary_new();
    for (i = 0; i < count; i++) {
	rb_ary_push(ary, item_new(items[i]));
    }
    return ary;
}

#items=(items) ⇒ Object

call-seq:

items=(items)

Returns the items of the menu.



3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
# File 'ext/curses/curses.c', line 3359

static VALUE
menu_set_items(VALUE obj, VALUE items)
{
    struct menudata *menup;
    ITEM **old_items, **new_items;
    int i, error;

    Check_Type(items, T_ARRAY);
    GetMENU(obj, menup);
    old_items = menu_items(menup->menu);
    new_items = ALLOC_N(ITEM*, RARRAY_LEN(items) + 1);
    for (i = 0; i < RARRAY_LEN(items); i++) {
	struct itemdata *itemp;
	GetITEM(RARRAY_AREF(items, i), itemp);
	new_items[i] = itemp->item;
    }
    new_items[RARRAY_LEN(items)] = NULL;
    error = set_menu_items(menup->menu, new_items);
    if (error != E_OK) {
	xfree(new_items);
	check_curses_error(error);
	return items;
    }
    xfree(old_items);
    menup->items = rb_ary_dup(items);
    return items;
}

#last_itemObject



63
64
65
# File 'lib/curses.rb', line 63

def last_item
  driver(Curses::REQ_LAST_ITEM)
end

#left_itemObject



27
28
29
# File 'lib/curses.rb', line 27

def left_item
  driver(Curses::REQ_LEFT_ITEM)
end

#next_itemObject



67
68
69
# File 'lib/curses.rb', line 67

def next_item
  driver(Curses::REQ_NEXT_ITEM)
end

#next_matchObject



87
88
89
# File 'lib/curses.rb', line 87

def next_match
  driver(Curses::REQ_NEXT_MATCH)
end

#postObject

call-seq:

post

Post the menu.



3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
# File 'ext/curses/curses.c', line 3250

static VALUE
menu_post(VALUE obj)
{
    struct menudata *menup;
    int error;

    GetMENU(obj, menup);
    error = post_menu(menup->menu);
    check_curses_error(error);

    return obj;
}

#prev_itemObject



71
72
73
# File 'lib/curses.rb', line 71

def prev_item
  driver(Curses::REQ_PREV_ITEM)
end

#prev_matchObject



91
92
93
# File 'lib/curses.rb', line 91

def prev_match
  driver(Curses::REQ_PREV_MATCH)
end

#right_itemObject



31
32
33
# File 'lib/curses.rb', line 31

def right_item
  driver(Curses::REQ_RIGHT_ITEM)
end

#scroll_down_lineObject



47
48
49
# File 'lib/curses.rb', line 47

def scroll_down_line
  driver(Curses::REQ_SCR_DLINE)
end

#scroll_down_pageObject



55
56
57
# File 'lib/curses.rb', line 55

def scroll_down_page
  driver(Curses::REQ_SCR_DPAGE)
end

#scroll_up_lineObject



43
44
45
# File 'lib/curses.rb', line 43

def scroll_up_line
  driver(Curses::REQ_SCR_ULINE)
end

#scroll_up_pageObject



51
52
53
# File 'lib/curses.rb', line 51

def scroll_up_page
  driver(Curses::REQ_SCR_UPAGE)
end

#toggle_itemObject



75
76
77
# File 'lib/curses.rb', line 75

def toggle_item
  driver(Curses::REQ_TOGGLE_ITEM)
end

#unpostObject

call-seq:

unpost

Unpost the menu.



3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
# File 'ext/curses/curses.c', line 3271

static VALUE
menu_unpost(VALUE obj)
{
    struct menudata *menup;
    int error;

    GetMENU(obj, menup);
    error = unpost_menu(menup->menu);
    check_curses_error(error);

    return obj;
}

#up_itemObject



35
36
37
# File 'lib/curses.rb', line 35

def up_item
  driver(Curses::REQ_UP_ITEM)
end