Skip to content

Commit d1f5ae9

Browse files
committed
Made cursor position consistent with winsize
To be consistent with `winsize`, changed the cursor position format from `[x, y]` to `[row, column]`.
1 parent b801750 commit d1f5ae9

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

ext/io/console/console.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ mode_in_range(VALUE val, int high, const char *modename)
831831

832832
#if defined _WIN32
833833
static VALUE
834-
console_goto(VALUE io, VALUE x, VALUE y)
834+
console_goto(VALUE io, VALUE y, VALUE x)
835835
{
836836
rb_io_t *fptr;
837837
int fd;
@@ -859,11 +859,11 @@ console_cursor_pos(VALUE io)
859859
if (!GetConsoleScreenBufferInfo((HANDLE)rb_w32_get_osfhandle(fd), &ws)) {
860860
rb_syserr_fail(LAST_ERROR, 0);
861861
}
862-
return rb_assoc_new(UINT2NUM(ws.dwCursorPosition.X), UINT2NUM(ws.dwCursorPosition.Y));
862+
return rb_assoc_new(UINT2NUM(ws.dwCursorPosition.Y), UINT2NUM(ws.dwCursorPosition.X));
863863
}
864864

865865
static VALUE
866-
console_move(VALUE io, int x, int y)
866+
console_move(VALUE io, int y, int x)
867867
{
868868
rb_io_t *fptr;
869869
HANDLE h;
@@ -1116,20 +1116,18 @@ console_cursor_pos(VALUE io)
11161116
row = RARRAY_AREF(resp, 0);
11171117
column = RARRAY_AREF(resp, 1);
11181118
rb_ary_resize(resp, 2);
1119-
RARRAY_ASET(resp, 0, column);
1120-
RARRAY_ASET(resp, 1, row);
11211119
return resp;
11221120
}
11231121

11241122
static VALUE
1125-
console_goto(VALUE io, VALUE x, VALUE y)
1123+
console_goto(VALUE io, VALUE y, VALUE x)
11261124
{
11271125
rb_io_write(io, rb_sprintf("\x1b[%d;%dH", NUM2UINT(y), NUM2UINT(x)));
11281126
return io;
11291127
}
11301128

11311129
static VALUE
1132-
console_move(VALUE io, int x, int y)
1130+
console_move(VALUE io, int y, int x)
11331131
{
11341132
if (x || y) {
11351133
VALUE s = rb_str_new_cstr("");
@@ -1188,25 +1186,25 @@ console_cursor_set(VALUE io, VALUE cpos)
11881186
static VALUE
11891187
console_cursor_up(VALUE io, VALUE val)
11901188
{
1191-
return console_move(io, 0, -NUM2INT(val));
1189+
return console_move(io, -NUM2INT(val), 0);
11921190
}
11931191

11941192
static VALUE
11951193
console_cursor_down(VALUE io, VALUE val)
11961194
{
1197-
return console_move(io, 0, +NUM2INT(val));
1195+
return console_move(io, +NUM2INT(val), 0);
11981196
}
11991197

12001198
static VALUE
12011199
console_cursor_left(VALUE io, VALUE val)
12021200
{
1203-
return console_move(io, -NUM2INT(val), 0);
1201+
return console_move(io, 0, -NUM2INT(val));
12041202
}
12051203

12061204
static VALUE
12071205
console_cursor_right(VALUE io, VALUE val)
12081206
{
1209-
return console_move(io, +NUM2INT(val), 0);
1207+
return console_move(io, 0, +NUM2INT(val));
12101208
}
12111209

12121210
static VALUE

0 commit comments

Comments
 (0)