Class: Curses::Window
- Inherits:
-
Object
- Object
- Curses::Window
- Defined in:
- ext/curses/curses.c,
ext/curses/curses.c
Overview
Description
The means by which to create and manage frames or windows. While there may be more than one window at a time, only one window will receive input.
Usage
require "curses"
Curses.init_screen
my_str = "LOOK! PONIES!"
height, width = 12, my_str.length + 10
top, left = (Curses.lines - height) / 2, (Curses.cols - width) / 2
bwin = Curses::Window.new(height, width, top, left)
bwin.box("\\", "/")
bwin.refresh
win = bwin.subwin(height - 4, width - 4, top + 2, left + 2)
win.setpos(2, 3)
win.addstr(my_str)
# or even
win << "\nOH REALLY?"
win << "\nYES!! " + my_str
win.refresh
win.getch
win.close
Direct Known Subclasses
Instance Method Summary collapse
-
#<<(str) ⇒ Object
call-seq: <<(str).
-
#addch(ch) ⇒ Object
Add a character
ch
, with attributes, to the window, then advance the cursor. -
#addstr(str) ⇒ Object
add a string of characters
str
, to the window and advance cursor. -
#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
. -
#begx ⇒ Object
A getter for the beginning column (X coord) of the window.
-
#begy ⇒ Object
A getter for the beginning line (Y coord) of the window.
-
#bkgd(ch) ⇒ Object
Set the background of the current window and apply character Integer
ch
to every character. -
#bkgdset(ch) ⇒ Object
Manipulate the background of the current window with character Integer
ch
. -
#box(vert = nil, hor = nil, corn = nil) ⇒ Object
set the characters to frame the window in.
-
#chgat(n, attrs) ⇒ Object
Changes the attributes of a given number of characters starting at the current cursor location.
-
#clear ⇒ Object
Clear the window.
-
#close ⇒ Object
Deletes the window, and frees the memory.
-
#clrtoeol ⇒ Object
Clear the window to the end of line, that the cursor is currently on.
-
#color_set(col) ⇒ Object
Sets the current color of the given window to the foreground/background combination described by the Fixnum
col
. -
#curx ⇒ Object
A getter for the current column (X coord) of the window.
-
#cury ⇒ Object
A getter for the current line (Y coord) of the window.
-
#delch ⇒ Object
Delete the character under the cursor.
-
#deleteln ⇒ Object
Delete the line under the cursor.
-
#derwin(height, width, relative_top, relative_left) ⇒ Object
Construct a new subwindow with constraints of
height
lines,width
columns, begin attop
line, and beginleft
most column relative to the parent window. -
#erase ⇒ Object
Erase the window.
-
#get_char ⇒ Object
Read and returns a character or function key from the window.
-
#getbkgd ⇒ Object
Returns an Integer (
ch
) for the character property in the current window. -
#getch ⇒ Object
Read and returns a character from the window.
-
#getstr ⇒ Object
This is equivalent to a series of Curses::Window.getch calls.
-
#idlok(bool) ⇒ Object
If
bool
istrue
curses considers using the hardware insert/delete line feature of terminals so equipped. -
#inch ⇒ Object
Returns the character at the current position of the window.
-
#new(height, width, top, left) ⇒ Object
constructor
Construct a new Curses::Window with constraints of
height
lines,width
columns, begin attop
line, and beginleft
most column. -
#insch(ch) ⇒ Object
Insert a character
ch
, before the cursor, in the current window. -
#insertln ⇒ Object
Inserts a line above the cursor, and the bottom line is lost.
-
#keypad(bool) ⇒ Object
Enables the keypad of the user’s terminal.
-
#keypad(bool) ⇒ Object
Enables the keypad of the user’s terminal.
-
#line_touched?(line) ⇒ Boolean
Return true if the specified line has been modified since the last call of refresh.
-
#maxx ⇒ Object
A getter for the maximum columns for the window.
-
#maxy ⇒ Object
A getter for the maximum lines for the window.
-
#move(y, x) ⇒ Object
Moves the window so that the upper left-hand corner is at position (
y
,x
). -
#move_relative(x, y) ⇒ Object
Moves the derived or subwindow inside its parent window.
-
#nodelay=(bool) ⇒ Object
When in no-delay mode Curses::Window#getch is a non-blocking call.
-
#noutrefresh ⇒ Object
Refreshes the windows and lines.
-
#redraw ⇒ Object
Redraws the entire window.
-
#refresh ⇒ Object
Refreshes the windows and lines.
-
#resize(lines, cols) ⇒ Object
Resize the current window to Fixnum
lines
and Fixnumcols
. -
#scrl(num) ⇒ Object
Scrolls the current window Fixnum
num
lines. -
#scroll ⇒ Object
Scrolls the current window up one line.
-
#scrollok(bool) ⇒ Object
Controls what happens when the cursor of a window is moved off the edge of the window or scrolling region, either as a result of a newline action on the bottom line, or typing the last character of the last line.
-
#setpos(y, x) ⇒ Object
A setter for the position of the cursor in the current window, using coordinates
x
andy
. -
#setscrreg(top, bottom) ⇒ Object
Set a software scrolling region in a window.
-
#standend ⇒ Object
Enables the Normal display (no highlight).
-
#standout ⇒ Object
Enables the best highlighting mode of the terminal.
-
#subwin(height, width, top, left) ⇒ Object
Construct a new subwindow with constraints of
height
lines,width
columns, begin attop
line, and beginleft
most column. -
#timeout=(delay) ⇒ Object
Sets block and non-blocking reads for the window.
-
#touch ⇒ Object
Treat the window as if it has been modified since the last call of refresh.
-
#touch_line(y, n, changed = true) ⇒ Object
Make n lines from line y look as if they have (changed = true) or have not (changed = false) been modified since the last call of refresh.
-
#touched? ⇒ Boolean
Return true if the window has been modified since the last call of refresh.
-
#untouch ⇒ Object
Treat the window as if it has not been modified since the last call of refresh.
Constructor Details
#new(height, width, top, left) ⇒ Object
Construct a new Curses::Window with constraints of height
lines, width
columns, begin at top
line, and begin left
most column.
A new window using full screen is called as Curses::Window.new(0,0,0,0)
1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 |
# File 'ext/curses/curses.c', line 1830
static VALUE
window_initialize(VALUE obj, VALUE h, VALUE w, VALUE top, VALUE left)
{
struct windata *winp;
WINDOW *window;
curses_init_screen(Qnil);
TypedData_Get_Struct(obj, struct windata, &windata_type, winp);
if (winp->window) delwin(winp->window);
window = newwin(NUM2INT(h), NUM2INT(w), NUM2INT(top), NUM2INT(left));
wclear(window);
winp->window = window;
return obj;
}
|
Instance Method Details
#<<(str) ⇒ Object
call-seq:
<<(str)
Add String str
to the current string.
See also Curses::Window.addstr
2503 2504 2505 2506 2507 2508 |
# File 'ext/curses/curses.c', line 2503
static VALUE
window_addstr2(VALUE obj, VALUE str)
{
window_addstr(obj, str);
return obj;
}
|
#addch(ch) ⇒ Object
Add a character ch
, with attributes, to the window, then advance the cursor.
see also the system manual for curs_addch(3)
2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 |
# File 'ext/curses/curses.c', line 2437
static VALUE
window_addch(VALUE obj, VALUE ch)
{
struct windata *winp;
GetWINDOW(obj, winp);
waddch(winp->window, OBJ2CHTYPE(ch));
return Qnil;
}
|
#addstr(str) ⇒ Object
add a string of characters str
, to the window and advance cursor
2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 |
# File 'ext/curses/curses.c', line 2473
static VALUE
window_addstr(VALUE obj, VALUE str)
{
if (!NIL_P(str)) {
struct windata *winp;
StringValue(str);
#if defined(HAVE_WADDNWSTR) && defined(_WIN32)
str = rb_str_export_to_enc(str, get_wide_encoding());
GetWINDOW(obj, winp);
waddnwstr(winp->window, (wchar_t *)RSTRING_PTR(str), RSTRING_LEN(str) / sizeof(wchar_t));
#else
str = rb_str_export_to_enc(str, terminal_encoding);
GetWINDOW(obj, winp);
waddstr(winp->window, StringValueCStr(str));
#endif
}
return Qnil;
}
|
#attroff(attrs) ⇒ Object
Turns off the named attributes attrs
without affecting any others.
See also Curses::Window.attrset
2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 |
# File 'ext/curses/curses.c', line 2790
static VALUE
window_attroff(VALUE obj, VALUE attrs)
{
#ifdef HAVE_WATTROFF
struct windata *winp;
GetWINDOW(obj,winp);
return INT2FIX(wattroff(winp->window,NUM2CHTYPE(attrs)));
#else
return Qtrue;
#endif
}
|
#attron(attrs) ⇒ Object
Turns on the named attributes attrs
without turning any other attributes on or off.
See also Curses::Window.attrset
2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 |
# File 'ext/curses/curses.c', line 2812
static VALUE
window_attron(VALUE obj, VALUE attrs)
{
#ifdef HAVE_WATTRON
struct windata *winp;
VALUE val;
GetWINDOW(obj,winp);
val = INT2FIX(wattron(winp->window,NUM2CHTYPE(attrs)));
if (rb_block_given_p()) {
rb_yield(val);
wattroff(winp->window,NUM2CHTYPE(attrs));
return val;
}
else{
return val;
}
#else
return Qtrue;
#endif
}
|
#attrset(attrs) ⇒ Object
Sets the current attributes of the given window to attrs
.
The following video attributes, defined in <curses.h>, can be passed to the routines Curses::Window.attron, Curses::Window.attroff, and Curses::Window.attrset, or OR’d with the characters passed to addch.
A_NORMAL Normal display (no highlight)
A_STANDOUT Best highlighting mode of the terminal.
A_UNDERLINE Underlining
A_REVERSE Reverse video
A_BLINK Blinking
A_DIM Half bright
A_BOLD Extra bright or bold
A_PROTECT Protected mode
A_INVIS Invisible or blank mode
A_ALTCHARSET Alternate character set
A_CHARTEXT Bit-mask to extract a character
COLOR_PAIR(n) Color-pair number n
TODO: provide some examples here.
see also system manual curs_attr(3)
2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 |
# File 'ext/curses/curses.c', line 2860
static VALUE
window_attrset(VALUE obj, VALUE attrs)
{
#ifdef HAVE_WATTRSET
struct windata *winp;
GetWINDOW(obj,winp);
return INT2FIX(wattrset(winp->window,NUM2CHTYPE(attrs)));
#else
return Qtrue;
#endif
}
|
#begx ⇒ Object
A getter for the beginning column (X coord) of the window
2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 |
# File 'ext/curses/curses.c', line 2316
static VALUE
window_begx(VALUE obj)
{
struct windata *winp;
int x, RB_UNUSED_VAR(y);
GetWINDOW(obj, winp);
#ifdef getbegyx
getbegyx(winp->window, y, x);
#else
x = winp->window->_begx;
#endif
return INT2FIX(x);
}
|
#begy ⇒ Object
A getter for the beginning line (Y coord) of the window
2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 |
# File 'ext/curses/curses.c', line 2296
static VALUE
window_begy(VALUE obj)
{
struct windata *winp;
int RB_UNUSED_VAR(x), y;
GetWINDOW(obj, winp);
#ifdef getbegyx
getbegyx(winp->window, y, x);
#else
y = winp->window->_begy;
#endif
return INT2FIX(y);
}
|
#bkgd(ch) ⇒ Object
Set the background of the current window and apply character Integer ch
to every character.
see also Curses.bkgd
2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 |
# File 'ext/curses/curses.c', line 2903
static VALUE
window_bkgd(VALUE obj, VALUE ch)
{
#ifdef HAVE_WBKGD
struct windata *winp;
GetWINDOW(obj,winp);
return (wbkgd(winp->window, OBJ2CHTYPE(ch)) == OK) ? Qtrue : Qfalse;
#else
return Qfalse;
#endif
}
|
#bkgdset(ch) ⇒ Object
Manipulate the background of the current window with character Integer ch
see also Curses.bkgdset
2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 |
# File 'ext/curses/curses.c', line 2882
static VALUE
window_bkgdset(VALUE obj, VALUE ch)
{
#ifdef HAVE_WBKGDSET
struct windata *winp;
GetWINDOW(obj,winp);
wbkgdset(winp->window, OBJ2CHTYPE(ch));
#endif
return Qnil;
}
|
#box(vert = nil, hor = nil, corn = nil) ⇒ Object
set the characters to frame the window in. The vertical vert
and horizontal hor
character.
win = Curses::Window.new(5,5,5,5) win.box(?|, ?-)
2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 |
# File 'ext/curses/curses.c', line 2342
static VALUE
window_box(int argc, VALUE *argv, VALUE self)
{
struct windata *winp;
VALUE vert, hor, corn;
rb_scan_args(argc, argv, "03", &vert, &hor, &corn);
GetWINDOW(self, winp);
box(winp->window,
NIL_P(vert) ? 0 : OBJ2CHTYPE(vert),
NIL_P(hor) ? 0 : OBJ2CHTYPE(hor));
if (!NIL_P(corn)) {
int cur_x, cur_y, x, y;
chtype c;
c = OBJ2CHTYPE(corn);
getyx(winp->window, cur_y, cur_x);
x = NUM2INT(window_maxx(self)) - 1;
y = NUM2INT(window_maxy(self)) - 1;
wmove(winp->window, 0, 0);
waddch(winp->window, c);
wmove(winp->window, y, 0);
waddch(winp->window, c);
wmove(winp->window, y, x);
waddch(winp->window, c);
wmove(winp->window, 0, x);
waddch(winp->window, c);
wmove(winp->window, cur_y, cur_x);
}
return Qnil;
}
|
#chgat(n, attrs) ⇒ Object
Changes the attributes of a given number of characters starting at the current cursor location.
2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 |
# File 'ext/curses/curses.c', line 2942
static VALUE
window_chgat(VALUE obj, VALUE n, VALUE attrs)
{
#ifdef HAVE_WCHGAT
chtype a = NUM2CHTYPE(attrs);
attr_t attr;
short pair;
struct windata *winp;
GetWINDOW(obj,winp);
attr = a & A_ATTRIBUTES;
pair = PAIR_NUMBER(attr);
return (wchgat(winp->window, NUM2INT(n), attr, pair, NULL) == OK) ? Qtrue : Qfalse;
#else
return Qnil;
#endif
}
|
#clear ⇒ Object
Clear the window.
1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 |
# File 'ext/curses/curses.c', line 1927
static VALUE
window_clear(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
wclear(winp->window);
return Qnil;
}
|
#close ⇒ Object
Deletes the window, and frees the memory
1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 |
# File 'ext/curses/curses.c', line 1910
static VALUE
window_close(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
delwin(winp->window);
winp->window = 0;
return Qnil;
}
|
#clrtoeol ⇒ Object
Clear the window to the end of line, that the cursor is currently on.
1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 |
# File 'ext/curses/curses.c', line 1963
static VALUE
window_clrtoeol(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
wclrtoeol(winp->window);
return Qnil;
}
|
#color_set(col) ⇒ Object
Sets the current color of the given window to the foreground/background combination described by the Fixnum col
.
2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 |
# File 'ext/curses/curses.c', line 2728
static VALUE
window_color_set(VALUE obj, VALUE col)
{
struct windata *winp;
int res;
GetWINDOW(obj, winp);
res = wcolor_set(winp->window, NUM2INT(col), NULL);
return (res == OK) ? Qtrue : Qfalse;
}
|
#curx ⇒ Object
A getter for the current column (X coord) of the window
2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 |
# File 'ext/curses/curses.c', line 2232
static VALUE
window_curx(VALUE obj)
{
struct windata *winp;
int x, RB_UNUSED_VAR(y);
GetWINDOW(obj, winp);
getyx(winp->window, y, x);
return INT2FIX(x);
}
|
#cury ⇒ Object
A getter for the current line (Y coord) of the window
2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 |
# File 'ext/curses/curses.c', line 2216
static VALUE
window_cury(VALUE obj)
{
struct windata *winp;
int RB_UNUSED_VAR(x), y;
GetWINDOW(obj, winp);
getyx(winp->window, y, x);
return INT2FIX(y);
}
|
#delch ⇒ Object
Delete the character under the cursor
2593 2594 2595 2596 2597 2598 2599 2600 2601 |
# File 'ext/curses/curses.c', line 2593
static VALUE
window_delch(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
wdelch(winp->window);
return Qnil;
}
|
#deleteln ⇒ Object
Delete the line under the cursor.
2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 |
# File 'ext/curses/curses.c', line 2609
static VALUE
window_deleteln(VALUE obj)
{
#if defined(HAVE_WDELETELN) || defined(wdeleteln)
struct windata *winp;
GetWINDOW(obj, winp);
wdeleteln(winp->window);
#endif
return Qnil;
}
|
#derwin(height, width, relative_top, relative_left) ⇒ Object
Construct a new subwindow with constraints of height
lines, width
columns, begin at top
line, and begin left
most column relative to the parent window.
1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 |
# File 'ext/curses/curses.c', line 1883
static VALUE
window_derwin(VALUE obj, VALUE height, VALUE width, VALUE top, VALUE left)
{
struct windata *winp;
WINDOW *window;
VALUE win;
int h, w, t, l;
h = NUM2INT(height);
w = NUM2INT(width);
t = NUM2INT(top);
l = NUM2INT(left);
GetWINDOW(obj, winp);
window = derwin(winp->window, h, w, t, l);
win = prep_window(rb_obj_class(obj), window, 0);
return win;
}
|
#erase ⇒ Object
Erase the window.
1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 |
# File 'ext/curses/curses.c', line 1944
static VALUE
window_erase(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
werase(winp->window);
return Qnil;
}
|
#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
4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 |
# File 'ext/curses/curses.c', line 4871
static VALUE
window_get_char(VALUE obj)
{
#ifdef HAVE_WGET_WCH
struct windata *winp;
struct wget_wch_arg arg;
GetWINDOW(obj, winp);
arg.win = winp->window;
rb_thread_call_without_gvl(wget_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
struct windata *winp;
struct wgetch_arg arg;
GetWINDOW(obj, winp);
arg.win = winp->window;
rb_thread_call_without_gvl(wgetch_func, (void *)&arg, RUBY_UBF_IO, 0);
if (arg.c > 0xff) {
return INT2NUM(arg.c);
}
else if (arg.c >= 0) {
return keyboard_uint_chr(arg.c);
}
else {
return Qnil;
}
#endif
}
|
#getbkgd ⇒ Object
Returns an Integer (ch
) for the character property in the current window.
2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 |
# File 'ext/curses/curses.c', line 2921
static VALUE
window_getbkgd(VALUE obj)
{
#ifdef HAVE_WGETBKGD
chtype c;
struct windata *winp;
GetWINDOW(obj,winp);
return (c = getbkgd(winp->window) != ERR) ? ULONG2NUM(c) : Qnil;
#else
return Qnil;
#endif
}
|
#getch ⇒ Object
Read and returns a character from the window.
See Curses::Key to all the function KEY_* available
2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 |
# File 'ext/curses/curses.c', line 2531
static VALUE
window_getch(VALUE obj)
{
struct windata *winp;
struct wgetch_arg arg;
int c;
GetWINDOW(obj, winp);
arg.win = winp->window;
rb_thread_call_without_gvl(wgetch_func, (void *)&arg, RUBY_UBF_IO, 0);
c = arg.c;
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);
}
|
#getstr ⇒ Object
This is equivalent to a series of Curses::Window.getch calls
2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 |
# File 'ext/curses/curses.c', line 2574
static VALUE
window_getstr(VALUE obj)
{
struct windata *winp;
struct wgetstr_arg arg;
GetWINDOW(obj, winp);
arg.win = winp->window;
rb_thread_call_without_gvl(wgetstr_func, (void *)&arg, RUBY_UBF_IO, 0);
return rb_external_str_new_with_enc(arg.rtn, strlen(arg.rtn),
keyboard_encoding);
}
|
#idlok(bool) ⇒ Object
If bool
is true
curses considers using the hardware insert/delete line feature of terminals so equipped.
If bool
is false
, disables use of line insertion and deletion. This option should be enabled only if the application needs insert/delete line, for example, for a screen editor.
It is disabled by default because insert/delete line tends to be visually annoying when used in applications where it is not really needed. If insert/delete line cannot be used, curses redraws the changed portions of all lines.
2680 2681 2682 2683 2684 2685 2686 2687 2688 |
# File 'ext/curses/curses.c', line 2680
static VALUE
window_idlok(VALUE obj, VALUE bf)
{
struct windata *winp;
GetWINDOW(obj, winp);
idlok(winp->window, RTEST(bf) ? TRUE : FALSE);
return Qnil;
}
|
#inch ⇒ Object
Returns the character at the current position of the window.
2420 2421 2422 2423 2424 2425 2426 2427 |
# File 'ext/curses/curses.c', line 2420
static VALUE
window_inch(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
return CHTYPE2NUM(winch(winp->window));
}
|
#insch(ch) ⇒ Object
Insert a character ch
, before the cursor, in the current window
2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 |
# File 'ext/curses/curses.c', line 2455
static VALUE
window_insch(VALUE obj, VALUE ch)
{
struct windata *winp;
GetWINDOW(obj, winp);
winsch(winp->window, OBJ2CHTYPE(ch));
return Qnil;
}
|
#insertln ⇒ Object
Inserts a line above the cursor, and the bottom line is lost
2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 |
# File 'ext/curses/curses.c', line 2627
static VALUE
window_insertln(VALUE obj)
{
#if defined(HAVE_WINSERTLN) || defined(winsertln)
struct windata *winp;
GetWINDOW(obj, winp);
winsertln(winp->window);
#endif
return Qnil;
}
|
#keypad(bool) ⇒ Object
Enables the keypad of the user’s terminal.
If enabled (bool
is true
), the user can press a function key (such as an arrow key) and wgetch returns a single value representing the function key, as in KEY_LEFT. If disabled (bool
is false
), curses does not treat function keys specially and the program has to interpret the escape sequences itself. If the keypad in the terminal can be turned on (made to transmit) and off (made to work locally), turning on this option causes the terminal keypad to be turned on when Curses::Window.getch is called.
The default value for keypad is false.
3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 |
# File 'ext/curses/curses.c', line 3009
static VALUE
window_keypad(VALUE obj, VALUE val)
{
struct windata *winp;
GetWINDOW(obj,winp);
/* keypad() of NetBSD's libcurses returns no value */
#if defined(__NetBSD__) && !defined(NCURSES_VERSION)
keypad(winp->window,(RTEST(val) ? TRUE : FALSE));
return Qnil;
#else
/* may have to raise exception on ERR */
return (keypad(winp->window,RTEST(val) ? TRUE : FALSE)) == OK ?
Qtrue : Qfalse;
#endif
}
|
#keypad(bool) ⇒ Object
Enables the keypad of the user’s terminal.
If enabled (bool
is true
), the user can press a function key (such as an arrow key) and wgetch returns a single value representing the function key, as in KEY_LEFT. If disabled (bool
is false
), curses does not treat function keys specially and the program has to interpret the escape sequences itself. If the keypad in the terminal can be turned on (made to transmit) and off (made to work locally), turning on this option causes the terminal keypad to be turned on when Curses::Window.getch is called.
The default value for keypad is false.
3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 |
# File 'ext/curses/curses.c', line 3009
static VALUE
window_keypad(VALUE obj, VALUE val)
{
struct windata *winp;
GetWINDOW(obj,winp);
/* keypad() of NetBSD's libcurses returns no value */
#if defined(__NetBSD__) && !defined(NCURSES_VERSION)
keypad(winp->window,(RTEST(val) ? TRUE : FALSE));
return Qnil;
#else
/* may have to raise exception on ERR */
return (keypad(winp->window,RTEST(val) ? TRUE : FALSE)) == OK ?
Qtrue : Qfalse;
#endif
}
|
#line_touched?(line) ⇒ Boolean
Return true if the specified line has been modified since the last call of refresh.
2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 |
# File 'ext/curses/curses.c', line 2135
static VALUE
window_line_touched(VALUE obj, VALUE line)
{
struct windata *winp;
int result, n;
GetWINDOW(obj, winp);
n = NUM2INT(line);
result = is_linetouched(winp->window, n);
if (result == ERR) {
rb_raise(rb_eArgError, "Invalid line %d", n);
}
return result ? Qtrue : Qfalse;
}
|
#maxx ⇒ Object
A getter for the maximum columns for the window
2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 |
# File 'ext/curses/curses.c', line 2272
static VALUE
window_maxx(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
#if defined(getmaxx)
return INT2FIX(getmaxx(winp->window));
#elif defined(getmaxyx)
{
int x, RB_UNUSED_VAR(y);
getmaxyx(winp->window, y, x);
return INT2FIX(x);
}
#else
return INT2FIX(winp->window->_maxx+1);
#endif
}
|
#maxy ⇒ Object
A getter for the maximum lines for the window
2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 |
# File 'ext/curses/curses.c', line 2248
static VALUE
window_maxy(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
#if defined(getmaxy)
return INT2FIX(getmaxy(winp->window));
#elif defined(getmaxyx)
{
int RB_UNUSED_VAR(x), y;
getmaxyx(winp->window, y, x);
return INT2FIX(y);
}
#else
return INT2FIX(winp->window->_maxy+1);
#endif
}
|
#move(y, x) ⇒ Object
Moves the window so that the upper left-hand corner is at position (y
, x
)
2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 |
# File 'ext/curses/curses.c', line 2159
static VALUE
window_move(VALUE obj, VALUE y, VALUE x)
{
struct windata *winp;
GetWINDOW(obj, winp);
mvwin(winp->window, NUM2INT(y), NUM2INT(x));
return Qnil;
}
|
#move_relative(x, y) ⇒ Object
Moves the derived or subwindow inside its parent window. The screen-relative parameters of the window are not changed.
2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 |
# File 'ext/curses/curses.c', line 2178
static VALUE
window_move_relative(VALUE obj, VALUE y, VALUE x)
{
struct windata *winp;
GetWINDOW(obj, winp);
mvderwin(winp->window, NUM2INT(y), NUM2INT(x));
return Qnil;
}
|
#nodelay=(bool) ⇒ Object
When in no-delay mode Curses::Window#getch is a non-blocking call. If no input is ready #getch returns ERR.
When in delay mode (bool
is false
which is the default), Curses::Window#getch blocks until a key is pressed.
3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 |
# File 'ext/curses/curses.c', line 3042
static VALUE
window_nodelay(VALUE obj, VALUE val)
{
struct windata *winp;
GetWINDOW(obj,winp);
/* nodelay() of NetBSD's libcurses returns no value */
#if defined(__NetBSD__) && !defined(NCURSES_VERSION)
nodelay(winp->window, RTEST(val) ? TRUE : FALSE);
return Qnil;
#else
return nodelay(winp->window,RTEST(val) ? TRUE : FALSE) == OK ? Qtrue : Qfalse;
#endif
}
|
#noutrefresh ⇒ Object
Refreshes the windows and lines.
Curses::Window.noutrefresh allows multiple updates with more efficiency than Curses::Window.refresh alone.
1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 |
# File 'ext/curses/curses.c', line 1999
static VALUE
window_noutrefresh(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
#ifdef HAVE_DOUPDATE
wnoutrefresh(winp->window);
#else
wrefresh(winp->window);
#endif
return Qnil;
}
|
#redraw ⇒ Object
Redraws the entire window.
2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 |
# File 'ext/curses/curses.c', line 2020
static VALUE
window_redraw(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
redrawwin(winp->window);
return Qnil;
}
|
#refresh ⇒ Object
Refreshes the windows and lines.
1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 |
# File 'ext/curses/curses.c', line 1980
static VALUE
window_refresh(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
wrefresh(winp->window);
return Qnil;
}
|
#resize(lines, cols) ⇒ Object
Resize the current window to Fixnum lines
and Fixnum cols
2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 |
# File 'ext/curses/curses.c', line 2967
static VALUE
window_resize(VALUE obj, VALUE lin, VALUE col)
{
#if defined(HAVE_WRESIZE)
struct windata *winp;
GetWINDOW(obj,winp);
return wresize(winp->window, NUM2INT(lin), NUM2INT(col)) == OK ? Qtrue : Qfalse;
#else
return Qnil;
#endif
}
|
#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.
2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 |
# File 'ext/curses/curses.c', line 2767
static VALUE
window_scrl(VALUE obj, VALUE n)
{
#ifdef HAVE_WSCRL
struct windata *winp;
GetWINDOW(obj, winp);
/* may have to raise exception on ERR */
return (wscrl(winp->window,NUM2INT(n)) == OK) ? Qtrue : Qfalse;
#else
return Qfalse;
#endif
}
|
#scroll ⇒ Object
Scrolls the current window up one line.
2745 2746 2747 2748 2749 2750 2751 2752 2753 |
# File 'ext/curses/curses.c', line 2745
static VALUE
window_scroll(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
/* may have to raise exception on ERR */
return (scroll(winp->window) == OK) ? Qtrue : Qfalse;
}
|
#scrollok(bool) ⇒ Object
Controls what happens when the cursor of a window is moved off the edge of the window or scrolling region, either as a result of a newline action on the bottom line, or typing the last character of the last line.
If disabled, (bool
is false), the cursor is left on the bottom line.
If enabled, (bool
is true), the window is scrolled up one line (Note that to get the physical scrolling effect on the terminal, it is also necessary to call Curses::Window.idlok)
2654 2655 2656 2657 2658 2659 2660 2661 2662 |
# File 'ext/curses/curses.c', line 2654
static VALUE
window_scrollok(VALUE obj, VALUE bf)
{
struct windata *winp;
GetWINDOW(obj, winp);
scrollok(winp->window, RTEST(bf) ? TRUE : FALSE);
return Qnil;
}
|
#setpos(y, x) ⇒ Object
A setter for the position of the cursor in the current window, using coordinates x
and y
2201 2202 2203 2204 2205 2206 2207 2208 2209 |
# File 'ext/curses/curses.c', line 2201
static VALUE
window_setpos(VALUE obj, VALUE y, VALUE x)
{
struct windata *winp;
GetWINDOW(obj, winp);
wmove(winp->window, NUM2INT(y), NUM2INT(x));
return Qnil;
}
|
#setscrreg(top, bottom) ⇒ Object
Set a software scrolling region in a window. top
and bottom
are lines numbers of the margin.
If this option and Curses::Window.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.
2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 |
# File 'ext/curses/curses.c', line 2704
static VALUE
window_setscrreg(VALUE obj, VALUE top, VALUE bottom)
{
#ifdef HAVE_WSETSCRREG
struct windata *winp;
int res;
GetWINDOW(obj, winp);
res = wsetscrreg(winp->window, NUM2INT(top), NUM2INT(bottom));
/* may have to raise exception on ERR */
return (res == OK) ? Qtrue : Qfalse;
#else
return Qfalse;
#endif
}
|
#standend ⇒ Object
Enables the Normal display (no highlight)
This is equivalent to Curses::Window.attron(A_NORMAL)
see also Curses::Window.attrset
2405 2406 2407 2408 2409 2410 2411 2412 2413 |
# File 'ext/curses/curses.c', line 2405
static VALUE
window_standend(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
wstandend(winp->window);
return Qnil;
}
|
#standout ⇒ Object
Enables the best highlighting mode of the terminal.
This is equivalent to Curses::Window.attron(A_STANDOUT)
see also Curses::Window.attrset
2386 2387 2388 2389 2390 2391 2392 2393 2394 |
# File 'ext/curses/curses.c', line 2386
static VALUE
window_standout(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
wstandout(winp->window);
return Qnil;
}
|
#subwin(height, width, top, left) ⇒ Object
Construct a new subwindow with constraints of height
lines, width
columns, begin at top
line, and begin left
most column.
1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 |
# File 'ext/curses/curses.c', line 1854
static VALUE
window_subwin(VALUE obj, VALUE height, VALUE width, VALUE top, VALUE left)
{
struct windata *winp;
WINDOW *window;
VALUE win;
int h, w, t, l;
h = NUM2INT(height);
w = NUM2INT(width);
t = NUM2INT(top);
l = NUM2INT(left);
GetWINDOW(obj, winp);
window = subwin(winp->window, h, w, t, l);
win = prep_window(rb_obj_class(obj), window, 0);
return win;
}
|
#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.
3071 3072 3073 3074 3075 3076 3077 3078 3079 |
# File 'ext/curses/curses.c', line 3071
static VALUE
window_timeout(VALUE obj, VALUE delay)
{
struct windata *winp;
GetWINDOW(obj,winp);
wtimeout(winp->window,NUM2INT(delay));
return Qnil;
}
|
#touch ⇒ Object
Treat the window as if it has been modified since the last call of refresh.
2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 |
# File 'ext/curses/curses.c', line 2040
static VALUE
window_touch(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
touchwin(winp->window);
return Qnil;
}
|
#touch_line(y, n, changed = true) ⇒ Object
Make n lines from line y look as if they have (changed = true) or have not (changed = false) been modified since the last call of refresh.
2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 |
# File 'ext/curses/curses.c', line 2101
static VALUE
window_touch_line(int argc, VALUE *argv, VALUE obj)
{
struct windata *winp;
VALUE y, n, changed;
int result;
rb_scan_args(argc, argv, "12", &y, &n, &changed);
if (argc < 2) {
n = INT2NUM(1);
}
if (argc < 3) {
changed = Qtrue;
}
GetWINDOW(obj, winp);
result = wtouchln(winp->window, NUM2INT(y), NUM2INT(n), RTEST(changed));
if (result == ERR) {
rb_raise(rb_eRangeError, "Out of window");
}
return Qnil;
}
|
#touched? ⇒ Boolean
Return true if the window has been modified since the last call of refresh.
2081 2082 2083 2084 2085 2086 2087 2088 |
# File 'ext/curses/curses.c', line 2081
static VALUE
window_touched(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
return is_wintouched(winp->window) ? Qtrue : Qfalse;
}
|
#untouch ⇒ Object
Treat the window as if it has not been modified since the last call of refresh.
2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 |
# File 'ext/curses/curses.c', line 2061
static VALUE
window_untouch(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
untouchwin(winp->window);
return Qnil;
}
|