summaryrefslogtreecommitdiff
path: root/ext/io/console
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-09-09 23:48:47 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-09-10 08:18:03 +0900
commit3d9c7c28358110076abb2d77365eef805ddb896c (patch)
tree8f136beae137f65f974506037684281ec7771dc3 /ext/io/console
parent53ed4fb37632789db69815bb9b9df0e3572779ef (diff)
[ruby/io-console] Added IO#goto and IO#cursor= for VT
https://github.com/ruby/io-console/commit/7f2b1b473d
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2440
Diffstat (limited to 'ext/io/console')
-rw-r--r--ext/io/console/console.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/ext/io/console/console.c b/ext/io/console/console.c
index 8c30684113b..db40c1b014f 100644
--- a/ext/io/console/console.c
+++ b/ext/io/console/console.c
@@ -799,14 +799,6 @@ console_cursor_pos(VALUE io)
return rb_assoc_new(UINT2NUM(ws.dwCursorPosition.X), UINT2NUM(ws.dwCursorPosition.Y));
}
-static VALUE
-console_cursor_set(VALUE io, VALUE cpos)
-{
- cpos = rb_convert_type(cpos, T_ARRAY, "Array", "to_ary");
- if (RARRAY_LEN(cpos) != 2) rb_raise(rb_eArgError, "expected 2D coordinate");
- return console_goto(io, RARRAY_AREF(cpos, 0), RARRAY_AREF(cpos, 1));
-}
-
#include "win32_vk.inc"
static VALUE
@@ -835,8 +827,6 @@ console_key_pressed_p(VALUE io, VALUE k)
return GetKeyState(vk) & 0x80 ? Qtrue : Qfalse;
}
#else
-# define console_goto rb_f_notimplement
-# define console_cursor_set rb_f_notimplement
static VALUE
read_vt_response(VALUE io, VALUE query)
{
@@ -892,9 +882,24 @@ console_cursor_pos(VALUE io)
RARRAY_ASET(resp, 1, row);
return resp;
}
+
+static VALUE
+console_goto(VALUE io, VALUE x, VALUE y)
+{
+ rb_io_write(io, rb_sprintf("\x1b[%d;%dH", NUM2UINT(y), NUM2UINT(x)));
+ return io;
+}
# define console_key_pressed_p rb_f_notimplement
#endif
+static VALUE
+console_cursor_set(VALUE io, VALUE cpos)
+{
+ cpos = rb_convert_type(cpos, T_ARRAY, "Array", "to_ary");
+ if (RARRAY_LEN(cpos) != 2) rb_raise(rb_eArgError, "expected 2D coordinate");
+ return console_goto(io, RARRAY_AREF(cpos, 0), RARRAY_AREF(cpos, 1));
+}
+
/*
* call-seq:
* IO.console -> #<File:/dev/tty>