summaryrefslogtreecommitdiff
path: root/ext/io
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-09-23 19:22:31 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-09-23 19:24:43 +0900
commit8487193b109ab8cecea74ff383b01b5ecce172c4 (patch)
tree9792a09c8441f3792e4bc6e239dee7f5be5f9783 /ext/io
parentb443bdbdb997a6b5c0d6f06cada146f523361980 (diff)
[ruby/io-console] Try to write DSR query to writable IO
https://github.com/ruby/io-console/commit/a54b6e4dd1
Diffstat (limited to 'ext/io')
-rw-r--r--ext/io/console/console.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/ext/io/console/console.c b/ext/io/console/console.c
index 8c698b9b5f2..f5a32a8fbb5 100644
--- a/ext/io/console/console.c
+++ b/ext/io/console/console.c
@@ -1042,13 +1042,32 @@ console_key_pressed_p(VALUE io, VALUE k)
return GetKeyState(vk) & 0x80 ? Qtrue : Qfalse;
}
#else
+static int
+direct_query(VALUE io, VALUE query)
+{
+ if (RB_TYPE_P(io, T_FILE)) {
+ rb_io_t *fptr;
+ VALUE wio;
+ GetOpenFile(io, fptr);
+ wio = fptr->tied_io_for_writing;
+ if (wio) {
+ rb_io_write(wio, query);
+ rb_io_flush(wio);
+ return 1;
+ }
+ if (write(fptr->fd, RSTRING_PTR(query), RSTRING_LEN(query)) != -1) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
static VALUE
read_vt_response(VALUE io, VALUE query)
{
VALUE result, b;
int num = 0;
- if (!NIL_P(query)) rb_io_write(io, query);
- rb_io_flush(io);
+ if (!NIL_P(query) && !direct_query(io, query)) return Qnil;
if (rb_io_getbyte(io) != INT2FIX(0x1b)) return Qnil;
if (rb_io_getbyte(io) != INT2FIX('[')) return Qnil;
result = rb_ary_new();