ruby-changes:57872
From: Nobuyoshi <ko1@a...>
Date: Mon, 23 Sep 2019 19:25:12 +0900 (JST)
Subject: [ruby-changes:57872] 8487193b10 (master): [ruby/io-console] Try to write DSR query to writable IO
https://git.ruby-lang.org/ruby.git/commit/?id=8487193b10 From 8487193b109ab8cecea74ff383b01b5ecce172c4 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Mon, 23 Sep 2019 19:22:31 +0900 Subject: [ruby/io-console] Try to write DSR query to writable IO https://github.com/ruby/io-console/commit/a54b6e4dd1 diff --git a/ext/io/console/console.c b/ext/io/console/console.c index 8c698b9..f5a32a8 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) https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L1042 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(); -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/