Module: Curses

Defined in:
ext/curses/curses.c,
ext/curses/curses.c

Overview

Description

An implementation of the CRT screen handling and optimization library.

Structures and such

Classes

  • Curses::Window - class with the means to draw a window or box

  • Curses::MouseEvent - class for collecting mouse events

Modules

Curses

The curses implementation

Curses::Key

Collection of constants for keypress events

Examples

  • hello.rb

    :include: ../../sample/hello.rb
    
  • rain.rb

    :include: ../../sample/rain.rb
    

Defined Under Namespace

Modules: Key Classes: Error, Field, Form, Item, Menu, MouseEvent, Pad, Window

Constant Summary collapse

VERSION =

Identifies curses library version.

  • “ncurses 5.9.20110404”

  • “PDCurses 3.4 - Public Domain 2008”

  • “curses (SVR4)” (System V curses)

  • “curses (unknown)” (The original BSD curses? NetBSD maybe.)

version
TYPE_ALPHA =
INT2NUM(TYPE_CODE_ALPHA)
TYPE_ALNUM =
INT2NUM(TYPE_CODE_ALNUM)
TYPE_ENUM =
INT2NUM(TYPE_CODE_ENUM)
TYPE_INTEGER =
INT2NUM(TYPE_CODE_INTEGER)
TYPE_NUMERIC =
INT2NUM(TYPE_CODE_NUMERIC)
TYPE_REGEXP =
INT2NUM(TYPE_CODE_REGEXP)

Class Method Summary collapse

Class Method Details

.addch(ch) ⇒ Object

Add a character ch, with attributes, then advance the cursor.

see also the system manual for curs_addch(3)



786
787
788
789
790
791
792
# File 'ext/curses/curses.c', line 786

static VALUE
curses_addch(VALUE obj, VALUE ch)
{
    curses_stdscr();
    addch(OBJ2CHTYPE(ch));
    return Qnil;
}

.addstr(str) ⇒ Object

add a string of characters str, to the window and advance cursor



816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
# File 'ext/curses/curses.c', line 816

static VALUE
curses_addstr(VALUE obj, VALUE str)
{
    StringValue(str);
#if defined(HAVE_ADDNWSTR) && defined(_WIN32)
    str = rb_str_export_to_enc(str, get_wide_encoding());
    curses_stdscr();
    if (!NIL_P(str)) {
	addnwstr((wchar_t *)RSTRING_PTR(str), RSTRING_LEN(str) / sizeof(wchar_t));
    }
#else
    str = rb_str_export_to_enc(str, terminal_encoding);
    curses_stdscr();
    if (!NIL_P(str)) {
	addstr(StringValueCStr(str));
    }
#endif
    return Qnil;
}

.assume_default_colors(fg, bg) ⇒ Object

tells which colors to paint for color pair 0.

see also the system manual for default_colors(3)



1184
1185
1186
1187
1188
1189
1190
# File 'ext/curses/curses.c', line 1184

static VALUE
curses_assume_default_colors(VALUE obj, VALUE fg, VALUE bg)
{
    curses_stdscr();
    assume_default_colors(NUM2INT(fg), NUM2INT(bg));
    return Qnil;
}

.attroff(attrs) ⇒ Object

Turns off the named attributes attrs without affecting any others.

See also Curses::Window.attrset for additional information.



1074
1075
1076
1077
1078
1079
1080
# File 'ext/curses/curses.c', line 1074

static VALUE
curses_attroff(VALUE obj, VALUE attrs)
{
    curses_stdscr();
    return window_attroff(rb_stdscr,attrs);
    /* return INT2FIX(attroff(NUM2INT(attrs))); */
}

.attron(attrs) ⇒ Object

Turns on the named attributes attrs without turning any other attributes on or off.

See also Curses::Window.attrset for additional information.



1091
1092
1093
1094
1095
1096
1097
# File 'ext/curses/curses.c', line 1091

static VALUE
curses_attron(VALUE obj, VALUE attrs)
{
    curses_stdscr();
    return window_attron(rb_stdscr,attrs);
    /* return INT2FIX(attroff(NUM2INT(attrs))); */
}

.attrset(attrs) ⇒ Object

Sets the current attributes of the given window to attrs.

see also Curses::Window.attrset



1108
1109
1110
1111
1112
1113
1114
# File 'ext/curses/curses.c', line 1108

static VALUE
curses_attrset(VALUE obj, VALUE attrs)
{
    curses_stdscr();
    return window_attrset(rb_stdscr,attrs);
    /* return INT2FIX(attroff(NUM2INT(attrs))); */
}

.beepObject

Sounds an audible alarm on the terminal, if possible; otherwise it flashes the screen (visual bell).

see also Curses.flash



