Skip to content

Commit

Permalink
Store/restore terminal settings on start/stop.
Browse files Browse the repository at this point in the history
  • Loading branch information
netzpirat committed Oct 18, 2012
1 parent 6c620e4 commit d87560f
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions lib/guard/interactor.rb
Expand Up @@ -125,9 +125,8 @@ def configure_prompt
def start def start
return if ENV['GUARD_ENV'] == 'test' return if ENV['GUARD_ENV'] == 'test'


# TODO: Remove before merge store_terminal_settings if stty_exists?
Thread.abort_on_exception = true

if !@thread || !@thread.alive? if !@thread || !@thread.alive?
::Guard::UI.debug 'Start interactor' ::Guard::UI.debug 'Start interactor'


Expand All @@ -148,8 +147,32 @@ def stop
::Guard::UI.debug 'Stop interactor' ::Guard::UI.debug 'Stop interactor'
@thread.kill @thread.kill
end end

restore_terminal_settings if stty_exists?
end

# Detects whether or not the stty command exists
# on the user machine.
#
# @return [Boolean] the status of stty
#
def stty_exists?
@stty_exists ||= system('hash', 'stty')
end end


# Stores the terminal settings so we can resore them
# when stopping.
#
def store_terminal_settings
@stty_save = `stty -g 2>/dev/null`.chomp
end

# Restore terminal settings
#
def restore_terminal_settings
system("stty #{ @stty_save } 2>/dev/null") if @stty_save
end

# Converts and validates a plain text scope # Converts and validates a plain text scope
# to a valid plugin or group scope. # to a valid plugin or group scope.
# #
Expand Down

0 comments on commit d87560f

Please sign in to comment.