summaryrefslogtreecommitdiff
path: root/lib/highline/terminal.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/highline/terminal.rb')
-rwxr-xr-xlib/highline/terminal.rb55
1 files changed, 24 insertions, 31 deletions
diff --git a/lib/highline/terminal.rb b/lib/highline/terminal.rb
index a76a136..cd1d3dc 100755
--- a/lib/highline/terminal.rb
+++ b/lib/highline/terminal.rb
@@ -16,24 +16,17 @@ class HighLine
# input and output to.
# The specialized Terminals all decend from this HighLine::Terminal class
class Terminal
-
# Probe for and return a suitable Terminal instance
# @param input [IO] input stream
# @param output [IO] output stream
def self.get_terminal(input, output)
- terminal = nil
-
# First of all, probe for io/console
begin
require "io/console"
require "highline/terminal/io_console"
terminal = HighLine::Terminal::IOConsole.new(input, output)
rescue LoadError
- end
-
- # Fall back to UnixStty
- unless terminal
- require 'highline/terminal/unix_stty'
+ require "highline/terminal/unix_stty"
terminal = HighLine::Terminal::UnixStty.new(input, output)
end
@@ -57,8 +50,7 @@ class HighLine
# An initialization callback.
# It is called by {.get_terminal}.
- def initialize_system_extensions
- end
+ def initialize_system_extensions; end
# @return [Array<Integer, Integer>] two value terminal
# size like [columns, lines]
@@ -67,8 +59,7 @@ class HighLine
end
# Enter Raw No Echo mode.
- def raw_no_echo_mode
- end
+ def raw_no_echo_mode; end
# Yieds a block to be executed in Raw No Echo mode and
# then restore the terminal state.
@@ -80,40 +71,38 @@ class HighLine
end
# Restore terminal to its default mode
- def restore_mode
- end
+ def restore_mode; end
# Get one character from the terminal
# @return [String] one character
- def get_character
- end
+ def get_character; end # rubocop:disable Naming/AccessorMethodName
# Get one line from the terminal and format accordling.
# Use readline if question has readline mode set.
# @param question [HighLine::Question]
# @param highline [HighLine]
# @param options [Hash]
- def get_line(question, highline, options={})
+ def get_line(question, highline)
raw_answer =
- if question.readline
- get_line_with_readline(question, highline, options={})
- else
- get_line_default(highline)
- end
+ if question.readline
+ get_line_with_readline(question, highline)
+ else
+ get_line_default(highline)
+ end
question.format_answer(raw_answer)
end
# Get one line using #readline_read
# @param (see #get_line)
- def get_line_with_readline(question, highline, options={})
- require "readline" # load only if needed
+ def get_line_with_readline(question, highline)
+ require "readline" # load only if needed
question_string = highline.render_statement(question)
raw_answer = readline_read(question_string, question)
- if !raw_answer and highline.track_eof?
+ if !raw_answer && highline.track_eof?
raise EOFError, "The input stream is exhausted."
end
@@ -140,7 +129,7 @@ class HighLine
Readline.readline(prompt, true)
end
- $VERBOSE = old_verbose
+ $VERBOSE = old_verbose
raw_answer
end
@@ -148,8 +137,8 @@ class HighLine
# Get one line from terminal using default #gets method.
# @param highline (see #get_line)
def get_line_default(highline)
- raise EOFError, "The input stream is exhausted." if highline.track_eof? and
- highline.input.eof?
+ raise EOFError, "The input stream is exhausted." if highline.track_eof? &&
+ highline.input.eof?
highline.input.gets
end
@@ -157,12 +146,12 @@ class HighLine
# Running on JRuby?
def jruby?
- defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
+ defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
end
# Running on Rubinius?
def rubinius?
- defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
+ defined?(RUBY_ENGINE) && RUBY_ENGINE == "rbx"
end
# Running on Windows?
@@ -190,7 +179,11 @@ class HighLine
# Saves terminal state using shell stty command.
def save_stty
- @stty_save = `stty -g`.chomp rescue nil
+ @stty_save = begin
+ `stty -g`.chomp
+ rescue StandardError
+ nil
+ end
end
# Restores terminal state using shell stty command.