Skip to content

Commit 0c87081

Browse files
committed
Support hide/show cursor on Windows
1 parent a9050cf commit 0c87081

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/reline/windows.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def call(*args)
133133
@@GetFileType = Win32API.new('kernel32', 'GetFileType', ['L'], 'L')
134134
@@GetFileInformationByHandleEx = Win32API.new('kernel32', 'GetFileInformationByHandleEx', ['L', 'I', 'P', 'L'], 'I')
135135
@@FillConsoleOutputAttribute = Win32API.new('kernel32', 'FillConsoleOutputAttribute', ['L', 'L', 'L', 'L', 'P'], 'L')
136+
@@SetConsoleCursorInfo = Win32API.new('kernel32', 'SetConsoleCursorInfo', ['L', 'P'], 'L')
136137

137138
@@GetConsoleMode = Win32API.new('kernel32', 'GetConsoleMode', ['L', 'P'], 'L')
138139
@@SetConsoleMode = Win32API.new('kernel32', 'SetConsoleMode', ['L', 'L'], 'L')
@@ -342,11 +343,17 @@ def self.set_screen_size(rows, columns)
342343
end
343344

344345
def self.hide_cursor
345-
# ignored
346+
size = 100
347+
visible = 0 # 0 means false
348+
cursor_info = [size, visible].pack('Li')
349+
@@SetConsoleCursorInfo.call(@@hConsoleHandle, cursor_info)
346350
end
347351

348352
def self.show_cursor
349-
# ignored
353+
size = 100
354+
visible = 1 # 1 means true
355+
cursor_info = [size, visible].pack('Li')
356+
@@SetConsoleCursorInfo.call(@@hConsoleHandle, cursor_info)
350357
end
351358

352359
def self.set_winch_handler(&handler)

0 commit comments

Comments
 (0)