645
646
647
648
649
650
651
652
653
# File 'ext/curses/curses.c', line 645

static VALUE
curses_beep(VALUE obj)
{
#ifdef HAVE_BEEP
    curses_stdscr();
    beep();
#endif
    return Qnil;
}

.bkgd(ch) ⇒ Object

Window background manipulation routines.

Set the background property of the current and then apply the character Integer ch setting to every character position in that window.

see also the system manual for curs_bkgd(3)



1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
# File 'ext/curses/curses.c', line 1150

static VALUE
curses_bkgd(VALUE obj, VALUE ch)
{
#ifdef HAVE_BKGD
    curses_stdscr();
    return (bkgd(OBJ2CHTYPE(ch)) == OK) ? Qtrue : Qfalse;
#else
    return Qfalse;
#endif
}

.bkgdset(ch) ⇒ Object

Manipulate the background of the named window with character Integer ch

The background becomes a property of the character and moves with the character through any scrolling and insert/delete line/character operations.

see also the system manual for curs_bkgd(3)



1129
1130
1131
1132
1133
1134
1135
1136
1137
# File 'ext/curses/curses.c', line 1129

static VALUE
curses_bkgdset(VALUE obj, VALUE ch)
{
#ifdef HAVE_BKGDSET
    curses_stdscr();
    bkgdset(OBJ2CHTYPE(ch));
#endif
    return Qnil;
}

.can_change_color?Boolean

Returns true or false depending on whether the terminal can change color attributes

Returns:

  • (Boolean)


1362
1363
1364
1365
1366
1367
# File 'ext/curses/curses.c', line 1362

static VALUE
curses_can_change_color(VALUE obj)
{
    curses_stdscr();
    return can_change_color() ? Qtrue : Qfalse;
}

.cbreakObject

Put the terminal into cbreak mode.

Normally, the tty driver buffers typed characters until a newline or carriage return is typed. The Curses.cbreak routine disables line buffering and erase/kill character-processing (interrupt and flow control characters are unaffected), making characters typed by the user immediately available to the program.

The Curses.nocbreak routine returns the terminal to normal (cooked) mode.

Initially the terminal may or may not be in cbreak mode, as the mode is inherited; therefore, a program should call Curses.cbreak or Curses.nocbreak explicitly. Most interactive programs using curses set the cbreak mode. Note that Curses.cbreak overrides Curses.raw.

see also Curses.raw



562
563
564
565
566
567
568
# File 'ext/curses/curses.c', line 562

static VALUE
curses_cbreak(VALUE obj)
{
    curses_stdscr();
    cbreak();
    return Qnil;
}

.clearObject

Clears every position on the screen completely, so that a subsequent call by Curses.refresh for the screen/window will be repainted from scratch.



403
404
405
406
407
408
409
# File 'ext/curses/curses.c', line 403

static VALUE
curses_clear(VALUE obj)
{
    curses_stdscr();
    wclear(stdscr);
    return Qnil;
}

.close_screenObject

A program should always call Curses.close_screen before exiting or escaping from curses mode temporarily. This routine restores tty modes, moves the cursor to the lower left-hand corner of the screen and resets the terminal into the proper non-visual mode.

Calling Curses.refresh or Curses.doupdate after a temporary escape causes the program to resume visual mode.



343
344
345
346
347
348
349
350
351
352
353
# File 'ext/curses/curses.c', line 343

static VALUE
curses_close_screen(VALUE self)
{
    curses_stdscr();
#ifdef HAVE_ISENDWIN
    if (!isendwin())
#endif
	endwin();
    rb_stdscr = 0;
    return Qnil;
}

.closed?Boolean

Returns true if the window/screen has been closed, without any subsequent Curses.refresh calls, returns false otherwise.

Returns:

  • (Boolean)


383
384
385
386
387
388
389
390
391
# File 'ext/curses/curses.c', line 383

static VALUE
curses_closed(VALUE self)
{
    curses_stdscr();
    if (isendwin()) {
	return Qtrue;
    }
    return Qfalse;
}

.clrtoeolObject

Clears to the end of line, that the cursor is currently on.



433
434
435
436
437
438
439
# File 'ext/curses/curses.c', line 433

static VALUE
curses_clrtoeol(VALUE self)
{
    curses_stdscr();
    clrtoeol();
    return Qnil;
}

.color_content(color) ⇒ Object

Returns an 3 item Array of the RGB values in color



1390
1391
1392
1393
1394
1395
1396
1397
1398
# File 'ext/curses/curses.c', line 1390

static VALUE
curses_color_content(VALUE obj, VALUE color)
{
    short r,g,b;

    curses_stdscr();
    color_content(NUM2INT(color),&r,&g,&b);
    return rb_ary_new3(3,INT2FIX(r),INT2FIX(g),INT2FIX(b));
}

