summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-03 18:11:25 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-03 18:11:25 +0000
commit1014dfb442f2878834d78d8c8da8a0a62ba98d3d (patch)
treee4bbd32b494afe2b517285ab2e9a9c9f6a77ca60
parentfadd0160d0a4ac46af821c118f068d3fd806b990 (diff)
console.c: IO#beep
* ext/io/console/console.c (console_beep): new method IO#beep. [EXPERIMENTAL] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50424 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ext/io/console/console.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/ext/io/console/console.c b/ext/io/console/console.c
index b4ae892..5e8dad3 100644
--- a/ext/io/console/console.c
+++ b/ext/io/console/console.c
@@ -639,6 +639,24 @@ console_ioflush(VALUE io)
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)
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");