ruby-changes:38343
From: nobu <ko1@a...>
Date: Mon, 4 May 2015 03:11:41 +0900 (JST)
Subject: [ruby-changes:38343] nobu:r50424 (trunk): console.c: IO#beep
nobu 2015-05-04 03:11:25 +0900 (Mon, 04 May 2015) New Revision: 50424 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50424 Log: console.c: IO#beep * ext/io/console/console.c (console_beep): new method IO#beep. [EXPERIMENTAL] Modified files: trunk/ext/io/console/console.c Index: ext/io/console/console.c =================================================================== --- ext/io/console/console.c (revision 50423) +++ ext/io/console/console.c (revision 50424) @@ -639,6 +639,24 @@ console_ioflush(VALUE io) https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L639 return io; } +static VALUE +console_beep(VALUE io) +{ + rb_io_t *fptr; + int fd; + + GetOpenFile(io, fptr); + fd = GetWriteFD(fptr); +#ifdef _WIN32 + (void)fd; + MessageBeep(0); +#else + if (write(fd, "\a", 1) < 0) + rb_sys_fail(0); +#endif + return io; +} + /* * call-seq: * IO.console -> #<File:/dev/tty> @@ -782,6 +800,7 @@ InitVM_console(void) https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L800 rb_define_method(rb_cIO, "iflush", console_iflush, 0); rb_define_method(rb_cIO, "oflush", console_oflush, 0); rb_define_method(rb_cIO, "ioflush", console_ioflush, 0); + rb_define_method(rb_cIO, "beep", console_beep, 0); rb_define_singleton_method(rb_cIO, "console", console_dev, -1); { VALUE mReadable = rb_define_module_under(rb_cIO, "generic_readable"); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/