.color_pair(attrs) ⇒ Object

Sets the color pair attributes to attrs.

This should be equivalent to Curses.attrset(COLOR_PAIR(attrs))

TODO: validate that equivalency



1443
1444
1445
1446
1447
# File 'ext/curses/curses.c', line 1443

static VALUE
curses_color_pair(VALUE obj, VALUE attrs)
{
    return INT2FIX(COLOR_PAIR(NUM2INT(attrs)));
}

.color_pairsObject

Returns the COLOR_PAIRS available, if the curses library supports it.



1407
1408
1409
1410
1411
# File 'ext/curses/curses.c', line 1407

static VALUE
curses_color_pairs(VALUE obj)
{
    return INT2FIX(COLOR_PAIRS);
}

.colorsObject

returns COLORS



1375
1376
1377
1378
1379
# File 'ext/curses/curses.c', line 1375

static VALUE
curses_colors(VALUE obj)
{
    return INT2FIX(COLORS);
}

.colsObject

Returns the number of columns on the screen



987
988
989
990
991
# File 'ext/curses/curses.c', line 987

static VALUE
curses_cols(VALUE self)
{
    return INT2FIX(COLS);
}

.crmodeObject

Put the terminal into cbreak mode.

Normally, the tty driver buffers typed characters until a newline or carriage return is typed. The Curses.cbreak routine disables line buffering and erase/kill character-processing (interrupt and flow control characters are unaffected), making characters typed by the user immediately available to the program.

The Curses.nocbreak routine returns the terminal to normal (cooked) mode.

Initially the terminal may or may not be in cbreak mode, as the mode is inherited; therefore, a program should call Curses.cbreak or Curses.nocbreak explicitly. Most interactive programs using curses set the cbreak mode. Note that Curses.cbreak overrides Curses.raw.

see also Curses.raw



562
563
564
565
566
567
568
# File 'ext/curses/curses.c', line 562

static VALUE
curses_cbreak(VALUE obj)
{
    curses_stdscr();
    cbreak();
    return Qnil;
}

.curs_set(visibility) ⇒ Object

Sets Cursor Visibility. 0: invisible 1: visible 2: very visible



1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
# File 'ext/curses/curses.c', line 1002

static VALUE
curses_curs_set(VALUE obj, VALUE visibility)
{
#ifdef HAVE_CURS_SET
    int n;
    curses_stdscr();
    return (n = curs_set(NUM2INT(visibility)) != ERR) ? INT2FIX(n) : Qnil;
#else
    return Qnil;
#endif
}

.def_prog_modeObject

Save the current terminal modes as the “program” state for use by the Curses.reset_prog_mode

This is done automatically by Curses.init_screen



1657
1658
1659
1660
1661
1662
# File 'ext/curses/curses.c', line 1657

static VALUE
curses_def_prog_mode(VALUE obj)
{
    curses_stdscr();
    return def_prog_mode() == OK ? Qtrue : Qfalse;
}

.delchObject

Delete the character under the cursor



905
906
907
908
909
910
911
# File 'ext/curses/curses.c', line 905

static VALUE
curses_delch(VALUE obj)
{
    curses_stdscr();
    delch();
    return Qnil;
}

.deletelnObject

Delete the line under the cursor.



919
920
921
922
923
924
925
926
927
# File 'ext/curses/curses.c', line 919

static VALUE
curses_deleteln(VALUE obj)
{
    curses_stdscr();
#if defined(HAVE_DELETELN) || defined(deleteln)
    deleteln();
#endif
    return Qnil;
}

.doupdateObject

Refreshes the windows and lines.

Curses.doupdate allows multiple updates with more efficiency than Curses.refresh alone.



463
464
465
466
467
468
469
470
471
472
473
# File 'ext/curses/curses.c', line 463

static VALUE
curses_doupdate(VALUE obj)
{
    curses_stdscr();
#ifdef HAVE_DOUPDATE
    doupdate();
#else
    refresh();
#endif
    return Qnil;
}

.echoObject

Enables characters typed by the user to be echoed by Curses.getch as they are typed.



481
482
483
484
485
486
487
# File 'ext/curses/curses.c', line 481

static VALUE
curses_echo(VALUE obj)
{
    curses_stdscr();
    echo();
    return Qnil;
}

.eraseObject

Erase the screen.



417
418
419
420
421
422
423
# File 'ext/curses/curses.c', line 417

static VALUE
curses_erase(VALUE obj)
{
    curses_stdscr();
    werase(stdscr);
    return Qnil;
}

.ESCDELAYObject

Returns the total time, in milliseconds, for which curses will await a character sequence, e.g., a function key



