ruby-changes:57693
From: Nobuyoshi <ko1@a...>
Date: Tue, 10 Sep 2019 08:18:23 +0900 (JST)
Subject: [ruby-changes:57693] 53ed4fb376 (master): [ruby/io-console] Added IO#cursor for VT
https://git.ruby-lang.org/ruby.git/commit/?id=53ed4fb376 From 53ed4fb37632789db69815bb9b9df0e3572779ef Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Mon, 9 Sep 2019 23:17:38 +0900 Subject: [ruby/io-console] Added IO#cursor for VT https://github.com/ruby/io-console/commit/41a6a6cace diff --git a/ext/io/console/console.c b/ext/io/console/console.c index b50a73e..8c30684 100644 --- a/ext/io/console/console.c +++ b/ext/io/console/console.c @@ -836,7 +836,6 @@ console_key_pressed_p(VALUE io, VALUE k) https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L836 } #else # define console_goto rb_f_notimplement -# define console_cursor_pos rb_f_notimplement # define console_cursor_set rb_f_notimplement static VALUE read_vt_response(VALUE io, VALUE query) @@ -875,6 +874,24 @@ console_vt_response(int argc, VALUE *argv, VALUE io) https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L874 VALUE ret = ttymode_with_io(io, read_vt_response, query, set_rawmode, optp); return ret; } + +static VALUE +console_cursor_pos(VALUE io) +{ + VALUE query = rb_str_new_cstr("\e[6n"); + VALUE resp = console_vt_response(1, &query, io); + VALUE row, column, term; + if (!RB_TYPE_P(resp, T_ARRAY) || RARRAY_LEN(resp) != 3) return Qnil; + term = RARRAY_AREF(resp, 2); + if (!RB_TYPE_P(term, T_STRING) || RSTRING_LEN(term) != 1) return Qnil; + if (RSTRING_PTR(term)[0] != 'R') return Qnil; + row = RARRAY_AREF(resp, 0); + column = RARRAY_AREF(resp, 1); + rb_ary_resize(resp, 2); + RARRAY_ASET(resp, 0, column); + RARRAY_ASET(resp, 1, row); + return resp; +} # define console_key_pressed_p rb_f_notimplement #endif -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/