diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-09-24 15:53:58 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-09-24 16:20:31 +0900 |
commit | 10e3267c31c4c976d79e00bca484094f1a87dc65 (patch) | |
tree | 6eea029e66d6dc5376927d30d29af2c20ce9d0a8 /ext/io/console/console.c | |
parent | 244f7ec204e2b3fd54ca68740587b5be6d9defc4 (diff) |
[ruby/io-console] Made cursor position 0-origin
https://github.com/ruby/io-console/commit/9377e37295
Diffstat (limited to 'ext/io/console/console.c')
-rw-r--r-- | ext/io/console/console.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/ext/io/console/console.c b/ext/io/console/console.c index 1d6ebc874d..2604715605 100644 --- a/ext/io/console/console.c +++ b/ext/io/console/console.c @@ -1109,6 +1109,7 @@ 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; + unsigned int r, c; 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; @@ -1116,13 +1117,17 @@ console_cursor_pos(VALUE io) row = RARRAY_AREF(resp, 0); column = RARRAY_AREF(resp, 1); rb_ary_resize(resp, 2); + r = NUM2UINT(row) - 1; + c = NUM2UINT(column) - 1; + RARRAY_ASET(resp, 0, INT2NUM(r)); + RARRAY_ASET(resp, 1, INT2NUM(c)); return resp; } static VALUE console_goto(VALUE io, VALUE y, VALUE x) { - rb_io_write(io, rb_sprintf("\x1b[%d;%dH", NUM2UINT(y), NUM2UINT(x))); + rb_io_write(io, rb_sprintf("\x1b[%d;%dH", NUM2UINT(y)+1, NUM2UINT(x)+1)); return io; } @@ -1223,7 +1228,7 @@ static VALUE console_clear_screen(VALUE io) { console_erase_screen(io, INT2FIX(2)); - console_goto(io, INT2FIX(1), INT2FIX(1)); + console_goto(io, INT2FIX(0), INT2FIX(0)); return io; } |