1246
1247
1248
1249
1250
# File 'ext/curses/curses.c', line 1246

static VALUE
curses_escdelay_get(VALUE obj)
{
    return INT2NUM(ESCDELAY);
}

.ESCDELAY=(value) ⇒ Object

Sets the ESCDELAY to Integer value



1231
1232
1233
1234
1235
1236
# File 'ext/curses/curses.c', line 1231

static VALUE
curses_escdelay_set(VALUE obj, VALUE val)
{
    ESCDELAY = NUM2INT(val);
    return INT2NUM(ESCDELAY);
}

.flashObject

Flashes the screen, for visual alarm on the terminal, if possible; otherwise it sounds the alert.

see also Curses.beep



663
664
665
666
667
668
669
670
671
# File 'ext/curses/curses.c', line 663

static VALUE
curses_flash(VALUE obj)
{
#ifdef HAVE_FLASH
    curses_stdscr();
    flash();
#endif
    return Qnil;
}

.flushinpObject

The flushinp routine throws away any typeahead that has been typed by the user and has not yet been read by the program.



629
630
631
632
633
634
635
# File 'ext/curses/curses.c', line 629

static VALUE
curses_flushinp(VALUE obj)
{
    curses_stdscr();
    flushinp();
    return Qnil;
}

.get_charObject

Read and returns a character or function key from the window. A single or multibyte character is represented by a String, and a function key is represented by an Integer. Returns nil if no input is ready.

See Curses::Key to all the function KEY_* available



4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
# File 'ext/curses/curses.c', line 4664

static VALUE
curses_get_char(VALUE obj)
{
#ifdef HAVE_GET_WCH
    struct get_wch_arg arg;

    curses_stdscr();
    rb_thread_call_without_gvl(get_wch_func, &arg, RUBY_UBF_IO, 0);
    switch (arg.retval) {
    case OK:
	return keyboard_uint_chr(arg.ch);
    case KEY_CODE_YES:
	return key_code_value(arg.ch);
    }
    return Qnil;
#else
    int c;

    curses_stdscr();
    rb_thread_call_without_gvl(getch_func, &c, RUBY_UBF_IO, 0);
    if (c > 0xff) {
	return INT2NUM(c);
    }
    else if (c >= 0) {
	return keyboard_uint_chr(c);
    }
    else {
	return Qnil;
    }
#endif
}

.get_key_modifiersObject



4761
4762
4763
4764
4765
# File 'ext/curses/curses.c', line 4761

static VALUE
curses_get_key_modifiers(VALUE obj)
{
    return ULONG2NUM(PDC_get_key_modifiers());
}

.getchObject

Read and returns a character from the window.

See Curses::Key to all the function KEY_* available



852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
# File 'ext/curses/curses.c', line 852

static VALUE
curses_getch(VALUE obj)
{
    int c;

    curses_stdscr();
    rb_thread_call_without_gvl(getch_func, &c, RUBY_UBF_IO, 0);
    if (c == EOF) return Qnil;
    if (rb_isprint(c)) {
	char ch = (char)c;

	return rb_external_str_new_with_enc(&ch, 1, keyboard_encoding);
    }
    return UINT2NUM(c);
}

.getmouseObject

Returns coordinates of the mouse.

This will read and pop the mouse event data off the queue

See the BUTTON*, ALL_MOUSE_EVENTS and REPORT_MOUSE_POSITION constants, to examine the mask of the event



1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
# File 'ext/curses/curses.c', line 1512

static VALUE
curses_getmouse(VALUE obj)
{
    struct mousedata *mdata;
    VALUE val;

    curses_stdscr();
    val = TypedData_Make_Struct(cMouseEvent,struct mousedata,
				&mousedata_type,mdata);
    mdata->mevent = (MEVENT*)xmalloc(sizeof(MEVENT));
    return (getmouse(mdata->mevent) == OK) ? val : Qnil;
}

.getstrObject

This is equivalent to a series of Curses::Window.getch calls



889
890
891
892
893
894
895
896
897
# File 'ext/curses/curses.c', line 889

static VALUE
curses_getstr(VALUE obj)
{
    char rtn[GETSTR_BUF_SIZE];

    curses_stdscr();
    rb_thread_call_without_gvl(getstr_func, rtn, RUBY_UBF_IO, 0);
    return rb_external_str_new_with_enc(rtn, strlen(rtn), keyboard_encoding);
}

.has_colors?Boolean

Returns true or false depending on whether the terminal has color capabilities.

Returns:

  • (Boolean)


1350
1351
1352
1353
1354
1355
# File 'ext/curses/curses.c', line 1350

static VALUE
curses_has_colors(VALUE obj)
{
    curses_stdscr();
    return has_colors() ? Qtrue : Qfalse;
}

.inchObject

