Skip to content

Commit 179c52b

Browse files
committed
Use String#unpack1
1 parent 737b23b commit 179c52b

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

lib/reline/windows.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -235,21 +235,21 @@ def self.check_input_event
235235
num_of_events = 0.chr * 8
236236
while @@output_buf.empty? #or true
237237
next if @@WaitForSingleObject.(@@hConsoleInputHandle, 100) != 0 # max 0.1 sec
238-
next if @@GetNumberOfConsoleInputEvents.(@@hConsoleInputHandle, num_of_events) == 0 or num_of_events.unpack('L').first == 0
238+
next if @@GetNumberOfConsoleInputEvents.(@@hConsoleInputHandle, num_of_events) == 0 or num_of_events.unpack1('L') == 0
239239
input_record = 0.chr * 18
240240
read_event = 0.chr * 4
241241
if @@ReadConsoleInputW.(@@hConsoleInputHandle, input_record, 1, read_event) != 0
242-
event = input_record[0, 2].unpack('s*').first
242+
event = input_record[0, 2].unpack1('s*')
243243
case event
244244
when WINDOW_BUFFER_SIZE_EVENT
245245
@@winch_handler.()
246246
when KEY_EVENT
247-
key_down = input_record[4, 4].unpack('l*').first
248-
repeat_count = input_record[8, 2].unpack('s*').first
249-
virtual_key_code = input_record[10, 2].unpack('s*').first
250-
virtual_scan_code = input_record[12, 2].unpack('s*').first
251-
char_code = input_record[14, 2].unpack('S*').first
252-
control_key_state = input_record[16, 2].unpack('S*').first
247+
key_down = input_record[4, 4].unpack1('l*')
248+
repeat_count = input_record[8, 2].unpack1('s*')
249+
virtual_key_code = input_record[10, 2].unpack1('s*')
250+
virtual_scan_code = input_record[12, 2].unpack1('s*')
251+
char_code = input_record[14, 2].unpack1('S*')
252+
control_key_state = input_record[16, 2].unpack1('S*')
253253
is_key_down = key_down.zero? ? false : true
254254
if is_key_down
255255
process_key_event(repeat_count, virtual_key_code, virtual_scan_code, char_code, control_key_state)
@@ -291,8 +291,8 @@ def self.get_screen_size
291291
def self.cursor_pos
292292
csbi = 0.chr * 22
293293
@@GetConsoleScreenBufferInfo.call(@@hConsoleHandle, csbi)
294-
x = csbi[4, 2].unpack('s*').first
295-
y = csbi[6, 2].unpack('s*').first
294+
x = csbi[4, 2].unpack1('s*')
295+
y = csbi[6, 2].unpack1('s*')
296296
Reline::CursorPos.new(x, y)
297297
end
298298

@@ -324,7 +324,7 @@ def self.move_cursor_down(val)
324324
def self.erase_after_cursor
325325
csbi = 0.chr * 24
326326
@@GetConsoleScreenBufferInfo.call(@@hConsoleHandle, csbi)
327-
cursor = csbi[4, 4].unpack('L').first
327+
cursor = csbi[4, 4].unpack1('L')
328328
written = 0.chr * 4
329329
@@FillConsoleOutputCharacter.call(@@hConsoleHandle, 0x20, get_screen_size.last - cursor_pos.x, cursor, written)
330330
@@FillConsoleOutputAttribute.call(@@hConsoleHandle, 0, get_screen_size.last - cursor_pos.x, cursor, written)
@@ -343,8 +343,8 @@ def self.scroll_down(val)
343343
def self.clear_screen
344344
csbi = 0.chr * 22
345345
return if @@GetConsoleScreenBufferInfo.call(@@hConsoleHandle, csbi) == 0
346-
buffer_width = csbi[0, 2].unpack('S').first
347-
attributes = csbi[8, 2].unpack('S').first
346+
buffer_width = csbi[0, 2].unpack1('S')
347+
attributes = csbi[8, 2].unpack1('S')
348348
_window_left, window_top, _window_right, window_bottom = *csbi[10,8].unpack('S*')
349349
fill_length = buffer_width * (window_bottom - window_top + 1)
350350
screen_topleft = window_top * 65536

0 commit comments

Comments
 (0)