Skip to content

Commit

Permalink
[ruby/io-console] [DOC] Add missing documents
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu authored and hsbt committed Dec 25, 2023
1 parent 4173c4b commit e7f91fd
Showing 1 changed file with 138 additions and 0 deletions.
138 changes: 138 additions & 0 deletions ext/io/console/console.c
Expand Up @@ -898,6 +898,16 @@ console_set_winsize(VALUE io, VALUE size)
#endif

#ifdef _WIN32
/*
* call-seq:
* io.check_winsize_changed { ... } -> io
*
* Yields while console input events are queued.
*
* This method is Windows only.
*
* You must require 'io/console' to use this method.
*/
static VALUE
console_check_winsize_changed(VALUE io)
{
Expand Down Expand Up @@ -984,6 +994,14 @@ console_ioflush(VALUE io)
return io;
}

/*
* call-seq:
* io.beep
*
* Beeps on the output console.
*
* You must require 'io/console' to use this method.
*/
static VALUE
console_beep(VALUE io)
{
Expand Down Expand Up @@ -1051,6 +1069,17 @@ console_scroll(VALUE io, int line)

#include "win32_vk.inc"

/*
* call-seq:
* io.pressed?(key) -> bool
*
* Returns +true+ if +key+ is pressed. +key+ may be a virtual key
* code or its name (String or Symbol) with out "VK_" prefix.
*
* This method is Windows only.
*
* You must require 'io/console' to use this method.
*/
static VALUE
console_key_pressed_p(VALUE io, VALUE k)
{
Expand Down Expand Up @@ -1194,6 +1223,14 @@ console_cursor_pos(VALUE io)
#endif
}

/*
* call-seq:
* io.goto(line, column) -> io
*
* Set the cursor position at +line+ and +column+.
*
* You must require 'io/console' to use this method.
*/
static VALUE
console_goto(VALUE io, VALUE y, VALUE x)
{
Expand Down Expand Up @@ -1240,6 +1277,15 @@ console_move(VALUE io, int y, int x)
return io;
}

/*
* call-seq:
* io.goto_column(column) -> io
*
* Set the cursor position at +column+ in the same line of the current
* position.
*
* You must require 'io/console' to use this method.
*/
static VALUE
console_goto_column(VALUE io, VALUE val)
{
Expand All @@ -1262,6 +1308,18 @@ console_goto_column(VALUE io, VALUE val)
return io;
}

/*
* call-seq:
* io.erase_line(mode) -> io
*
* Erases the line at the cursor corresponding to +mode+.
* +mode+ may be either:
* 0: after cursor
* 1: before and cursor
* 2: entire line
*
* You must require 'io/console' to use this method.
*/
static VALUE
console_erase_line(VALUE io, VALUE val)
{
Expand Down Expand Up @@ -1297,6 +1355,18 @@ console_erase_line(VALUE io, VALUE val)
return io;
}

/*
* call-seq:
* io.erase_screen(mode) -> io
*
* Erases the screen at the cursor corresponding to +mode+.
* +mode+ may be either:
* 0: after cursor
* 1: before and cursor
* 2: entire screen
*
* You must require 'io/console' to use this method.
*/
static VALUE
console_erase_screen(VALUE io, VALUE val)
{
Expand Down Expand Up @@ -1339,6 +1409,16 @@ console_erase_screen(VALUE io, VALUE val)
return io;
}

/*
* call-seq:
* io.cursor = [line, column] -> io
*
* Same as <tt>io.goto(line, column)</tt>
*
* See IO#goto.
*
* You must require 'io/console' to use this method.
*/
static VALUE
console_cursor_set(VALUE io, VALUE cpos)
{
Expand All @@ -1347,42 +1427,98 @@ console_cursor_set(VALUE io, VALUE cpos)
return console_goto(io, RARRAY_AREF(cpos, 0), RARRAY_AREF(cpos, 1));
}

/*
* call-seq:
* io.cursor_up(n) -> io
*
* Moves the cursor up +n+ lines.
*
* You must require 'io/console' to use this method.
*/
static VALUE
console_cursor_up(VALUE io, VALUE val)
{
return console_move(io, -NUM2INT(val), 0);
}

/*
* call-seq:
* io.cursor_down(n) -> io
*
* Moves the cursor down +n+ lines.
*
* You must require 'io/console' to use this method.
*/
static VALUE
console_cursor_down(VALUE io, VALUE val)
{
return console_move(io, +NUM2INT(val), 0);
}

/*
* call-seq:
* io.cursor_left(n) -> io
*
* Moves the cursor left +n+ columns.
*
* You must require 'io/console' to use this method.
*/
static VALUE
console_cursor_left(VALUE io, VALUE val)
{
return console_move(io, 0, -NUM2INT(val));
}

/*
* call-seq:
* io.cursor_right(n) -> io
*
* Moves the cursor right +n+ columns.
*
* You must require 'io/console' to use this method.
*/
static VALUE
console_cursor_right(VALUE io, VALUE val)
{
return console_move(io, 0, +NUM2INT(val));
}

/*
* call-seq:
* io.scroll_forward(n) -> io
*
* Scrolls the entire scrolls forward +n+ lines.
*
* You must require 'io/console' to use this method.
*/
static VALUE
console_scroll_forward(VALUE io, VALUE val)
{
return console_scroll(io, +NUM2INT(val));
}

/*
* call-seq:
* io.scroll_backward(n) -> io
*
* Scrolls the entire scrolls backward +n+ lines.
*
* You must require 'io/console' to use this method.
*/
static VALUE
console_scroll_backward(VALUE io, VALUE val)
{
return console_scroll(io, -NUM2INT(val));
}

/*
* call-seq:
* io.clear_screen -> io
*
* Clears the entire screen and moves the cursor top-left corner.
*
* You must require 'io/console' to use this method.
*/
static VALUE
console_clear_screen(VALUE io)
{
Expand Down Expand Up @@ -1677,7 +1813,9 @@ InitVM_console(void)
rb_define_method(rb_cIO, "getpass", console_getpass, -1);
rb_define_singleton_method(rb_cIO, "console", console_dev, -1);
{
/* :stopdoc: */
VALUE mReadable = rb_define_module_under(rb_cIO, "generic_readable");
/* :startdoc: */
rb_define_method(mReadable, "getch", io_getch, -1);
rb_define_method(mReadable, "getpass", io_getpass, -1);
}
Expand Down

0 comments on commit e7f91fd

Please sign in to comment.