Returns the character at the current position.



771
772
773
774
775
776
# File 'ext/curses/curses.c', line 771

static VALUE
curses_inch(VALUE obj)
{
    curses_stdscr();
    return CHTYPE2NUM(inch());
}

.init_color(color, r, g, b) ⇒ Object

Changes the definition of a color. It takes four arguments:

  • the number of the color to be changed, color

  • the amount of red, r

  • the amount of green, g

  • the amount of blue, b

The value of the first argument must be between 0 and COLORS. (See the section Colors for the default color index.) Each of the last three arguments must be a value between 0 and 1000. When Curses.init_color is used, all occurrences of that color on the screen immediately change to the new definition.



1336
1337
1338
1339
1340
1341
1342
1343
# File 'ext/curses/curses.c', line 1336

static VALUE
curses_init_color(VALUE obj, VALUE color, VALUE r, VALUE g, VALUE b)
{
    /* may have to raise exception on ERR */
    curses_stdscr();
    return (init_color(NUM2INT(color),NUM2INT(r),
		       NUM2INT(g),NUM2INT(b)) == OK) ? Qtrue : Qfalse;
}

.init_pair(pair, f, b) ⇒ Object

Changes the definition of a color-pair.

It takes three arguments: the number of the color-pair to be changed pair, the foreground color number f, and the background color number b.

If the color-pair was previously initialized, the screen is refreshed and all occurrences of that color-pair are changed to the new definition.



1312
1313
1314
1315
1316
1317
1318
# File 'ext/curses/curses.c', line 1312

static VALUE
curses_init_pair(VALUE obj, VALUE pair, VALUE f, VALUE b)
{
    /* may have to raise exception on ERR */
    curses_stdscr();
    return (init_pair(NUM2INT(pair),NUM2INT(f),NUM2INT(b)) == OK) ? Qtrue : Qfalse;
}

.init_screenObject

Initialize a standard screen

see also Curses.stdscr



304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'ext/curses/curses.c', line 304

static VALUE
curses_init_screen(VALUE self)
{
    if (rb_stdscr) return rb_stdscr;
    initscr();
    if (stdscr == 0) {
	rb_raise(rb_eRuntimeError, "can't initialize curses");
    }
    rb_set_end_proc(curses_finalize, 0);
    clear();
    rb_stdscr = prep_window(cWindow, stdscr);
    return rb_stdscr;
}

.insch(ch) ⇒ Object

Insert a character ch, before the cursor.



801
802
803
804
805
806
807
# File 'ext/curses/curses.c', line 801

static VALUE
curses_insch(VALUE obj, VALUE ch)
{
    curses_stdscr();
    insch(OBJ2CHTYPE(ch));
    return Qnil;
}

.insertlnObject

Inserts a line above the cursor, and the bottom line is lost



935
936
937
938
939
940
941
942
943
# File 'ext/curses/curses.c', line 935

static VALUE
curses_insertln(VALUE obj)
{
    curses_stdscr();
#if defined(HAVE_INSERTLN) || defined(insertln)
    insertln();
#endif
    return Qnil;
}

.keyboard_encodingObject

Returns the encoding for keyboard input.



4540
4541
4542
4543
4544
# File 'ext/curses/curses.c', line 4540

static VALUE
curses_get_keyboard_encoding(VALUE obj)
{
    return rb_enc_from_encoding(keyboard_encoding);
}

.keyboard_encoding=(encoding) ⇒ Object

Sets the encoding for keyboard input.



4552
4553
4554
4555
4556
4557
# File 'ext/curses/curses.c', line 4552

static VALUE
curses_set_keyboard_encoding(VALUE obj, VALUE enc)
{
    keyboard_encoding = rb_to_encoding(enc);
    return enc;
}

.keyname(c) ⇒ Object

Returns the character string corresponding to key c



951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
# File 'ext/curses/curses.c', line 951

static VALUE
curses_keyname(VALUE obj, VALUE c)
{
#ifdef HAVE_KEYNAME
    int cc = curses_char(c);
    const char *name;

    curses_stdscr();
    name = keyname(cc);
    if (name) {
	return rb_str_new_cstr(name);
    }
    else {
	return Qnil;
    }
#else
    return Qnil;
#endif
}

.linesObject

Returns the number of lines on the screen



976
977
978
979
980
# File 'ext/curses/curses.c', line 976

static VALUE
curses_lines(VALUE self)
{
    return INT2FIX(LINES);
}

.mouseinterval(interval) ⇒ Object

The Curses.mouseinterval function sets the maximum time (in thousands of a second) that can elapse between press and release events for them to be recognized as a click.

Use Curses.mouseinterval(0) to disable click resolution. This function returns the previous interval value.

