@@ -820,6 +820,25 @@ console_move(VALUE io, int x, int y)
820
820
return io ;
821
821
}
822
822
823
+ static VALUE
824
+ console_goto_column (VALUE io , VALUE val )
825
+ {
826
+ rb_io_t * fptr ;
827
+ HANDLE h ;
828
+ rb_console_size_t ws ;
829
+ COORD * pos = & ws .dwCursorPosition ;
830
+
831
+ GetOpenFile (io , fptr );
832
+ h = (HANDLE )rb_w32_get_osfhandle (GetWriteFD (fptr ));
833
+ if (!GetConsoleScreenBufferInfo (h , & ws )) {
834
+ rb_syserr_fail (LAST_ERROR , 0 );
835
+ }
836
+ pos -> X = NUM2INT (val );
837
+ if (!SetConsoleCursorPosition (h , * pos )) {
838
+ rb_syserr_fail (LAST_ERROR , 0 );
839
+ }
840
+ return io ;
841
+ }
823
842
#include "win32_vk.inc"
824
843
825
844
static VALUE
@@ -923,6 +942,13 @@ console_move(VALUE io, int x, int y)
923
942
}
924
943
return io ;
925
944
}
945
+
946
+ static VALUE
947
+ console_goto_column (VALUE io , VALUE val )
948
+ {
949
+ rb_io_write (io , rb_sprintf ("\x1b[%dG" , NUM2UINT (val )+ 1 ));
950
+ return io ;
951
+ }
926
952
# define console_key_pressed_p rb_f_notimplement
927
953
#endif
928
954
@@ -1194,6 +1220,7 @@ InitVM_console(void)
1194
1220
rb_define_method (rb_cIO , "cursor_down" , console_cursor_down , 1 );
1195
1221
rb_define_method (rb_cIO , "cursor_left" , console_cursor_left , 1 );
1196
1222
rb_define_method (rb_cIO , "cursor_right" , console_cursor_right , 1 );
1223
+ rb_define_method (rb_cIO , "goto_column" , console_goto_column , 1 );
1197
1224
rb_define_method (rb_cIO , "pressed?" , console_key_pressed_p , 1 );
1198
1225
#if ENABLE_IO_GETPASS
1199
1226
rb_define_method (rb_cIO , "getpass" , console_getpass , -1 );
0 commit comments