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
#!/usr/local/bin/ruby require "curses" include Curses def show_message(message) width = message.length + 6 win = Window.new(5, width, (lines - 5) / 2, (cols - width) / 2) win.box(?|, ?-) win.setpos(2, 3) win.addstr(message) win.refresh win.getch win.close end init_screen begin crmode # show_message("Hit any key") setpos((lines - 5) / 2, (cols - 10) / 2) addstr("Hit any key") refresh getch show_message("Hello, World!") refresh ensure close_screen end
-
rain.rb
#!/usr/local/bin/ruby # rain for a curses test require "curses" include Curses def onsig(sig) close_screen exit sig end def ranf rand(32767).to_f / 32767 end # main # for i in %w[HUP INT QUIT TERM] if trap(i, "SIG_IGN") != 0 then # 0 for SIG_IGN trap(i) {|sig| onsig(sig) } end end init_screen nl noecho srand xpos = {} ypos = {} r = lines - 4 c = cols - 4 for i in 0 .. 4 xpos[i] = (c * ranf).to_i + 2 ypos[i] = (r * ranf).to_i + 2 end i = 0 while TRUE x = (c * ranf).to_i + 2 y = (r * ranf).to_i + 2 setpos(y, x); addstr(".") setpos(ypos[i], xpos[i]); addstr("o") i = if i == 0 then 4 else i - 1 end setpos(ypos[i], xpos[i]); addstr("O") i = if i == 0 then 4 else i - 1 end setpos(ypos[i] - 1, xpos[i]); addstr("-") setpos(ypos[i], xpos[i] - 1); addstr("|.|") setpos(ypos[i] + 1, xpos[i]); addstr("-") i = if i == 0 then 4 else i - 1 end setpos(ypos[i] - 2, xpos[i]); addstr("-") setpos(ypos[i] - 1, xpos[i] - 1); addstr("/ \\") setpos(ypos[i], xpos[i] - 2); addstr("| O |") setpos(ypos[i] + 1, xpos[i] - 1); addstr("\\ /") setpos(ypos[i] + 2, xpos[i]); addstr("-") i = if i == 0 then 4 else i - 1 end setpos(ypos[i] - 2, xpos[i]); addstr(" ") setpos(ypos[i] - 1, xpos[i] - 1); addstr(" ") setpos(ypos[i], xpos[i] - 2); addstr(" ") setpos(ypos[i] + 1, xpos[i] - 1); addstr(" ") setpos(ypos[i] + 2, xpos[i]); addstr(" ") xpos[i] = x ypos[i] = y refresh sleep(0.5) end # end of main
- MODULE Curses::Key
- CLASS Curses::MouseEvent
- CLASS Curses::Pad
- CLASS Curses::Window
- E
- T
- A
- B
- C
- D
- E
- F
- G
- H
- I
- K
- L
- M
- N
- P
- R
- S
- T
- U
VERSION | = | version |
Identifies curses library version.
|
||
A_ATTRIBUTES | = | Character attribute mask |
Bit-mask to extract attributes See ::inch or Curses::Window#inch |
||
A_NORMAL | = | Attribute mask |
Normal display (no highlight) See ::attrset |
||
A_STANDOUT | = | Attribute mask |
Best highlighting mode of the terminal. See ::attrset |
||
A_UNDERLINE | = | Attribute mask |
Underlining See ::attrset |
||
A_REVERSE | = | Attribute mask |
Reverse video See ::attrset |
||
A_BLINK | = | Attribute mask |
Blinking See ::attrset |
||
A_DIM | = | Attribute mask |
Half bright See ::attrset |
||
A_BOLD | = | Attribute mask |
Extra bright or bold See ::attrset |
||
A_PROTECT | = | Attribute mask |
Protected mode See ::attrset |
||
A_INVIS | = | Attribute mask |
Invisible or blank mode See ::attrset |
||
A_ALTCHARSET | = | Attribute mask |
Alternate character set See ::attrset |
||
A_CHARTEXT | = | Attribute mask |
Bit-mask to extract a character See ::attrset |
||
A_HORIZONTAL | = | Attribute mask |
horizontal highlight Check system curs_attr(3x) for support |
||
A_LEFT | = | Attribute mask |
left highlight Check system curs_attr(3x) for support |
||
A_LOW | = | Attribute mask |
low highlight Check system curs_attr(3x) for support |
||
A_RIGHT | = | Attribute mask |
right highlight Check system curs_attr(3x) for support |
||
A_TOP | = | Attribute mask |
top highlight Check system curs_attr(3x) for support |
||
A_VERTICAL | = | Attribute mask |
vertical highlight Check system curs_attr(3x) for support |
||
A_COLOR | = | Character attribute mask |
Bit-mask to extract color-pair field information See ::inch or Curses::Window#inch |
||
COLORS | = | UINT2NUM(COLORS) |
Number of the colors available |
||
COLOR_BLACK | = | UINT2NUM(COLOR_BLACK) |
Value of the color black |
||
COLOR_RED | = | UINT2NUM(COLOR_RED) |
Value of the color red |
||
COLOR_GREEN | = | UINT2NUM(COLOR_GREEN) |
Value of the color green |
||
COLOR_YELLOW | = | UINT2NUM(COLOR_YELLOW) |
Value of the color yellow |
||
COLOR_BLUE | = | UINT2NUM(COLOR_BLUE) |
Value of the color blue |
||
COLOR_MAGENTA | = | UINT2NUM(COLOR_MAGENTA) |
Value of the color magenta |
||
COLOR_CYAN | = | UINT2NUM(COLOR_CYAN) |
Value of the color cyan |
||
COLOR_WHITE | = | UINT2NUM(COLOR_WHITE) |
Value of the color white |
||
BUTTON1_PRESSED | = | Mouse event mask |
mouse button 1 down See ::getmouse |
||
BUTTON1_RELEASED | = | Mouse event mask |
mouse button 1 up See ::getmouse |
||
BUTTON1_CLICKED | = | Mouse event mask |
mouse button 1 clicked See ::getmouse |
||
BUTTON1_DOUBLE_CLICKED | = | Mouse event mask |
mouse button 1 double clicked See ::getmouse |
||
BUTTON1_TRIPLE_CLICKED | = | Mouse event mask |
mouse button 1 triple clicked See ::getmouse |
||
BUTTON2_PRESSED | = | Mouse event mask |
mouse button 2 down See ::getmouse |
||
BUTTON2_RELEASED | = | Mouse event mask |
mouse button 2 up See ::getmouse |
||
BUTTON2_CLICKED | = | Mouse event mask |
mouse button 2 clicked See ::getmouse |
||
BUTTON2_DOUBLE_CLICKED | = | Mouse event mask |
mouse button 2 double clicked See ::getmouse |
||
BUTTON2_TRIPLE_CLICKED | = | Mouse event mask |
mouse button 2 triple clicked See ::getmouse |
||
BUTTON3_PRESSED | = | Mouse event mask |
mouse button 3 down See ::getmouse |
||
BUTTON3_RELEASED | = | Mouse event mask |
mouse button 3 up See ::getmouse |
||
BUTTON3_CLICKED | = | Mouse event mask |
mouse button 3 clicked See ::getmouse |
||
BUTTON3_DOUBLE_CLICKED | = | Mouse event mask |
mouse button 3 double clicked See ::getmouse |
||
BUTTON3_TRIPLE_CLICKED | = | Mouse event mask |
mouse button 3 triple clicked See ::getmouse |
||
BUTTON4_PRESSED | = | Mouse event mask |
mouse button 4 down See ::getmouse |
||
BUTTON4_RELEASED | = | Mouse event mask |
mouse button 4 up See ::getmouse |
||
BUTTON4_CLICKED | = | Mouse event mask |
mouse button 4 clicked See ::getmouse |
||
BUTTON4_DOUBLE_CLICKED | = | Mouse event mask |
mouse button 4 double clicked See ::getmouse |
||
BUTTON4_TRIPLE_CLICKED | = | Mouse event mask |
mouse button 4 triple clicked See ::getmouse |
||
BUTTON_SHIFT | = | Mouse event mask |
shift was down during button state change See ::getmouse |
||
BUTTON_CTRL | = | Mouse event mask |
control was down during button state change See ::getmouse |
||
BUTTON_ALT | = | Mouse event mask |
alt was down during button state change See ::getmouse |
||
ALL_MOUSE_EVENTS | = | Mouse event mask |
report all button state changes See ::getmouse |
||
REPORT_MOUSE_POSITION | = | Mouse event mask |
report mouse movement See ::getmouse |
||
KEY_MOUSE | = | UINT2NUM(KEY_MOUSE) |
Mouse event read |
||
KEY_MIN | = | UINT2NUM(KEY_MIN) |
The minimum allowed curses key value. |
||
KEY_BREAK | = | UINT2NUM(KEY_BREAK) |
Break key |
||
KEY_DOWN | = | UINT2NUM(KEY_DOWN) |
the down arrow key |
||
KEY_UP | = | UINT2NUM(KEY_UP) |
the up arrow key |
||
KEY_LEFT | = | UINT2NUM(KEY_LEFT) |
the left arrow key |
||
KEY_RIGHT | = | UINT2NUM(KEY_RIGHT) |
the right arrow key |
||
KEY_HOME | = | UINT2NUM(KEY_HOME) |
Home key (upward+left arrow) |
||
KEY_BACKSPACE | = | UINT2NUM(KEY_BACKSPACE) |
Backspace |
||
KEY_DL | = | UINT2NUM(KEY_DL) |
Delete line |
||
KEY_IL | = | UINT2NUM(KEY_IL) |
Insert line |
||
KEY_DC | = | UINT2NUM(KEY_DC) |
Delete character |
||
KEY_IC | = | UINT2NUM(KEY_IC) |
Insert char or enter insert mode |
||
KEY_EIC | = | UINT2NUM(KEY_EIC) |
Enter insert char mode |
||
KEY_CLEAR | = | UINT2NUM(KEY_CLEAR) |
Clear Screen |
||
KEY_EOS | = | UINT2NUM(KEY_EOS) |
Clear to end of screen |
||
KEY_EOL | = | UINT2NUM(KEY_EOL) |
Clear to end of line |
||
KEY_SF | = | UINT2NUM(KEY_SF) |
Scroll 1 line forward |
||
KEY_SR | = | UINT2NUM(KEY_SR) |
Scroll 1 line backware (reverse) |
||
KEY_NPAGE | = | UINT2NUM(KEY_NPAGE) |
Next page |
||
KEY_PPAGE | = | UINT2NUM(KEY_PPAGE) |
Previous page |
||
KEY_STAB | = | UINT2NUM(KEY_STAB) |
Set tab |
||
KEY_CTAB | = | UINT2NUM(KEY_CTAB) |
Clear tab |
||
KEY_CATAB | = | UINT2NUM(KEY_CATAB) |
Clear all tabs |
||
KEY_ENTER | = | UINT2NUM(KEY_ENTER) |
Enter or send |
||
KEY_SRESET | = | UINT2NUM(KEY_SRESET) |
Soft (partial) reset |
||
KEY_RESET | = | UINT2NUM(KEY_RESET) |
Reset or hard reset |
||
KEY_PRINT | = | UINT2NUM(KEY_PRINT) |
Print or copy |
||
KEY_LL | = | UINT2NUM(KEY_LL) |
Home down or bottom (lower left) |
||
KEY_A1 | = | UINT2NUM(KEY_A1) |
Upper left of keypad |
||
KEY_A3 | = | UINT2NUM(KEY_A3) |
Upper right of keypad |
||
KEY_B2 | = | UINT2NUM(KEY_B2) |
Center of keypad |
||
KEY_C1 | = | UINT2NUM(KEY_C1) |
Lower left of keypad |
||
KEY_C3 | = | UINT2NUM(KEY_C3) |
Lower right of keypad |
||
KEY_BTAB | = | UINT2NUM(KEY_BTAB) |
Back tab key |
||
KEY_BEG | = | UINT2NUM(KEY_BEG) |
Beginning key |
||
KEY_CANCEL | = | UINT2NUM(KEY_CANCEL) |
Cancel key |
||
KEY_CLOSE | = | UINT2NUM(KEY_CLOSE) |
Close key |
||
KEY_COMMAND | = | UINT2NUM(KEY_COMMAND) |
Cmd (command) key |
||
KEY_COPY | = | UINT2NUM(KEY_COPY) |
Copy key |
||
KEY_CREATE | = | UINT2NUM(KEY_CREATE) |
Create key |
||
KEY_END | = | UINT2NUM(KEY_END) |
End key |
||
KEY_EXIT | = | UINT2NUM(KEY_EXIT) |
Exit key |
||
KEY_FIND | = | UINT2NUM(KEY_FIND) |
Find key |
||
KEY_HELP | = | UINT2NUM(KEY_HELP) |
Help key |
||
KEY_MARK | = | UINT2NUM(KEY_MARK) |
Mark key |
||
KEY_MESSAGE | = | UINT2NUM(KEY_MESSAGE) |
Message key |
||
KEY_MOVE | = | UINT2NUM(KEY_MOVE) |
Move key |
||
KEY_NEXT | = | UINT2NUM(KEY_NEXT) |
Next object key |
||
KEY_OPEN | = | UINT2NUM(KEY_OPEN) |
Open key |
||
KEY_OPTIONS | = | UINT2NUM(KEY_OPTIONS) |
Options key |
||
KEY_PREVIOUS | = | UINT2NUM(KEY_PREVIOUS) |
Previous object key |
||
KEY_REDO | = | UINT2NUM(KEY_REDO) |
Redo key |
||
KEY_REFERENCE | = | UINT2NUM(KEY_REFERENCE) |
Reference key |
||
KEY_REFRESH | = | UINT2NUM(KEY_REFRESH) |
Refresh key |
||
KEY_REPLACE | = | UINT2NUM(KEY_REPLACE) |
Replace key |
||
KEY_RESTART | = | UINT2NUM(KEY_RESTART) |
Restart key |
||
KEY_RESUME | = | UINT2NUM(KEY_RESUME) |
Resume key |
||
KEY_SAVE | = | UINT2NUM(KEY_SAVE) |
Save key |
||
KEY_SBEG | = | UINT2NUM(KEY_SBEG) |
Shifted beginning key |
||
KEY_SCANCEL | = | UINT2NUM(KEY_SCANCEL) |
Shifted cancel key |
||
KEY_SCOMMAND | = | UINT2NUM(KEY_SCOMMAND) |
Shifted command key |
||
KEY_SCOPY | = | UINT2NUM(KEY_SCOPY) |
Shifted copy key |
||
KEY_SCREATE | = | UINT2NUM(KEY_SCREATE) |
Shifted create key |
||
KEY_SDC | = | UINT2NUM(KEY_SDC) |
Shifted delete char key |
||
KEY_SDL | = | UINT2NUM(KEY_SDL) |
Shifted delete line key |
||
KEY_SELECT | = | UINT2NUM(KEY_SELECT) |
Select key |
||
KEY_SEND | = | UINT2NUM(KEY_SEND) |
Shifted end key |
||
KEY_SEOL | = | UINT2NUM(KEY_SEOL) |
Shifted clear line key |
||
KEY_SEXIT | = | UINT2NUM(KEY_SEXIT) |
Shifted exit key |
||
KEY_SFIND | = | UINT2NUM(KEY_SFIND) |
Shifted find key |
||
KEY_SHELP | = | UINT2NUM(KEY_SHELP) |
Shifted help key |
||
KEY_SHOME | = | UINT2NUM(KEY_SHOME) |
Shifted home key |
||
KEY_SIC | = | UINT2NUM(KEY_SIC) |
Shifted input key |
||
KEY_SLEFT | = | UINT2NUM(KEY_SLEFT) |
Shifted left arrow key |
||
KEY_SMESSAGE | = | UINT2NUM(KEY_SMESSAGE) |
Shifted message key |
||
KEY_SMOVE | = | UINT2NUM(KEY_SMOVE) |
Shifted move key |
||
KEY_SNEXT | = | UINT2NUM(KEY_SNEXT) |
Shifted next key |
||
KEY_SOPTIONS | = | UINT2NUM(KEY_SOPTIONS) |
Shifted options key |
||
KEY_SPREVIOUS | = | UINT2NUM(KEY_SPREVIOUS) |
Shifted previous key |
||
KEY_SPRINT | = | UINT2NUM(KEY_SPRINT) |
Shifted print key |
||
KEY_SREDO | = | UINT2NUM(KEY_SREDO) |
Shifted redo key |
||
KEY_SREPLACE | = | UINT2NUM(KEY_SREPLACE) |
Shifted replace key |
||
KEY_SRIGHT | = | UINT2NUM(KEY_SRIGHT) |
Shifted right arrow key |
||
KEY_SRSUME | = | UINT2NUM(KEY_SRSUME) |
Shifted resume key |
||
KEY_SSAVE | = | UINT2NUM(KEY_SSAVE) |
Shifted save key |
||
KEY_SSUSPEND | = | UINT2NUM(KEY_SSUSPEND) |
Shifted suspend key |
||
KEY_SUNDO | = | UINT2NUM(KEY_SUNDO) |
Shifted undo key |
||
KEY_SUSPEND | = | UINT2NUM(KEY_SUSPEND) |
Suspend key |
||
KEY_UNDO | = | UINT2NUM(KEY_UNDO) |
Undo key |
||
KEY_RESIZE | = | UINT2NUM(KEY_RESIZE) |
Screen Resized |
||
KEY_MAX | = | UINT2NUM(KEY_MAX) |
The maximum allowed curses key value. |
Returns the total time, in milliseconds, for which curses will await a character sequence, e.g., a function key
Source: show
static VALUE curses_escdelay_get(VALUE obj) { return INT2NUM(ESCDELAY); }
Sets the ::ESCDELAY to Integer value
Source: show
static VALUE curses_escdelay_set(VALUE obj, VALUE val) { ESCDELAY = NUM2INT(val); return INT2NUM(ESCDELAY); }
Returns the number of positions in a tab.
Source: show
static VALUE curses_tabsize_get(VALUE ojb) { return INT2NUM(TABSIZE); }
Source: show
static VALUE curses_tabsize_set(VALUE obj, VALUE val) { TABSIZE = NUM2INT(val); return INT2NUM(TABSIZE); }
Add a character ch
, with attributes, then advance the cursor.
see also the system manual for curs_addch(3)
Source: show
static VALUE curses_addch(VALUE obj, VALUE ch) { curses_stdscr(); addch(NUM2CH(ch)); return Qnil; }
add a string of characters str
, to the window and advance
cursor
Source: show
static VALUE curses_addstr(VALUE obj, VALUE str) { StringValue(str); str = rb_str_export_locale(str); curses_stdscr(); if (!NIL_P(str)) { addstr(StringValueCStr(str)); } return Qnil; }
Turns on the named attributes attrs
without affecting any
others.
See also Curses::Window#attrset for additional information.
Source: show
static VALUE curses_attroff(VALUE obj, VALUE attrs) { curses_stdscr(); return window_attroff(rb_stdscr,attrs); /* return INT2FIX(attroff(NUM2INT(attrs))); */ }
Turns off the named attributes attrs
without turning any other
attributes on or off.
See also Curses::Window#attrset for additional information.
Source: show
static VALUE curses_attron(VALUE obj, VALUE attrs) { curses_stdscr(); return window_attron(rb_stdscr,attrs); /* return INT2FIX(attroff(NUM2INT(attrs))); */ }
Sets the current attributes of the given window to attrs
.
see also Curses::Window#attrset
Source: show
static VALUE curses_attrset(VALUE obj, VALUE attrs) { curses_stdscr(); return window_attrset(rb_stdscr,attrs); /* return INT2FIX(attroff(NUM2INT(attrs))); */ }
Sounds an audible alarm on the terminal, if possible; otherwise it flashes the screen (visual bell).
see also ::flash
Source: show
static VALUE curses_beep(VALUE obj) { #ifdef HAVE_BEEP curses_stdscr(); beep(); #endif return Qnil; }
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)
Source: show
static VALUE curses_bkgd(VALUE obj, VALUE ch) { #ifdef HAVE_BKGD curses_stdscr(); return (bkgd(NUM2CH(ch)) == OK) ? Qtrue : Qfalse; #else return Qfalse; #endif }
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)
Source: show
static VALUE curses_bkgdset(VALUE obj, VALUE ch) { #ifdef HAVE_BKGDSET curses_stdscr(); bkgdset(NUM2CH(ch)); #endif return Qnil; }
Returns true
or false
depending on whether the
terminal can change color attributes
Source: show
static VALUE curses_can_change_color(VALUE obj) { curses_stdscr(); return can_change_color() ? Qtrue : Qfalse; }
Put the terminal into cbreak mode.
Normally, the tty driver buffers typed characters until a newline or carriage return is typed. The ::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 ::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 ::cbreak or ::nocbreak explicitly. Most interactive programs using curses set the cbreak mode. Note that ::cbreak overrides ::raw.
see also ::raw
Source: show
static VALUE curses_cbreak(VALUE obj) { curses_stdscr(); cbreak(); return Qnil; }
Clears every position on the screen completely, so that a subsequent call by ::refresh for the screen/window will be repainted from scratch.
Source: show
static VALUE curses_clear(VALUE obj) { curses_stdscr(); wclear(stdscr); return Qnil; }
A program should always call ::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 ::refresh or ::doupdate after a temporary escape causes the program to resume visual mode.
Source: show
static VALUE curses_close_screen(void) { curses_stdscr(); #ifdef HAVE_ISENDWIN if (!isendwin()) #endif endwin(); rb_stdscr = 0; return Qnil; }
Returns true
if the window/screen has been closed, without any
subsequent ::refresh calls,
returns false
otherwise.
Source: show
static VALUE curses_closed(void) { curses_stdscr(); if (isendwin()) { return Qtrue; } return Qfalse; }
Clears to the end of line, that the cursor is currently on.
Source: show
static VALUE curses_clrtoeol(void) { curses_stdscr(); clrtoeol(); return Qnil; }
Returns an 3 item Array of the RGB values in color
Source: show
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)); }
Sets the color pair attributes to attrs
.
This should be equivalent to ::attrset(COLOR_PAIR(attrs
))
TODO: validate that equivalency
Source: show
static VALUE curses_color_pair(VALUE obj, VALUE attrs) { return INT2FIX(COLOR_PAIR(NUM2INT(attrs))); }
Returns the COLOR_PAIRS available, if the curses library supports it.
Source: show
static VALUE curses_color_pairs(VALUE obj) { return INT2FIX(COLOR_PAIRS); }
returns COLORS
Source: show
static VALUE curses_colors(VALUE obj) { return INT2FIX(COLORS); }
Returns the number of columns on the screen
Source: show
static VALUE curses_cols(void) { return INT2FIX(COLS); }
Put the terminal into cbreak mode.
Normally, the tty driver buffers typed characters until a newline or carriage return is typed. The ::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 ::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 ::cbreak or ::nocbreak explicitly. Most interactive programs using curses set the cbreak mode. Note that ::cbreak overrides ::raw.
see also ::raw
Source: show
static VALUE curses_cbreak(VALUE obj) { curses_stdscr(); cbreak(); return Qnil; }
Sets Cursor Visibility. 0: invisible 1: visible 2: very visible
Source: show
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 }
Save the current terminal modes as the “program” state for use by the ::reset_prog_mode
This is done automatically by ::init_screen
Source: show
static VALUE curses_def_prog_mode(VALUE obj) { curses_stdscr(); return def_prog_mode() == OK ? Qtrue : Qfalse; }
Delete the character under the cursor
Source: show
static VALUE curses_delch(VALUE obj) { curses_stdscr(); delch(); return Qnil; }
Delete the line under the cursor.
Source: show
static VALUE curses_deleteln(VALUE obj) { curses_stdscr(); #if defined(HAVE_DELETELN) || defined(deleteln) deleteln(); #endif return Qnil; }
Refreshes the windows and lines.
::doupdate allows multiple updates with more efficiency than ::refresh alone.
Source: show
static VALUE curses_doupdate(VALUE obj) { curses_stdscr(); #ifdef HAVE_DOUPDATE doupdate(); #else refresh(); #endif return Qnil; }
Enables characters typed by the user to be echoed by ::getch as they are typed.
Source: show
static VALUE curses_echo(VALUE obj) { curses_stdscr(); echo(); return Qnil; }
Flashs the screen, for visual alarm on the terminal, if possible; otherwise it sounds the alert.
see also ::beep
Source: show
static VALUE curses_flash(VALUE obj) { #ifdef HAVE_FLASH curses_stdscr(); flash(); #endif return Qnil; }
Read and returns a character from the window.
See Curses::Key to all the function KEY_* available
Source: show
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_locale_str_new(&ch, 1); } return UINT2NUM(c); }
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
Source: show
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; }
This is equivalent to a series f Curses::Window#getch calls
Source: show
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_locale_str_new_cstr(rtn); }
Returns true
or false
depending on whether the
terminal has color capbilities.
Source: show
static VALUE curses_has_colors(VALUE obj) { curses_stdscr(); return has_colors() ? Qtrue : Qfalse; }
Returns the character at the current position.
Source: show
static VALUE curses_inch(VALUE obj) { curses_stdscr(); return CH2FIX(inch()); }
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 ::init_color is used, all occurrences of that color on the screen immediately change to the new definition.
Source: show
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; }
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.
Source: show
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; }
Initialize a standard screen
see also ::stdscr
Source: show
static VALUE curses_init_screen(void) { rb_secure(4); if (rb_stdscr) return rb_stdscr; initscr(); if (stdscr == 0) { rb_raise(rb_eRuntimeError, "can't initialize curses"); } clear(); rb_stdscr = prep_window(cWindow, stdscr); return rb_stdscr; }
Insert a character ch
, before the cursor.
Source: show
static VALUE curses_insch(VALUE obj, VALUE ch) { curses_stdscr(); insch(NUM2CH(ch)); return Qnil; }
Inserts a line above the cursor, and the bottom line is lost
Source: show
static VALUE curses_insertln(VALUE obj) { curses_stdscr(); #if defined(HAVE_INSERTLN) || defined(insertln) insertln(); #endif return Qnil; }
Returns the character string corresponding to key c
Source: show
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 }
Returns the number of lines on the screen
Source: show
static VALUE curses_lines(void) { return INT2FIX(LINES); }
The ::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 ::mouseinterval to disable click resolution. This function returns the previous interval value.
Use ::mouseinterval to obtain the interval without altering it.
The default is one sixth of a second.
Source: show
static VALUE curses_mouseinterval(VALUE obj, VALUE interval) { curses_stdscr(); return mouseinterval(NUM2INT(interval)) ? Qtrue : Qfalse; }
Returns the mask
of the reportable events
Source: show
static VALUE curses_mousemask(VALUE obj, VALUE mask) { curses_stdscr(); return INT2NUM(mousemask(NUM2UINT(mask),NULL)); }
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 ::addch('n') does the equivalent of return and line feed on the virtual screen).
Initially, these translations do occur. If you disable them using ::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.
Source: show
static VALUE curses_nl(VALUE obj) { curses_stdscr(); nl(); return Qnil; }
Put the terminal into normal mode (out of cbreak mode).
See ::cbreak for more detail.
Source: show
static VALUE curses_nocbreak(VALUE obj) { curses_stdscr(); nocbreak(); return Qnil; }
Put the terminal into normal mode (out of cbreak mode).
See ::cbreak for more detail.
Source: show
static VALUE curses_nocbreak(VALUE obj) { curses_stdscr(); nocbreak(); return Qnil; }
Disables characters typed by the user to be echoed by ::getch as they are typed.
Source: show
static VALUE curses_noecho(VALUE obj) { curses_stdscr(); noecho(); return Qnil; }
Disable the underlying display device to translate the return key into newline on input
See ::nl for more detail
Source: show
static VALUE curses_nonl(VALUE obj) { curses_stdscr(); nonl(); return Qnil; }
Put the terminal out of raw mode.
see ::raw for more detail
Source: show
static VALUE curses_noraw(VALUE obj) { curses_stdscr(); noraw(); return Qnil; }
Returns a 2 item Array, with the foreground and background color, in
pair
Source: show
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)); }
Returns the Fixnum color pair number of
attributes attrs
.
Source: show
static VALUE curses_pair_number(VALUE obj, VALUE attrs) { curses_stdscr(); return INT2FIX(PAIR_NUMBER(NUM2LONG(attrs))); }
Put the terminal into raw mode.
Raw mode is similar to ::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.
Source: show
static VALUE curses_raw(VALUE obj) { curses_stdscr(); raw(); return Qnil; }
Refreshes the windows and lines.
Source: show
static VALUE curses_refresh(VALUE obj) { curses_stdscr(); refresh(); return Qnil; }
Reset the current terminal modes to the saved state by the ::def_prog_mode
This is done automatically by ::close_screen
Source: show
static VALUE curses_reset_prog_mode(VALUE obj) { curses_stdscr(); return reset_prog_mode() == OK ? Qtrue : Qfalse; }
Source: show
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 }
Source: show
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 }
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.
Source: show
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 }
A setter for the position of the cursor, using coordinates x
and y
Source: show
static VALUE curses_setpos(VALUE obj, VALUE y, VALUE x) { curses_stdscr(); move(NUM2INT(y), NUM2INT(x)); return Qnil; }
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.
Source: show
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 }
Enables the Normal display (no highlight)
This is equivalent to ::attron
see also Curses::Window#attrset for additional information.
Source: show
static VALUE curses_standend(VALUE obj) { curses_stdscr(); standend(); return Qnil; }
Enables the best highlighting mode of the terminal.
This is equivalent to Curses:Window.attron(A_STANDOUT)
see also Curses::Window#attrset additional information
Source: show
static VALUE curses_standout(VALUE obj) { curses_stdscr(); standout(); return Qnil; }
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 ::init_screen
Source: show
static VALUE curses_start_color(VALUE obj) { /* may have to raise exception on ERR */ curses_stdscr(); return (start_color() == OK) ? Qtrue : Qfalse; }
The Standard Screen.
Upon initializing curses, a default window called stdscr, which is the size of the terminal screen, is created.
Many curses functions use this window.
Source: show
#define curses_stdscr curses_init_screen
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.
Source: show
static VALUE curses_timeout(VALUE obj, VALUE delay) { curses_stdscr(); timeout(NUM2INT(delay)); return Qnil; }
Places ch
back onto the input queue to be returned by the next
call to ::getch.
There is just one input queue for all windows.
Source: show
static VALUE curses_ungetch(VALUE obj, VALUE ch) { int c = curses_char(ch); curses_stdscr(); ungetch(c); return Qnil; }
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 ::ungetmouse function behaves analogously to ::ungetch.
Source: show
static VALUE curses_ungetmouse(VALUE obj, VALUE mevent) { struct mousedata *mdata; curses_stdscr(); GetMOUSE(mevent,mdata); return (ungetmouse(mdata->mevent) == OK) ? Qtrue : Qfalse; }