Use Curses.mouseinterval(-1) to obtain the interval without altering it.

The default is one sixth of a second.



1559
1560
1561
1562
1563
1564
# File 'ext/curses/curses.c', line 1559

static VALUE
curses_mouseinterval(VALUE obj, VALUE interval)
{
    curses_stdscr();
    return mouseinterval(NUM2INT(interval)) ? Qtrue : Qfalse;
}

.mousemask(mask) ⇒ Object

Returns the mask of the reportable events



1572
1573
1574
1575
1576
1577
# File 'ext/curses/curses.c', line 1572

static VALUE
curses_mousemask(VALUE obj, VALUE mask)
{
    curses_stdscr();
    return ULONG2NUM(mousemask(NUM2UINT(mask),NULL));
}

.nlObject

Enable the underlying display device to translate the return key into newline on input, and whether it translates newline into return and line-feed on output (in either case, the call Curses.addch(‘n’) does the equivalent of return and line feed on the virtual screen).

Initially, these translations do occur. If you disable them using Curses.nonl, curses will be able to make better use of the line-feed capability, resulting in faster cursor motion. Also, curses will then be able to detect the return key.



599
600
601
602
603
604
605
# File 'ext/curses/curses.c', line 599

static VALUE
curses_nl(VALUE obj)
{
    curses_stdscr();
    nl();
    return Qnil;
}

.nocbreakObject

Put the terminal into normal mode (out of cbreak mode).

See Curses.cbreak for more detail.



577
578
579
580
581
582
583
# File 'ext/curses/curses.c', line 577

static VALUE
curses_nocbreak(VALUE obj)
{
    curses_stdscr();
    nocbreak();
    return Qnil;
}

.nocrmodeObject

Put the terminal into normal mode (out of cbreak mode).

See Curses.cbreak for more detail.



577
578
579
580
581
582
583
# File 'ext/curses/curses.c', line 577

static VALUE
curses_nocbreak(VALUE obj)
{
    curses_stdscr();
    nocbreak();
    return Qnil;
}

.noechoObject

Disables characters typed by the user to be echoed by Curses.getch as they are typed.



495
496
497
498
499
500
501
# File 'ext/curses/curses.c', line 495

static VALUE
curses_noecho(VALUE obj)
{
    curses_stdscr();
    noecho();
    return Qnil;
}

.nonlObject

Disable the underlying display device to translate the return key into newline on input

See Curses.nl for more detail



615
616
617
618
619
620
621
# File 'ext/curses/curses.c', line 615

static VALUE
curses_nonl(VALUE obj)
{
    curses_stdscr();
    nonl();
    return Qnil;
}

.norawObject

Put the terminal out of raw mode.

see Curses.raw for more detail



532
533
534
535
536
537
538
# File 'ext/curses/curses.c', line 532

static VALUE
curses_noraw(VALUE obj)
{
    curses_stdscr();
    noraw();
    return Qnil;
}

.pair_content(pair) ⇒ Object

Returns a 2 item Array, with the foreground and background color, in pair



1423
1424
1425
1426
1427
1428
1429
1430
1431
# File 'ext/curses/curses.c', line 1423

static VALUE
curses_pair_content(VALUE obj, VALUE pair)
{
    short f,b;

    curses_stdscr();
    pair_content(NUM2INT(pair),&f,&b);
    return rb_ary_new3(2,INT2FIX(f),INT2FIX(b));
}

.pair_number(attrs) ⇒ Object

Returns the Fixnum color pair number of attributes attrs.



1455
1456
1457
1458
1459
1460
# File 'ext/curses/curses.c', line 1455

static VALUE
curses_pair_number(VALUE obj, VALUE attrs)
{
    curses_stdscr();
    return INT2FIX(PAIR_NUMBER(NUM2LONG(attrs)));
}

.rawObject

Put the terminal into raw mode.

Raw mode is similar to Curses.cbreak mode, in that characters typed are immediately passed through to the user program.

The differences are that in raw mode, the interrupt, quit, suspend, and flow control characters are all passed through uninterpreted, instead of generating a signal. The behavior of the BREAK key depends on other bits in the tty driver that are not set by curses.



517
518
519
520
521
522
523
# File 'ext/curses/curses.c', line 517

static VALUE
curses_raw(VALUE obj)
{
    curses_stdscr();
    raw();
    return Qnil;
}

.refreshObject

Refreshes the windows and lines.



447
448
449
450
451
452
453
# File 'ext/curses/curses.c', line 447

static VALUE
curses_refresh(VALUE obj)
{
    curses_stdscr();
    refresh();
    return Qnil;
}

.reset_prog_modeObject

Reset the current terminal modes to the saved state by the Curses.def_prog_mode

This is done automatically by Curses.close_screen



