[前][次][番号順一覧][スレッド一覧]

ruby-changes:57878

From: Nobuyoshi <ko1@a...>
Date: Tue, 24 Sep 2019 16:20:54 +0900 (JST)
Subject: [ruby-changes:57878] 244f7ec204 (master): [ruby/io-console] Made cursor position consistent with `winsize`

https://git.ruby-lang.org/ruby.git/commit/?id=244f7ec204

From 244f7ec204e2b3fd54ca68740587b5be6d9defc4 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Tue, 24 Sep 2019 15:48:58 +0900
Subject: [ruby/io-console] Made cursor position consistent with `winsize`

To be consistent with `winsize`, changed the cursor position
format from `[x, y]` to `[row, column]`.

https://github.com/ruby/io-console/commit/d1f5ae9286

diff --git a/ext/io/console/console.c b/ext/io/console/console.c
index cd47f1e..1d6ebc8 100644
--- a/ext/io/console/console.c
+++ b/ext/io/console/console.c
@@ -831,7 +831,7 @@ mode_in_range(VALUE val, int high, const char *modename) https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L831
 
 #if defined _WIN32
 static VALUE
-console_goto(VALUE io, VALUE x, VALUE y)
+console_goto(VALUE io, VALUE y, VALUE x)
 {
     rb_io_t *fptr;
     int fd;
@@ -859,11 +859,11 @@ console_cursor_pos(VALUE io) https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L859
     if (!GetConsoleScreenBufferInfo((HANDLE)rb_w32_get_osfhandle(fd), &ws)) {
 	rb_syserr_fail(LAST_ERROR, 0);
     }
-    return rb_assoc_new(UINT2NUM(ws.dwCursorPosition.X), UINT2NUM(ws.dwCursorPosition.Y));
+    return rb_assoc_new(UINT2NUM(ws.dwCursorPosition.Y), UINT2NUM(ws.dwCursorPosition.X));
 }
 
 static VALUE
-console_move(VALUE io, int x, int y)
+console_move(VALUE io, int y, int x)
 {
     rb_io_t *fptr;
     HANDLE h;
@@ -1116,20 +1116,18 @@ console_cursor_pos(VALUE io) https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L1116
     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;
 }
 
 static VALUE
-console_goto(VALUE io, VALUE x, VALUE y)
+console_goto(VALUE io, VALUE y, VALUE x)
 {
     rb_io_write(io, rb_sprintf("\x1b[%d;%dH", NUM2UINT(y), NUM2UINT(x)));
     return io;
 }
 
 static VALUE
-console_move(VALUE io, int x, int y)
+console_move(VALUE io, int y, int x)
 {
     if (x || y) {
 	VALUE s = rb_str_new_cstr("");
@@ -1188,25 +1186,25 @@ console_cursor_set(VALUE io, VALUE cpos) https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L1186
 static VALUE
 console_cursor_up(VALUE io, VALUE val)
 {
-    return console_move(io, 0, -NUM2INT(val));
+    return console_move(io, -NUM2INT(val), 0);
 }
 
 static VALUE
 console_cursor_down(VALUE io, VALUE val)
 {
-    return console_move(io, 0, +NUM2INT(val));
+    return console_move(io, +NUM2INT(val), 0);
 }
 
 static VALUE
 console_cursor_left(VALUE io, VALUE val)
 {
-    return console_move(io, -NUM2INT(val), 0);
+    return console_move(io, 0, -NUM2INT(val));
 }
 
 static VALUE
 console_cursor_right(VALUE io, VALUE val)
 {
-    return console_move(io, +NUM2INT(val), 0);
+    return console_move(io, 0, +NUM2INT(val));
 }
 
 static VALUE
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]