@@ -444,6 +444,16 @@ def test_cursor_position
444444 end
445445 end
446446
447+ def test_cursor_visibility
448+ run_pty ( <<~'RUBY' ) do |r , _ , _ |
449+ con = IO.console
450+ abort unless con.hide_cursor.equal?(con)
451+ abort unless con.show_cursor.equal?(con)
452+ RUBY
453+ assert_equal ( "\e [?25l\e [?25h" , r . read ( 12 ) )
454+ end
455+ end unless RbConfig ::CONFIG [ "host_os" ] =~ /mswin|mingw/
456+
447457 def assert_ctrl ( expect , cc , r , w )
448458 sleep 0.1
449459 w . print cc
@@ -700,6 +710,36 @@ def test_pressed_invalid
700710
701711RbConfig ::CONFIG [ "host_os" ] =~ /mswin|mingw/ and defined? ( IO . console ) and IO . console and \
702712TestIO_Console . class_eval do
713+ def test_cursor_visibility
714+ require "fiddle/import"
715+
716+ kernel32 = Module . new do
717+ extend Fiddle ::Importer
718+ dlload "kernel32.dll"
719+ extern "void *CreateFileW(void *, long, long, void *, long, long, void *)"
720+ extern "int CloseHandle(void *)"
721+ extern "int GetConsoleCursorInfo(void *, void *)"
722+ end
723+ File . open ( "CONOUT$" , "r+" ) do |output |
724+ info = [ 0 , 0 ] . pack ( "L<L<" )
725+ path = "CONOUT$\0 " . encode ( "UTF-16LE" )
726+ handle = kernel32 . CreateFileW ( path , -0x40000000 , 3 , nil , 3 , 0 , nil )
727+ assert_not_equal ( 0 , kernel32 . GetConsoleCursorInfo ( handle , info ) )
728+ size , visible = info . unpack ( "L<L<" )
729+ begin
730+ assert_same ( output , output . hide_cursor )
731+ assert_not_equal ( 0 , kernel32 . GetConsoleCursorInfo ( handle , info ) )
732+ assert_equal ( [ size , 0 ] , info . unpack ( "L<L<" ) )
733+ assert_same ( output , output . show_cursor )
734+ assert_not_equal ( 0 , kernel32 . GetConsoleCursorInfo ( handle , info ) )
735+ assert_equal ( [ size , 1 ] , info . unpack ( "L<L<" ) )
736+ ensure
737+ visible == 0 ? output . hide_cursor : output . show_cursor
738+ kernel32 . CloseHandle ( handle )
739+ end
740+ end
741+ end
742+
703743 def test_console_input_events
704744 require "fiddle"
705745
0 commit comments