1676
1677
1678
1679
1680
1681
# File 'ext/curses/curses.c', line 1676

static VALUE
curses_reset_prog_mode(VALUE obj)
{
    curses_stdscr();
    return reset_prog_mode() == OK ? Qtrue : Qfalse;
}

.resizeterm(lines, cols) ⇒ Object

Resize the current term to Fixnum lines and Fixnum cols



1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
# File 'ext/curses/curses.c', line 1270

static VALUE
curses_resizeterm(VALUE obj, VALUE lin, VALUE col)
{
#if defined(HAVE_RESIZETERM)
    curses_stdscr();
    return (resizeterm(NUM2INT(lin),NUM2INT(col)) == OK) ? Qtrue : Qfalse;
#else
    return Qnil;
#endif
}

.resizeterm(lines, cols) ⇒ Object

Resize the current term to Fixnum lines and Fixnum cols



1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
# File 'ext/curses/curses.c', line 1270

static VALUE
curses_resizeterm(VALUE obj, VALUE lin, VALUE col)
{
#if defined(HAVE_RESIZETERM)
    curses_stdscr();
    return (resizeterm(NUM2INT(lin),NUM2INT(col)) == OK) ? Qtrue : Qfalse;
#else
    return Qnil;
#endif
}

.return_key_modifiers(flag) ⇒ Object



4767
4768
4769
4770
4771
# File 'ext/curses/curses.c', line 4767

static VALUE
curses_return_key_modifiers(VALUE obj, VALUE flag)
{
    return INT2NUM(PDC_return_key_modifiers(RTEST(flag)));
}

.save_key_modifiers(flag) ⇒ Object



4773
4774
4775
4776
4777
# File 'ext/curses/curses.c', line 4773

static VALUE
curses_save_key_modifiers(VALUE obj, VALUE flag)
{
    return INT2NUM(PDC_save_key_modifiers(RTEST(flag)));
}

.scrl(num) ⇒ Object

Scrolls the current window Fixnum num lines. The current cursor position is not changed.

For positive num, it scrolls up.

For negative num, it scrolls down.



1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
# File 'ext/curses/curses.c', line 1026

static VALUE
curses_scrl(VALUE obj, VALUE n)
{
    /* may have to raise exception on ERR */
#ifdef HAVE_SCRL
    curses_stdscr();
    return (scrl(NUM2INT(n)) == OK) ? Qtrue : Qfalse;
#else
    return Qfalse;
#endif
}

.setpos(y, x) ⇒ Object

A setter for the position of the cursor, using coordinates x and y



724
725
726
727
728
729
730
# File 'ext/curses/curses.c', line 724

static VALUE
curses_setpos(VALUE obj, VALUE y, VALUE x)
{
    curses_stdscr();
    move(NUM2INT(y), NUM2INT(x));
    return Qnil;
}

.setscrreg(top, bottom) ⇒ Object

call-seq:

setscrreg(top, bottom)

Set a software scrolling region in a window. top and bottom are lines numbers of the margin.

If this option and Curses.scrollok are enabled, an attempt to move off the bottom margin line causes all lines in the scrolling region to scroll one line in the direction of the first line. Only the text of the window is scrolled.



1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
# File 'ext/curses/curses.c', line 1053

static VALUE
curses_setscrreg(VALUE obj, VALUE top, VALUE bottom)
{
    /* may have to raise exception on ERR */
#ifdef HAVE_SETSCRREG
    curses_stdscr();
    return (setscrreg(NUM2INT(top), NUM2INT(bottom)) == OK) ? Qtrue : Qfalse;
#else
    return Qfalse;
#endif
}

.standendObject

Enables the Normal display (no highlight)

This is equivalent to Curses.attron(A_NORMAL)

see also Curses::Window.attrset for additional information.



758
759
760
761
762
763
764
# File 'ext/curses/curses.c', line 758

static VALUE
curses_standend(VALUE obj)
{
    curses_stdscr();
    standend();
    return Qnil;
}

.standoutObject

Enables the best highlighting mode of the terminal.

This is equivalent to Curses:Window.attron(A_STANDOUT)

see also Curses::Window.attrset additional information



741
742
743
744
745
746
747
# File 'ext/curses/curses.c', line 741

static VALUE
curses_standout(VALUE obj)
{
    curses_stdscr();
    standout();
    return Qnil;
}

.start_colorObject

Initializes the color attributes, for terminals that support it.

This must be called, in order to use color attributes. It is good practice to call it just after Curses.init_screen



1290
1291
1292
1293
1294
1295
1296
# File 'ext/curses/curses.c', line 1290

static VALUE
curses_start_color(VALUE obj)
{
    /* may have to raise exception on ERR */
    curses_stdscr();
    return (start_color() == OK) ? Qtrue : Qfalse;
}

