Module: Curses
- Defined in:
- ext/curses/curses.c,
ext/curses/curses.c,
lib/curses.rb more...
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, Screen, 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
-
.addch(ch) ⇒ Object
Add a character
ch
, with attributes, then advance the cursor. -
.addstr(str) ⇒ Object
add a string of characters
str
, to the window and advance cursor. -
.assume_default_colors(fg, bg) ⇒ Object
tells which colors to paint for color pair 0.
-
.attroff(attrs) ⇒ Object
Turns off the named attributes
attrs
without affecting any others. -
.attron(attrs) ⇒ Object
Turns on the named attributes
attrs
without turning any other attributes on or off. -
.attrset(attrs) ⇒ Object
Sets the current attributes of the given window to
attrs
. -
.beep ⇒ Object
Sounds an audible alarm on the terminal, if possible; otherwise it flashes the screen (visual bell).
-
.bkgd(ch) ⇒ Object
Window background manipulation routines.
-
.bkgdset(ch) ⇒ Object
Manipulate the background of the named window with character Integer
ch
. -
.can_change_color? ⇒ Boolean
Returns
true
orfalse
depending on whether the terminal can change color attributes. -
.cbreak ⇒ Object
Put the terminal into cbreak mode.
- .chgat ⇒ Object
-
.clear ⇒ Object
Clears every position on the screen completely, so that a subsequent call by Curses.refresh for the screen/window will be repainted from scratch.
-
.close_screen ⇒ Object
A program should always call Curses.close_screen before exiting or escaping from curses mode temporarily.
-
.closed? ⇒ Boolean
Returns
true
if the window/screen has been closed, without any subsequent Curses.refresh calls, returnsfalse
otherwise. -
.clrtoeol ⇒ Object
Clears to the end of line, that the cursor is currently on.
-
.color_content(color) ⇒ Object
Returns an 3 item Array of the RGB values in
color
. -
.color_pair(attrs) ⇒ Object
Sets the color pair attributes to
attrs
. -
.color_pairs ⇒ Object
Returns the COLOR_PAIRS available, if the curses library supports it.
-
.colors ⇒ Object
returns COLORS.
-
.cols ⇒ Object
Returns the number of columns on the screen.
-
.crmode ⇒ Object
Put the terminal into cbreak mode.
-
.curs_set(visibility) ⇒ Object
Sets Cursor Visibility.
-
.def_prog_mode ⇒ Object
Save the current terminal modes as the “program” state for use by the Curses.reset_prog_mode.
-
.delch ⇒ Object
Delete the character under the cursor.
-
.deleteln ⇒ Object
Delete the line under the cursor.
-
.doupdate ⇒ Object
Refreshes the windows and lines.
-
.echo ⇒ Object
Enables characters typed by the user to be echoed by Curses.getch as they are typed.
-
.erase ⇒ Object
Erase the screen.
-
.ESCDELAY ⇒ Object
Returns the total time, in milliseconds, for which curses will await a character sequence, e.g., a function key.
-
.ESCDELAY=(value) ⇒ Object
Sets the ESCDELAY to Integer
value
. -
.flash ⇒ Object
Flashes the screen, for visual alarm on the terminal, if possible; otherwise it sounds the alert.
-
.flushinp ⇒ Object
The flushinp routine throws away any typeahead that has been typed by the user and has not yet been read by the program.
-
.get_char ⇒ Object
Read and returns a character or function key from the window.
- .get_key_modifiers ⇒ Object
-
.getch ⇒ Object
Read and returns a character from the window.
-
.getmouse ⇒ Object
Returns coordinates of the mouse.
-
.getstr ⇒ Object
This is equivalent to a series of Curses::Window.getch calls.
-
.has_colors? ⇒ Boolean
Returns
true
orfalse
depending on whether the terminal has color capabilities. -
.inch ⇒ Object
Returns the character at the current position.
-
.init_color(color, r, g, b) ⇒ Object
Changes the definition of a color.
-
.init_pair(pair, f, b) ⇒ Object
Changes the definition of a color-pair.
-
.init_screen ⇒ Object
Initialize a standard screen.
-
.insch(ch) ⇒ Object
Insert a character
ch
, before the cursor. -
.insertln ⇒ Object
Inserts a line above the cursor, and the bottom line is lost.
-
.keyboard_encoding ⇒ Object
Returns the encoding for keyboard input.
-
.keyboard_encoding=(encoding) ⇒ Object
Sets the encoding for keyboard input.
-
.keyname(c) ⇒ Object
Returns the character string corresponding to key
c
. -
.lines ⇒ Object
Returns the number of lines on the screen.
-
.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.
-
.mousemask(mask) ⇒ Object
Returns the
mask
of the reportable events. -
.nl ⇒ Object
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).
-
.nocbreak ⇒ Object
Put the terminal into normal mode (out of cbreak mode).
-
.nocrmode ⇒ Object
Put the terminal into normal mode (out of cbreak mode).
-
.noecho ⇒ Object
Disables characters typed by the user to be echoed by Curses.getch as they are typed.
-
.nonl ⇒ Object
Disable the underlying display device to translate the return key into newline on input.
-
.noraw ⇒ Object
Put the terminal out of raw mode.
-
.pair_content(pair) ⇒ Object
Returns a 2 item Array, with the foreground and background color, in
pair
. -
.pair_number(attrs) ⇒ Object
Returns the Fixnum color pair number of attributes
attrs
. -
.raw ⇒ Object
Put the terminal into raw mode.
-
.refresh ⇒ Object
Refreshes the windows and lines.
-
.reset_prog_mode ⇒ Object
Reset the current terminal modes to the saved state by the Curses.def_prog_mode.
-
.resizeterm(lines, cols) ⇒ Object
Resize the current term to Fixnum
lines
and Fixnumcols
. -
.resizeterm(lines, cols) ⇒ Object
Resize the current term to Fixnum
lines
and Fixnumcols
. - .return_key_modifiers(flag) ⇒ Object
- .save_key_modifiers(flag) ⇒ Object
-
.scrl(num) ⇒ Object
Scrolls the current window Fixnum
num
lines. -
.setpos(y, x) ⇒ Object
A setter for the position of the cursor, using coordinates
x
andy
. -
.setscrreg(top, bottom) ⇒ Object
call-seq: setscrreg(top, bottom).
-
.standend ⇒ Object
Enables the Normal display (no highlight).
-
.standout ⇒ Object
Enables the best highlighting mode of the terminal.
-
.start_color ⇒ Object
Initializes the color attributes, for terminals that support it.
-
.stdscr ⇒ Object
Initialize a standard screen.
-
.TABSIZE ⇒ Object
Returns the number of positions in a tab.
-
.TABSIZE=(value) ⇒ Object
Sets the TABSIZE to Integer
value
. -
.terminal_encoding ⇒ Object
Returns the encoding for terminal output.
-
.terminal_encoding=(encoding) ⇒ Object
Sets the encoding for terminal output.
-
.timeout=(delay) ⇒ Object
Sets block and non-blocking reads for the window.
-
.unget_char(ch) ⇒ Object
Places
ch
back onto the input queue to be returned by the next call to Curses.get_char etc. -
.ungetch(ch) ⇒ Object
Places
ch
back onto the input queue to be returned by the next call to Curses.getch. -
.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.
-
.use_default_colors ⇒ Object
tells the curses library to use terminal’s default colors.
Class Method Details
permalink .addch(ch) ⇒ Object
Add a character ch
, with attributes, then advance the cursor.
see also the system manual for curs_addch(3)
793 794 795 796 797 798 799 |
# File 'ext/curses/curses.c', line 793
static VALUE
curses_addch(VALUE obj, VALUE ch)
{
curses_stdscr();
addch(OBJ2CHTYPE(ch));
return Qnil;
}
|
permalink .addstr(str) ⇒ Object
add a string of characters str
, to the window and advance cursor
823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 |
# File 'ext/curses/curses.c', line 823
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;
}
|
permalink .assume_default_colors(fg, bg) ⇒ Object
tells which colors to paint for color pair 0.
see also the system manual for default_colors(3)
1191 1192 1193 1194 1195 1196 1197 |
# File 'ext/curses/curses.c', line 1191
static VALUE
curses_assume_default_colors(VALUE obj, VALUE fg, VALUE bg)
{
curses_stdscr();
assume_default_colors(NUM2INT(fg), NUM2INT(bg));
return Qnil;
}
|
permalink .attroff(attrs) ⇒ Object
Turns off the named attributes attrs
without affecting any others.
See also Curses::Window.attrset for additional information.
1081 1082 1083 1084 1085 1086 1087 |
# File 'ext/curses/curses.c', line 1081
static VALUE
curses_attroff(VALUE obj, VALUE attrs)
{
curses_stdscr();
return window_attroff(rb_stdscr,attrs);
/* return INT2FIX(attroff(NUM2INT(attrs))); */
}
|
permalink .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.
1098 1099 1100 1101 1102 1103 1104 |
# File 'ext/curses/curses.c', line 1098
static VALUE
curses_attron(VALUE obj, VALUE attrs)
{
curses_stdscr();
return window_attron(rb_stdscr,attrs);
/* return INT2FIX(attroff(NUM2INT(attrs))); */
}
|
permalink .attrset(attrs) ⇒ Object
Sets the current attributes of the given window to attrs
.
see also Curses::Window.attrset
1115 1116 1117 1118 1119 1120 1121 |
# File 'ext/curses/curses.c', line 1115
static VALUE
curses_attrset(VALUE obj, VALUE attrs)
{
curses_stdscr();
return window_attrset(rb_stdscr,attrs);
/* return INT2FIX(attroff(NUM2INT(attrs))); */
}
|
permalink .beep ⇒ Object
Sounds an audible alarm on the terminal, if possible; otherwise it flashes the screen (visual bell).
see also Curses.flash
652 653 654 655 656 657 658 659 660 |
# File 'ext/curses/curses.c', line 652
static VALUE
curses_beep(VALUE obj)
{
#ifdef HAVE_BEEP
curses_stdscr();
beep();
#endif
return Qnil;
}
|
permalink .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)
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 |
# File 'ext/curses/curses.c', line 1157
static VALUE
curses_bkgd(VALUE obj, VALUE ch)
{
#ifdef HAVE_BKGD
curses_stdscr();
return (bkgd(OBJ2CHTYPE(ch)) == OK) ? Qtrue : Qfalse;
#else
return Qfalse;
#endif
}
|
permalink .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)
1136 1137 1138 1139 1140 1141 1142 1143 1144 |
# File 'ext/curses/curses.c', line 1136
static VALUE
curses_bkgdset(VALUE obj, VALUE ch)
{
#ifdef HAVE_BKGDSET
curses_stdscr();
bkgdset(OBJ2CHTYPE(ch));
#endif
return Qnil;
}
|
permalink .can_change_color? ⇒ Boolean
Returns true
or false
depending on whether the terminal can change color attributes
1369 1370 1371 1372 1373 1374 |
# File 'ext/curses/curses.c', line 1369
static VALUE
curses_can_change_color(VALUE obj)
{
curses_stdscr();
return can_change_color() ? Qtrue : Qfalse;
}
|
permalink .cbreak ⇒ Object
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
569 570 571 572 573 574 575 |
# File 'ext/curses/curses.c', line 569
static VALUE
curses_cbreak(VALUE obj)
{
curses_stdscr();
cbreak();
return Qnil;
}
|
permalink .chgat ⇒ Object
[View source]
93 94 95 |
# File 'lib/curses.rb', line 93 def chgat(...) Curses.stdscr.chgat(...) end |
permalink .clear ⇒ Object
Clears every position on the screen completely, so that a subsequent call by Curses.refresh for the screen/window will be repainted from scratch.
410 411 412 413 414 415 416 |
# File 'ext/curses/curses.c', line 410
static VALUE
curses_clear(VALUE obj)
{
curses_stdscr();
wclear(stdscr);
return Qnil;
}
|
permalink .close_screen ⇒ Object
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.
350 351 352 353 354 355 356 357 358 359 360 |
# File 'ext/curses/curses.c', line 350
static VALUE
curses_close_screen(VALUE self)
{
curses_stdscr();
#ifdef HAVE_ISENDWIN
if (!isendwin())
#endif
endwin();
rb_stdscr = 0;
return Qnil;
}
|
permalink .closed? ⇒ Boolean
Returns true
if the window/screen has been closed, without any subsequent Curses.refresh calls, returns false
otherwise.
390 391 392 393 394 395 396 397 398 |
# File 'ext/curses/curses.c', line 390
static VALUE
curses_closed(VALUE self)
{
curses_stdscr();
if (isendwin()) {
return Qtrue;
}
return Qfalse;
}
|
permalink .clrtoeol ⇒ Object
Clears to the end of line, that the cursor is currently on.
440 441 442 443 444 445 446 |
# File 'ext/curses/curses.c', line 440
static VALUE
curses_clrtoeol(VALUE self)
{
curses_stdscr();
clrtoeol();
return Qnil;
}
|
permalink .color_content(color) ⇒ Object
Returns an 3 item Array of the RGB values in color
1397 1398 1399 1400 1401 1402 1403 1404 1405 |
# File 'ext/curses/curses.c', line 1397
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));
}
|
permalink .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
1450 1451 1452 1453 1454 |
# File 'ext/curses/curses.c', line 1450
static VALUE
curses_color_pair(VALUE obj, VALUE attrs)
{
return CHTYPE2NUM(COLOR_PAIR(NUM2CHTYPE(attrs)));
}
|
permalink .color_pairs ⇒ Object
Returns the COLOR_PAIRS available, if the curses library supports it.
1414 1415 1416 1417 1418 |
# File 'ext/curses/curses.c', line 1414
static VALUE
curses_color_pairs(VALUE obj)
{
return INT2FIX(COLOR_PAIRS);
}
|
permalink .colors ⇒ Object
returns COLORS
1382 1383 1384 1385 1386 |
# File 'ext/curses/curses.c', line 1382
static VALUE
curses_colors(VALUE obj)
{
return INT2FIX(COLORS);
}
|
permalink .cols ⇒ Object
Returns the number of columns on the screen
994 995 996 997 998 |
# File 'ext/curses/curses.c', line 994
static VALUE
curses_cols(VALUE self)
{
return INT2FIX(COLS);
}
|
permalink .crmode ⇒ Object
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
569 570 571 572 573 574 575 |
# File 'ext/curses/curses.c', line 569
static VALUE
curses_cbreak(VALUE obj)
{
curses_stdscr();
cbreak();
return Qnil;
}
|
permalink .curs_set(visibility) ⇒ Object
Sets Cursor Visibility. 0: invisible 1: visible 2: very visible
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 |
# File 'ext/curses/curses.c', line 1009
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
}
|
permalink .def_prog_mode ⇒ Object
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
1664 1665 1666 1667 1668 1669 |
# File 'ext/curses/curses.c', line 1664
static VALUE
curses_def_prog_mode(VALUE obj)
{
curses_stdscr();
return def_prog_mode() == OK ? Qtrue : Qfalse;
}
|
permalink .delch ⇒ Object
Delete the character under the cursor
912 913 914 915 916 917 918 |
# File 'ext/curses/curses.c', line 912
static VALUE
curses_delch(VALUE obj)
{
curses_stdscr();
delch();
return Qnil;
}
|
permalink .deleteln ⇒ Object
Delete the line under the cursor.
926 927 928 929 930 931 932 933 934 |
# File 'ext/curses/curses.c', line 926
static VALUE
curses_deleteln(VALUE obj)
{
curses_stdscr();
#if defined(HAVE_DELETELN) || defined(deleteln)
deleteln();
#endif
return Qnil;
}
|
permalink .doupdate ⇒ Object
Refreshes the windows and lines.
Curses.doupdate allows multiple updates with more efficiency than Curses.refresh alone.
470 471 472 473 474 475 476 477 478 479 480 |
# File 'ext/curses/curses.c', line 470
static VALUE
curses_doupdate(VALUE obj)
{
curses_stdscr();
#ifdef HAVE_DOUPDATE
doupdate();
#else
refresh();
#endif
return Qnil;
}
|
permalink .echo ⇒ Object
Enables characters typed by the user to be echoed by Curses.getch as they are typed.
488 489 490 491 492 493 494 |
# File 'ext/curses/curses.c', line 488
static VALUE
curses_echo(VALUE obj)
{
curses_stdscr();
echo();
return Qnil;
}
|
permalink .erase ⇒ Object
Erase the screen.
424 425 426 427 428 429 430 |
# File 'ext/curses/curses.c', line 424
static VALUE
curses_erase(VALUE obj)
{
curses_stdscr();
werase(stdscr);
return Qnil;
}
|
permalink .ESCDELAY ⇒ Object
Returns the total time, in milliseconds, for which curses will await a character sequence, e.g., a function key
1253 1254 1255 1256 1257 |
# File 'ext/curses/curses.c', line 1253
static VALUE
curses_escdelay_get(VALUE obj)
{
return INT2NUM(ESCDELAY);
}
|
permalink .ESCDELAY=(value) ⇒ Object
Sets the ESCDELAY to Integer value
1238 1239 1240 1241 1242 1243 |
# File 'ext/curses/curses.c', line 1238
static VALUE
curses_escdelay_set(VALUE obj, VALUE val)
{
ESCDELAY = NUM2INT(val);
return INT2NUM(ESCDELAY);
}
|
permalink .flash ⇒ Object
Flashes the screen, for visual alarm on the terminal, if possible; otherwise it sounds the alert.
see also Curses.beep
670 671 672 673 674 675 676 677 678 |
# File 'ext/curses/curses.c', line 670
static VALUE
curses_flash(VALUE obj)
{
#ifdef HAVE_FLASH
curses_stdscr();
flash();
#endif
return Qnil;
}
|
permalink .flushinp ⇒ Object
The flushinp routine throws away any typeahead that has been typed by the user and has not yet been read by the program.
636 637 638 639 640 641 642 |
# File 'ext/curses/curses.c', line 636
static VALUE
curses_flushinp(VALUE obj)
{
curses_stdscr();
flushinp();
return Qnil;
}
|
permalink .get_char ⇒ Object
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
4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 |
# File 'ext/curses/curses.c', line 4811
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
}
|
permalink .get_key_modifiers ⇒ Object
[View source]
4908 4909 4910 4911 4912 |
# File 'ext/curses/curses.c', line 4908
static VALUE
curses_get_key_modifiers(VALUE obj)
{
return ULONG2NUM(PDC_get_key_modifiers());
}
|
permalink .getch ⇒ Object
Read and returns a character from the window.
See Curses::Key to all the function KEY_* available
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 |
# File 'ext/curses/curses.c', line 859
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);
}
|
permalink .getmouse ⇒ Object
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
1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 |
# File 'ext/curses/curses.c', line 1519
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;
}
|
permalink .getstr ⇒ Object
This is equivalent to a series of Curses::Window.getch calls
896 897 898 899 900 901 902 903 904 |
# File 'ext/curses/curses.c', line 896
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);
}
|
permalink .has_colors? ⇒ Boolean
Returns true
or false
depending on whether the terminal has color capabilities.
1357 1358 1359 1360 1361 1362 |
# File 'ext/curses/curses.c', line 1357
static VALUE
curses_has_colors(VALUE obj)
{
curses_stdscr();
return has_colors() ? Qtrue : Qfalse;
}
|
permalink .inch ⇒ Object
Returns the character at the current position.
778 779 780 781 782 783 |
# File 'ext/curses/curses.c', line 778
static VALUE
curses_inch(VALUE obj)
{
curses_stdscr();
return CHTYPE2NUM(inch());
}
|
permalink .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.
1343 1344 1345 1346 1347 1348 1349 1350 |
# File 'ext/curses/curses.c', line 1343
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;
}
|
permalink .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.
1319 1320 1321 1322 1323 1324 1325 |
# File 'ext/curses/curses.c', line 1319
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;
}
|
permalink .init_screen ⇒ Object
Initialize a standard screen
see also Curses.stdscr
311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'ext/curses/curses.c', line 311
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, 1);
return rb_stdscr;
}
|
permalink .insch(ch) ⇒ Object
Insert a character ch
, before the cursor.
808 809 810 811 812 813 814 |
# File 'ext/curses/curses.c', line 808
static VALUE
curses_insch(VALUE obj, VALUE ch)
{
curses_stdscr();
insch(OBJ2CHTYPE(ch));
return Qnil;
}
|
permalink .insertln ⇒ Object
Inserts a line above the cursor, and the bottom line is lost
942 943 944 945 946 947 948 949 950 |
# File 'ext/curses/curses.c', line 942
static VALUE
curses_insertln(VALUE obj)
{
curses_stdscr();
#if defined(HAVE_INSERTLN) || defined(insertln)
insertln();
#endif
return Qnil;
}
|
permalink .keyboard_encoding ⇒ Object
Returns the encoding for keyboard input.
4687 4688 4689 4690 4691 |
# File 'ext/curses/curses.c', line 4687
static VALUE
curses_get_keyboard_encoding(VALUE obj)
{
return rb_enc_from_encoding(keyboard_encoding);
}
|
permalink .keyboard_encoding=(encoding) ⇒ Object
Sets the encoding for keyboard input.
4699 4700 4701 4702 4703 4704 |
# File 'ext/curses/curses.c', line 4699
static VALUE
curses_set_keyboard_encoding(VALUE obj, VALUE enc)
{
keyboard_encoding = rb_to_encoding(enc);
return enc;
}
|
permalink .keyname(c) ⇒ Object
Returns the character string corresponding to key c
958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 |
# File 'ext/curses/curses.c', line 958
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
}
|
permalink .lines ⇒ Object
Returns the number of lines on the screen
983 984 985 986 987 |
# File 'ext/curses/curses.c', line 983
static VALUE
curses_lines(VALUE self)
{
return INT2FIX(LINES);
}
|
permalink .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.
1566 1567 1568 1569 1570 1571 |
# File 'ext/curses/curses.c', line 1566
static VALUE
curses_mouseinterval(VALUE obj, VALUE interval)
{
curses_stdscr();
return mouseinterval(NUM2INT(interval)) ? Qtrue : Qfalse;
}
|
permalink .mousemask(mask) ⇒ Object
Returns the mask
of the reportable events
1579 1580 1581 1582 1583 1584 |
# File 'ext/curses/curses.c', line 1579
static VALUE
curses_mousemask(VALUE obj, VALUE mask)
{
curses_stdscr();
return ULONG2NUM(mousemask(NUM2UINT(mask),NULL));
}
|
permalink .nl ⇒ Object
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.
606 607 608 609 610 611 612 |
# File 'ext/curses/curses.c', line 606
static VALUE
curses_nl(VALUE obj)
{
curses_stdscr();
nl();
return Qnil;
}
|
permalink .nocbreak ⇒ Object
Put the terminal into normal mode (out of cbreak mode).
See Curses.cbreak for more detail.
584 585 586 587 588 589 590 |
# File 'ext/curses/curses.c', line 584
static VALUE
curses_nocbreak(VALUE obj)
{
curses_stdscr();
nocbreak();
return Qnil;
}
|
permalink .nocrmode ⇒ Object
Put the terminal into normal mode (out of cbreak mode).
See Curses.cbreak for more detail.
584 585 586 587 588 589 590 |
# File 'ext/curses/curses.c', line 584
static VALUE
curses_nocbreak(VALUE obj)
{
curses_stdscr();
nocbreak();
return Qnil;
}
|
permalink .noecho ⇒ Object
Disables characters typed by the user to be echoed by Curses.getch as they are typed.
502 503 504 505 506 507 508 |
# File 'ext/curses/curses.c', line 502
static VALUE
curses_noecho(VALUE obj)
{
curses_stdscr();
noecho();
return Qnil;
}
|
permalink .nonl ⇒ Object
Disable the underlying display device to translate the return key into newline on input
See Curses.nl for more detail
622 623 624 625 626 627 628 |
# File 'ext/curses/curses.c', line 622
static VALUE
curses_nonl(VALUE obj)
{
curses_stdscr();
nonl();
return Qnil;
}
|
permalink .noraw ⇒ Object
Put the terminal out of raw mode.
see Curses.raw for more detail
539 540 541 542 543 544 545 |
# File 'ext/curses/curses.c', line 539
static VALUE
curses_noraw(VALUE obj)
{
curses_stdscr();
noraw();
return Qnil;
}
|
permalink .pair_content(pair) ⇒ Object
Returns a 2 item Array, with the foreground and background color, in pair
1430 1431 1432 1433 1434 1435 1436 1437 1438 |
# File 'ext/curses/curses.c', line 1430
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));
}
|
permalink .pair_number(attrs) ⇒ Object
Returns the Fixnum color pair number of attributes attrs
.
1462 1463 1464 1465 1466 1467 |
# File 'ext/curses/curses.c', line 1462
static VALUE
curses_pair_number(VALUE obj, VALUE attrs)
{
curses_stdscr();
return INT2FIX(PAIR_NUMBER(NUM2CHTYPE(attrs)));
}
|
permalink .raw ⇒ Object
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.
524 525 526 527 528 529 530 |
# File 'ext/curses/curses.c', line 524
static VALUE
curses_raw(VALUE obj)
{
curses_stdscr();
raw();
return Qnil;
}
|
permalink .refresh ⇒ Object
Refreshes the windows and lines.
454 455 456 457 458 459 460 |
# File 'ext/curses/curses.c', line 454
static VALUE
curses_refresh(VALUE obj)
{
curses_stdscr();
refresh();
return Qnil;
}
|
permalink .reset_prog_mode ⇒ Object
Reset the current terminal modes to the saved state by the Curses.def_prog_mode
This is done automatically by Curses.close_screen
1683 1684 1685 1686 1687 1688 |
# File 'ext/curses/curses.c', line 1683
static VALUE
curses_reset_prog_mode(VALUE obj)
{
curses_stdscr();
return reset_prog_mode() == OK ? Qtrue : Qfalse;
}
|
permalink .resizeterm(lines, cols) ⇒ Object
Resize the current term to Fixnum lines
and Fixnum cols
1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 |
# File 'ext/curses/curses.c', line 1277
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
}
|
permalink .resizeterm(lines, cols) ⇒ Object
Resize the current term to Fixnum lines
and Fixnum cols
1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 |
# File 'ext/curses/curses.c', line 1277
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
}
|
permalink .return_key_modifiers(flag) ⇒ Object
[View source]
4914 4915 4916 4917 4918 |
# File 'ext/curses/curses.c', line 4914
static VALUE
curses_return_key_modifiers(VALUE obj, VALUE flag)
{
return INT2NUM(PDC_return_key_modifiers(RTEST(flag)));
}
|
permalink .save_key_modifiers(flag) ⇒ Object
[View source]
4920 4921 4922 4923 4924 |
# File 'ext/curses/curses.c', line 4920
static VALUE
curses_save_key_modifiers(VALUE obj, VALUE flag)
{
return INT2NUM(PDC_save_key_modifiers(RTEST(flag)));
}
|
permalink .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.
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 |
# File 'ext/curses/curses.c', line 1033
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
}
|
permalink .setpos(y, x) ⇒ Object
A setter for the position of the cursor, using coordinates x
and y
731 732 733 734 735 736 737 |
# File 'ext/curses/curses.c', line 731
static VALUE
curses_setpos(VALUE obj, VALUE y, VALUE x)
{
curses_stdscr();
move(NUM2INT(y), NUM2INT(x));
return Qnil;
}
|
permalink .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.
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 |
# File 'ext/curses/curses.c', line 1060
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
}
|
permalink .standend ⇒ Object
Enables the Normal display (no highlight)
This is equivalent to Curses.attron(A_NORMAL)
see also Curses::Window.attrset for additional information.
765 766 767 768 769 770 771 |
# File 'ext/curses/curses.c', line 765
static VALUE
curses_standend(VALUE obj)
{
curses_stdscr();
standend();
return Qnil;
}
|
permalink .standout ⇒ Object
Enables the best highlighting mode of the terminal.
This is equivalent to Curses:Window.attron(A_STANDOUT)
see also Curses::Window.attrset additional information
748 749 750 751 752 753 754 |
# File 'ext/curses/curses.c', line 748
static VALUE
curses_standout(VALUE obj)
{
curses_stdscr();
standout();
return Qnil;
}
|
permalink .start_color ⇒ Object
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
1297 1298 1299 1300 1301 1302 1303 |
# File 'ext/curses/curses.c', line 1297
static VALUE
curses_start_color(VALUE obj)
{
/* may have to raise exception on ERR */
curses_stdscr();
return (start_color() == OK) ? Qtrue : Qfalse;
}
|
permalink .stdscr ⇒ Object
Initialize a standard screen
see also Curses.stdscr
311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'ext/curses/curses.c', line 311
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, 1);
return rb_stdscr;
}
|
permalink .TABSIZE ⇒ Object
Returns the number of positions in a tab.
1223 1224 1225 1226 1227 |
# File 'ext/curses/curses.c', line 1223
static VALUE
curses_tabsize_get(VALUE ojb)
{
return INT2NUM(TABSIZE);
}
|
permalink .TABSIZE=(value) ⇒ Object
Sets the TABSIZE to Integer value
1209 1210 1211 1212 1213 1214 |
# File 'ext/curses/curses.c', line 1209
static VALUE
curses_tabsize_set(VALUE obj, VALUE val)
{
TABSIZE = NUM2INT(val);
return INT2NUM(TABSIZE);
}
|
permalink .terminal_encoding ⇒ Object
Returns the encoding for terminal output.
4712 4713 4714 4715 4716 |
# File 'ext/curses/curses.c', line 4712
static VALUE
curses_get_terminal_encoding(VALUE obj)
{
return rb_enc_from_encoding(terminal_encoding);
}
|
permalink .terminal_encoding=(encoding) ⇒ Object
Sets the encoding for terminal output.
4724 4725 4726 4727 4728 4729 |
# File 'ext/curses/curses.c', line 4724
static VALUE
curses_set_terminal_encoding(VALUE obj, VALUE enc)
{
terminal_encoding = rb_to_encoding(enc);
return enc;
}
|
permalink .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.
1644 1645 1646 1647 1648 1649 1650 |
# File 'ext/curses/curses.c', line 1644
static VALUE
curses_timeout(VALUE obj, VALUE delay)
{
curses_stdscr();
timeout(NUM2INT(delay));
return Qnil;
}
|
permalink .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.
4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 |
# File 'ext/curses/curses.c', line 4740
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;
}
|
permalink .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.
711 712 713 714 715 716 717 718 |
# File 'ext/curses/curses.c', line 711
static VALUE
curses_ungetch(VALUE obj, VALUE ch)
{
int c = curses_char(ch);
curses_stdscr();
ungetch(c);
return Qnil;
}
|
permalink .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.
1540 1541 1542 1543 1544 1545 1546 1547 1548 |
# File 'ext/curses/curses.c', line 1540
static VALUE
curses_ungetmouse(VALUE obj, VALUE mevent)
{
struct mousedata *mdata;
curses_stdscr();
GetMOUSE(mevent,mdata);
return (ungetmouse(mdata->mevent) == OK) ? Qtrue : Qfalse;
}
|
permalink .use_default_colors ⇒ Object
tells the curses library to use terminal’s default colors.
see also the system manual for default_colors(3)
1174 1175 1176 1177 1178 1179 1180 |
# File 'ext/curses/curses.c', line 1174
static VALUE
curses_use_default_colors(VALUE obj)
{
curses_stdscr();
use_default_colors();
return Qnil;
}
|