Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbrictson committed Apr 2, 2024
1 parent 3479fcd commit e9e496f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/mighty_test/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ def clear
end

def wait_for_keypress
return stdin.getc unless stdin.respond_to?(:raw) && tty?

stdin.raw(intr: true) { stdin.getc }
with_raw_input do
sleep if stdin.eof?
stdin.getc
end
end

def play_sound(name, wait: false)
Expand Down Expand Up @@ -54,5 +55,11 @@ def play_sound(name, wait: false)
def tty?
$stdout.respond_to?(:tty?) && $stdout.tty?
end

def with_raw_input(&)
return yield unless stdin.respond_to?(:raw) && tty?

stdin.raw(intr: true, &)
end
end
end

0 comments on commit e9e496f

Please sign in to comment.