.stdscrObject

Initialize a standard screen

see also Curses.stdscr



304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'ext/curses/curses.c', line 304

static VALUE
curses_init_screen(VALUE self)
{
    if (rb_stdscr) return rb_stdscr;
    initscr();
    if (stdscr == 0) {
	rb_raise(rb_eRuntimeError, "can't initialize curses");
    }
    rb_set_end_proc(curses_finalize, 0);
    clear();
    rb_stdscr = prep_window(cWindow, stdscr);
    return rb_stdscr;
}

.TABSIZEObject

Returns the number of positions in a tab.



1216
1217
1218
1219
1220
# File 'ext/curses/curses.c', line 1216

static VALUE
curses_tabsize_get(VALUE ojb)
{
    return INT2NUM(TABSIZE);
}

.TABSIZE=(value) ⇒ Object

Sets the TABSIZE to Integer value



1202
1203
1204
1205
1206
1207
# File 'ext/curses/curses.c', line 1202

static VALUE
curses_tabsize_set(VALUE obj, VALUE val)
{
    TABSIZE = NUM2INT(val);
    return INT2NUM(TABSIZE);
}

.terminal_encodingObject

Returns the encoding for terminal output.



4565
4566
4567
4568
4569
# File 'ext/curses/curses.c', line 4565

static VALUE
curses_get_terminal_encoding(VALUE obj)
{
    return rb_enc_from_encoding(terminal_encoding);
}

.terminal_encoding=(encoding) ⇒ Object

Sets the encoding for terminal output.



4577
4578
4579
4580
4581
4582
# File 'ext/curses/curses.c', line 4577

static VALUE
curses_set_terminal_encoding(VALUE obj, VALUE enc)
{
    terminal_encoding = rb_to_encoding(enc);
    return enc;
}

.timeout=(delay) ⇒ Object

Sets block and non-blocking reads for the window.

  • If delay is negative, blocking read is used (i.e., waits indefinitely for input).

  • If delay is zero, then non-blocking read is used (i.e., read returns ERR if no input is waiting).

  • If delay is positive, then read blocks for delay milliseconds, and returns ERR if there is still no input.



1637
1638
1639
1640
1641
1642
1643
# File 'ext/curses/curses.c', line 1637

static VALUE
curses_timeout(VALUE obj, VALUE delay)
{
    curses_stdscr();
    timeout(NUM2INT(delay));
    return Qnil;
}

.unget_char(ch) ⇒ Object

Places ch back onto the input queue to be returned by the next call to Curses.get_char etc.

There is just one input queue for all windows.



4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
# File 'ext/curses/curses.c', line 4593

static VALUE
curses_unget_char(VALUE obj, VALUE ch)
{
    ID id_ord;
    unsigned int c;

    curses_stdscr();
    if (FIXNUM_P(ch)) {
	ungetch(NUM2UINT(ch));
    }
    else {
	StringValue(ch);
	CONST_ID(id_ord, "ord");
	c = NUM2UINT(rb_funcall(ch, id_ord, 0));
#ifdef HAVE_UNGET_WCH
	unget_wch(c);
#else
	if (c > 0xff) {
	    rb_raise(rb_eRangeError, "Out of range: %u", c);
	}
	ungetch(c);
#endif
    }
    return Qnil;
}

.ungetch(ch) ⇒ Object

Places ch back onto the input queue to be returned by the next call to Curses.getch.

There is just one input queue for all windows.



704
705
706
707
708
709
710
711
# File 'ext/curses/curses.c', line 704

static VALUE
curses_ungetch(VALUE obj, VALUE ch)
{
    int c = curses_char(ch);
    curses_stdscr();
    ungetch(c);
    return Qnil;
}

.ungetmouse(mevent) ⇒ Object

It pushes a KEY_MOUSE event onto the input queue, and associates with that event the given state data and screen-relative character-cell coordinates.

The Curses.ungetmouse function behaves analogously to Curses.ungetch.



1533
1534
1535
1536
1537
1538
1539
1540
1541
# File 'ext/curses/curses.c', line 1533

static VALUE
curses_ungetmouse(VALUE obj, VALUE mevent)
{
    struct mousedata *mdata;

    curses_stdscr();
    GetMOUSE(mevent,mdata);
    return (ungetmouse(mdata->mevent) == OK) ? Qtrue : Qfalse;
}

.use_default_colorsObject

tells the curses library to use terminal’s default colors.

see also the system manual for default_colors(3)



1167
1168
1169
1170
1171
1172
1173
# File 'ext/curses/curses.c', line 1167

static VALUE
curses_use_default_colors(VALUE obj)
{
    curses_stdscr();
    use_default_colors();
    return Qnil;
}