Class: Curses::Screen

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

Overview

Description

A Screen represents a terminal. A program that outputs to more than one terminal should create a Screen

for each terminal instead of calling Curses.init_screen.

Usage

require "curses"

screen = Screen.new(STDOUT, STDIN, "xterm")
screen.set_term

Curses.addstr("Hit any key")
Curses.refresh
Curses.getch
Curses.close_screen

Instance Method Summary collapse

Constructor Details

#new(outf, inf, type = nil) ⇒ Object

Construct a new Curses::Screen.



1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
# File 'ext/curses/curses.c', line 1761

static VALUE
screen_initialize(int argc, VALUE *argv, VALUE obj)
{
    VALUE outf, inf, type;
    struct screendata *screenp;
    rb_io_t *outfptr, *infptr;

    rb_scan_args(argc, argv, "21", &outf, &inf, &type);
    TypedData_Get_Struct(obj, struct screendata, &screendata_type, screenp);
    if (screenp->screen) delscreen(screenp->screen);
    Check_Type(outf, T_FILE);
    RB_IO_POINTER(outf, outfptr);
    rb_io_check_writable(outfptr);
    Check_Type(inf, T_FILE);
    RB_IO_POINTER(inf, infptr);
    rb_io_check_readable(infptr);
    screenp->screen = newterm(NIL_P(type) ? NULL : StringValueCStr(type),
                              rb_io_stdio_file(outfptr),
                              rb_io_stdio_file(infptr));
    screenp->stdscr = Qnil;

    return obj;
}

Instance Method Details

#set_termObject

Set the current terminal.



1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
# File 'ext/curses/curses.c', line 1791

static VALUE
screen_set_term(VALUE obj)
{
    struct screendata *screenp;

    GetSCREEN(obj, screenp);
    set_term(screenp->screen);
    if (NIL_P(screenp->stdscr)) {
        screenp->stdscr = prep_window(cWindow, stdscr, 1);
    }
    rb_stdscr = screenp->stdscr;

    return Qnil;
}