diff options
author | Abinoam P. Marques Jr <abinoam@gmail.com> | 2017-06-30 23:53:15 -0300 |
---|---|---|
committer | Abinoam P. Marques Jr <abinoam@gmail.com> | 2017-06-30 23:53:15 -0300 |
commit | 97888f5f91f9675ef2f7809fe1cb423abf6099c8 (patch) | |
tree | d26f2898b93308ba8a3e12b5fd3b363a46a0ef59 /lib | |
parent | 7a63996d6eaccbe403c724f40a771e4a48c7ea34 (diff) | |
download | highline-97888f5f91f9675ef2f7809fe1cb423abf6099c8.tar.gz |
Rubocop automatic corrections
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/highline.rb | 30 | ||||
-rw-r--r-- | lib/highline/builtin_styles.rb | 51 | ||||
-rw-r--r-- | lib/highline/color_scheme.rb | 46 | ||||
-rw-r--r-- | lib/highline/compatibility.rb | 6 | ||||
-rw-r--r-- | lib/highline/custom_errors.rb | 1 | ||||
-rw-r--r-- | lib/highline/import.rb | 4 | ||||
-rw-r--r-- | lib/highline/list.rb | 9 | ||||
-rw-r--r-- | lib/highline/list_renderer.rb | 18 | ||||
-rw-r--r-- | lib/highline/menu.rb | 90 | ||||
-rw-r--r-- | lib/highline/paginator.rb | 7 | ||||
-rwxr-xr-x | lib/highline/question.rb | 74 | ||||
-rw-r--r-- | lib/highline/question/answer_converter.rb | 2 | ||||
-rw-r--r-- | lib/highline/question_asker.rb | 9 | ||||
-rw-r--r-- | lib/highline/simulate.rb | 5 | ||||
-rw-r--r-- | lib/highline/statement.rb | 6 | ||||
-rw-r--r-- | lib/highline/string.rb | 3 | ||||
-rw-r--r-- | lib/highline/string_extensions.rb | 6 | ||||
-rwxr-xr-x | lib/highline/style.rb | 53 | ||||
-rw-r--r-- | lib/highline/template_renderer.rb | 8 | ||||
-rwxr-xr-x | lib/highline/terminal.rb | 43 | ||||
-rw-r--r-- | lib/highline/terminal/io_console.rb | 2 | ||||
-rw-r--r-- | lib/highline/terminal/ncurses.rb | 2 | ||||
-rw-r--r-- | lib/highline/terminal/unix_stty.rb | 21 | ||||
-rw-r--r-- | lib/highline/wrapper.rb | 18 |
24 files changed, 246 insertions, 268 deletions
diff --git a/lib/highline.rb b/lib/highline.rb index a94bbed..7612674 100755 --- a/lib/highline.rb +++ b/lib/highline.rb @@ -97,8 +97,8 @@ class HighLine # @param page_at [Integer] page size and paginating. # @param indent_size [Integer] indentation size in spaces. # @param indent_level [Integer] how deep is indentated. - def initialize( input = $stdin, output = $stdout, - wrap_at = nil, page_at = nil, indent_size=3, indent_level=0 ) + def initialize(input = $stdin, output = $stdout, + wrap_at = nil, page_at = nil, indent_size = 3, indent_level = 0) @input = input @output = output @@ -185,8 +185,8 @@ class HighLine # @param yes_or_no_question [String] a question that accepts yes and no as answers # @param character [Boolean, :getc] character mode to be passed to Question#character # @see Question#character - def agree( yes_or_no_question, character = nil ) - ask(yes_or_no_question, lambda { |yn| yn.downcase[0] == ?y}) do |q| + def agree(yes_or_no_question, character = nil) + ask(yes_or_no_question, ->(yn) { yn.downcase[0] == 'y' }) do |q| q.validate = /\A(?:y(?:es)?|no?)\Z/i q.responses[:not_valid] = 'Please enter "yes" or "no".' q.responses[:ask_on_error] = :question @@ -236,7 +236,7 @@ class HighLine # @param items [Array<String>] # @param details [Proc] to be passed to Menu.new # @return [String] answer - def choose( *items, &details ) + def choose(*items, &details) menu = Menu.new(&details) menu.choices(*items) unless items.empty? @@ -268,7 +268,7 @@ class HighLine # @return [lambda] lambda to be used in autocompletion operations def shell_style_lambda(menu) - lambda do |command| # shell-style selection + lambda do |command| # shell-style selection first_word = command.to_s.split.first || "" options = menu.options @@ -359,7 +359,7 @@ class HighLine statement = render_statement(statement) return if statement.empty? - statement = (indentation+statement) + statement = (indentation + statement) # Don't add a newline if statement ends with whitespace, OR # if statement ends with whitespace before a color escape code. @@ -384,7 +384,7 @@ class HighLine # set to <tt>:auto</tt>, HighLine will attempt to determine the columns # available for the <tt>@output</tt> or use a sensible default. # - def wrap_at=( setting ) + def wrap_at=(setting) @wrap_at = setting == :auto ? output_cols : setting end @@ -394,7 +394,7 @@ class HighLine # set to <tt>:auto</tt>, HighLine will attempt to determine the rows available # for the <tt>@output</tt> or use a sensible default. # - def page_at=( setting ) + def page_at=(setting) @page_at = setting == :auto ? output_rows - 2 : setting end @@ -402,7 +402,7 @@ class HighLine # Outputs indentation with current settings # def indentation - ' '*@indent_size*@indent_level + ' ' * @indent_size * @indent_level end # @@ -413,7 +413,7 @@ class HighLine # @param multiline [Boolean] # @return [void] # @see #multi_indent - def indent(increase=1, statement=nil, multiline=nil) + def indent(increase = 1, statement = nil, multiline = nil) @indent_level += increase multi = @multi_indent @multi_indent ||= multiline @@ -505,7 +505,7 @@ class HighLine # @param question [Question] # @return [String] response def get_response_line_mode(question) - if question.echo == true and !question.limit + if question.echo == true && !question.limit get_line(question) else get_line_raw_no_echo_mode(question) @@ -535,7 +535,7 @@ class HighLine # honor backspace and delete if character == "\b" chopped = line.chop! - output_erase_char if chopped and question.echo + output_erase_char if chopped && question.echo else line << character say_last_char_or_echo_char(line, question) @@ -563,11 +563,11 @@ class HighLine def say_last_char_or_echo_char(line, question) @output.print(line[-1]) if question.echo == true - @output.print(question.echo) if question.echo and question.echo != true + @output.print(question.echo) if question.echo && question.echo != true end def line_overflow_for_question?(line, question) - question.limit and line.size == question.limit + question.limit && line.size == question.limit end def output_erase_char diff --git a/lib/highline/builtin_styles.rb b/lib/highline/builtin_styles.rb index c829f60..175497f 100644 --- a/lib/highline/builtin_styles.rb +++ b/lib/highline/builtin_styles.rb @@ -1,4 +1,4 @@ -#coding: utf-8 +# coding: utf-8 class HighLine # Builtin Styles that are included at HighLine initialization. @@ -23,17 +23,17 @@ class HighLine blink: "\e[5m", reverse: "\e[7m", concealed: "\e[8m" - } + }.freeze STYLE_LIST.each do |style_name, code| - style = String(style_name).upcase + style = String(style_name).upcase - const_set style, code - const_set style + "_STYLE", Style.new(name: style_name, code: code, builtin: true) + const_set style, code + const_set style + "_STYLE", Style.new(name: style_name, code: code, builtin: true) end # Basic Style names like CLEAR, BOLD, UNDERLINE - STYLES = %w{CLEAR RESET BOLD DARK UNDERLINE UNDERSCORE BLINK REVERSE CONCEALED} + STYLES = %w[CLEAR RESET BOLD DARK UNDERLINE UNDERSCORE BLINK REVERSE CONCEALED].freeze # A Hash with the basic colors an their ANSI escape codes. COLOR_LIST = { @@ -48,23 +48,23 @@ class HighLine gray: { code: "\e[37m", rgb: [192, 192, 192] }, grey: { code: "\e[37m", rgb: [192, 192, 192] }, none: { code: "\e[38m", rgb: [0, 0, 0] } - } + }.freeze COLOR_LIST.each do |color_name, attributes| - color = String(color_name).upcase + color = String(color_name).upcase - style = Style.new( - name: color_name, - code: attributes[:code], - rgb: attributes[:rgb], - builtin: true - ) + style = Style.new( + name: color_name, + code: attributes[:code], + rgb: attributes[:rgb], + builtin: true + ) - const_set color + "_STYLE", style + const_set color + "_STYLE", style end # The builtin styles basic colors like black, red, green. - BASIC_COLORS = %w{BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE GRAY GREY NONE} + BASIC_COLORS = %w[BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE GRAY GREY NONE].freeze colors = BASIC_COLORS.dup BASIC_COLORS.each do |color| @@ -86,11 +86,10 @@ class HighLine const_set "ON_#{color}", const_get("ON_#{color}_STYLE").code end - ON_NONE_STYLE.rgb = [255,255,255] # Override; white background + ON_NONE_STYLE.rgb = [255, 255, 255] # Override; white background # BuiltinStyles class methods to be extended. module ClassMethods - # Regexp to match against RGB style constant names. RGB_COLOR_PATTERN = /^(ON_)?(RGB_)([A-F0-9]{6})(_STYLE)?$/ @@ -99,17 +98,17 @@ class HighLine # @param name [Symbol] missing constant name def const_missing(name) if name.to_s =~ RGB_COLOR_PATTERN - on = $1 - suffix = $4 + on = Regexp.last_match(1) + suffix = Regexp.last_match(4) - if suffix - code_name = $1.to_s + $2 + $3 - else - code_name = name.to_s - end + code_name = if suffix + Regexp.last_match(1).to_s + Regexp.last_match(2) + Regexp.last_match(3) + else + name.to_s + end style_name = code_name + '_STYLE' - style = Style.rgb($3) + style = Style.rgb(Regexp.last_match(3)) style = style.on if on const_set(style_name, style) diff --git a/lib/highline/color_scheme.rb b/lib/highline/color_scheme.rb index 11cd687..a776fbf 100644 --- a/lib/highline/color_scheme.rb +++ b/lib/highline/color_scheme.rb @@ -8,7 +8,6 @@ # # This is Free Software. See LICENSE and COPYING for details - class HighLine # # ColorScheme objects encapsulate a named set of colors to be used in the @@ -49,15 +48,15 @@ class HighLine # constants. # # @param h [Hash] - def initialize( h = nil ) - @scheme = Hash.new + def initialize(h = nil) + @scheme = {} load_from_hash(h) if h yield self if block_given? end # Load multiple colors from key/value pairs. # @param h [Hash] - def load_from_hash( h ) + def load_from_hash(h) h.each_pair do |color_tag, constants| self[color_tag] = constants end @@ -66,20 +65,20 @@ class HighLine # Does this color scheme include the given tag name? # @param color_tag [#to_sym] # @return [Boolean] - def include?( color_tag ) + def include?(color_tag) @scheme.keys.include?(to_symbol(color_tag)) end # Allow the scheme to be accessed like a Hash. # @param color_tag [#to_sym] # @return [Style] - def []( color_tag ) + def [](color_tag) @scheme[to_symbol(color_tag)] end # Retrieve the original form of the scheme # @param color_tag [#to_sym] - def definition( color_tag ) + def definition(color_tag) style = @scheme[to_symbol(color_tag)] style && style.list end @@ -93,29 +92,28 @@ class HighLine # Allow the scheme to be set like a Hash. # @param color_tag [#to_sym] # @param constants [Array<Symbol>] Array of Style symbols - def []=( color_tag, constants ) - @scheme[to_symbol(color_tag)] = HighLine::Style.new(:name=>color_tag.to_s.downcase.to_sym, - :list=>constants, :no_index=>true) + def []=(color_tag, constants) + @scheme[to_symbol(color_tag)] = HighLine::Style.new(name: color_tag.to_s.downcase.to_sym, + list: constants, no_index: true) end # Retrieve the color scheme hash (in original definition format) # @return [Hash] scheme as Hash. It may be reused in a new ColorScheme. def to_hash - @scheme.inject({}) { |hsh, pair| key, value = pair; hsh[key] = value.list; hsh } + @scheme.each_with_object({}) { |pair, hsh| key, value = pair; hsh[key] = value.list; } end - private # Return a normalized representation of a color name. - def to_symbol( t ) + def to_symbol(t) t.to_s.downcase end # Return a normalized representation of a color setting. - def to_constant( v ) + def to_constant(v) v = v.to_s if v.is_a?(Symbol) - if v.is_a?(::String) then + if v.is_a?(::String) HighLine.const_get(v.upcase) else v @@ -130,16 +128,16 @@ class HighLine # <tt>:error</tt>, <tt>:warning</tt>, <tt>:notice</tt>, <tt>:info</tt>, # <tt>:debug</tt>, <tt>:row_even</tt>, and <tt>:row_odd</tt> colors. # - def initialize( h = nil ) + def initialize(_h = nil) scheme = { - :critical => [ :yellow, :on_red ], - :error => [ :bold, :red ], - :warning => [ :bold, :yellow ], - :notice => [ :bold, :magenta ], - :info => [ :bold, :cyan ], - :debug => [ :bold, :green ], - :row_even => [ :cyan ], - :row_odd => [ :magenta ] + critical: %i[yellow on_red], + error: %i[bold red], + warning: %i[bold yellow], + notice: %i[bold magenta], + info: %i[bold cyan], + debug: %i[bold green], + row_even: [:cyan], + row_odd: [:magenta] } super(scheme) end diff --git a/lib/highline/compatibility.rb b/lib/highline/compatibility.rb index 33c889c..ee13fd6 100644 --- a/lib/highline/compatibility.rb +++ b/lib/highline/compatibility.rb @@ -4,13 +4,13 @@ unless STDIN.respond_to? :getbyte # HighLine adds #getbyte alias to #getc when #getbyte is not available. class IO # alias to #getc when #getbyte is not available - alias_method :getbyte, :getc + alias getbyte getc end # HighLine adds #getbyte alias to #getc when #getbyte is not available. class StringIO # alias to #getc when #getbyte is not available - alias_method :getbyte, :getc + alias getbyte getc end end @@ -18,6 +18,6 @@ unless "".respond_to? :each_line # HighLine adds #each_line alias to #each when each_line is not available. class String # alias to #each when each_line is not available. - alias_method :each_line, :each + alias each_line each end end diff --git a/lib/highline/custom_errors.rb b/lib/highline/custom_errors.rb index 2d45687..3f57395 100644 --- a/lib/highline/custom_errors.rb +++ b/lib/highline/custom_errors.rb @@ -1,5 +1,4 @@ class HighLine - # Internal HighLine errors. module CustomErrors # An error that responds to :explanation_key diff --git a/lib/highline/import.rb b/lib/highline/import.rb index c2e6084..46cb3db 100644 --- a/lib/highline/import.rb +++ b/lib/highline/import.rb @@ -38,11 +38,11 @@ class Object # @param details [lambda] block to be called with the question # instance as argument. # @return [String] answer - def or_ask( *args, &details ) + def or_ask(*args, &details) ask(*args) do |question| question.first_answer = String(self) - details.call(question) if details + yield(question) if details end end end diff --git a/lib/highline/list.rb b/lib/highline/list.rb index 1f2af2c..8e0a0b0 100644 --- a/lib/highline/list.rb +++ b/lib/highline/list.rb @@ -1,10 +1,8 @@ # coding: utf-8 class HighLine - # List class with some convenience methods like {#col_down}. class List - # Original given *items* argument. # It's frozen at initialization time and # all later transformations will happen on {#list}. @@ -33,7 +31,6 @@ class HighLine attr_reader :transpose_mode - # Content are distributed first by column in col down mode. # @return [Boolean] # @@ -141,9 +138,7 @@ class HighLine # Set the {#row_join_string}. # @see #row_join_string - def row_join_string=(string) - @row_join_string = string - end + attr_writer :row_join_string # Returns the row join string size. # Useful for calculating the actual size of @@ -178,4 +173,4 @@ class HighLine row.compact.join(row_join_string) + "\n" end end -end
\ No newline at end of file +end diff --git a/lib/highline/list_renderer.rb b/lib/highline/list_renderer.rb index fde6ad4..8052d71 100644 --- a/lib/highline/list_renderer.rb +++ b/lib/highline/list_renderer.rb @@ -118,7 +118,7 @@ class HighLine::ListRenderer HighLine::List.new(right_padded_items, cols: col_count, col_down: true).to_s end - def list_uneven_columns_mode(list=nil) + def list_uneven_columns_mode(list = nil) list ||= HighLine::List.new(items) col_max = option || items.size @@ -126,9 +126,9 @@ class HighLine::ListRenderer list.cols = column_count widths = get_col_widths(list) - if column_count == 1 or # last guess - inside_line_size_limit?(widths) or # good guess - option # defined by user + if column_count == 1 || # last guess + inside_line_size_limit?(widths) || # good guess + option # defined by user return pad_uneven_rows(list, widths) end end @@ -194,7 +194,7 @@ class HighLine::ListRenderer end def inside_line_size_limit?(widths) - line_size = widths.inject(0) { |sum, n| sum + n + row_join_str_size } + line_size = widths.reduce(0) { |sum, n| sum + n + row_join_str_size } line_size <= line_size_limit + row_join_str_size end @@ -211,16 +211,14 @@ class HighLine::ListRenderer end def line_size_limit - @line_size_limit ||= ( highline.wrap_at || 80 ) + @line_size_limit ||= (highline.wrap_at || 80) end def row_join_string @row_join_string ||= " " end - def row_join_string=(string) - @row_join_string = string - end + attr_writer :row_join_string def row_join_str_size row_join_string.size @@ -248,4 +246,4 @@ class HighLine::ListRenderer def row_count (items.count / col_count.to_f).ceil end -end
\ No newline at end of file +end diff --git a/lib/highline/menu.rb b/lib/highline/menu.rb index e1834ef..a743c4d 100644 --- a/lib/highline/menu.rb +++ b/lib/highline/menu.rb @@ -21,16 +21,16 @@ class HighLine # Pass +false+ to _color_ to turn off HighLine::Menu's # index coloring. # Pass a color and the Menu's indices will be colored. - def self.index_color=(color = :rgb_77bbff) - @index_color = color + class << self + attr_writer :index_color end # Initialize it self.index_color = false # Returns color used for coloring Menu's indices - def self.index_color - @index_color + class << self + attr_reader :index_color end # @@ -53,10 +53,10 @@ class HighLine # Initialize Question objects with ignored values, we'll # adjust ours as needed. # - super("Ignored", [ ], &nil) # avoiding passing the block along + super("Ignored", [], &nil) # avoiding passing the block along - @items = [ ] - @hidden_items = [ ] + @items = [] + @hidden_items = [] @help = Hash.new("There's no help for that topic.") @index = :number @@ -75,13 +75,13 @@ class HighLine @index_color = self.class.index_color # Override Questions responses, we'll set our own. - @responses = { } + @responses = {} # Context for action code. @highline = nil yield self if block_given? - init_help if @shell and not @help.empty? + init_help if @shell && !@help.empty? end # @@ -186,11 +186,11 @@ class HighLine # menu.help("rules", "The rules of this system are as follows...") # end - def choice( name, help = nil, text = nil, &action ) + def choice(name, help = nil, text = nil, &action) item = Menu::Item.new(name, text: text, help: help, action: action) @items << item @help.merge!(item.item_help) - update_responses # rebuild responses based on our settings + update_responses # rebuild responses based on our settings end # @@ -231,7 +231,7 @@ class HighLine # choice has more options available to you, like longer text or help (and # of course, individual actions) # - def choices( *names, &action ) + def choices(*names, &action) names.each { |n| choice(n, &action) } end @@ -242,7 +242,7 @@ class HighLine # @param action (see #choice) # @return (see #choice) - def hidden( name, help = nil, &action ) + def hidden(name, help = nil, &action) item = Menu::Item.new(name, text: name, help: help, action: action) @hidden_items << item @help.merge!(item.item_help) @@ -263,11 +263,11 @@ class HighLine # _index_suffix_ to a single space and _select_by_ to <tt>:name</tt>. # Because of this, you should make a habit of setting the _index_ first. # - def index=( style ) + def index=(style) @index = style # Default settings. - if @index == :none or @index.is_a?(::String) + if @index == :none || @index.is_a?(::String) @index_suffix = " " @select_by = :name end @@ -277,17 +277,17 @@ class HighLine # Initializes the help system by adding a <tt>:help</tt> choice, some # action code, and the default help listing. # - def init_help( ) + def init_help return if @items.include?(:help) topics = @help.keys.sort help_help = @help.include?("help") ? @help["help"] : - "This command will display helpful messages about " + - "functionality, like this one. To see the help for " + - "a specific topic enter:\n\thelp [TOPIC]\nTry asking " + - "for help on any of the following:\n\n" + - "<%= list(#{topics.inspect}, :columns_across) %>" - choice(:help, help_help) do |command, topic| + "This command will display helpful messages about " \ + "functionality, like this one. To see the help for " \ + "a specific topic enter:\n\thelp [TOPIC]\nTry asking " \ + "for help on any of the following:\n\n" \ + "<%= list(#{topics.inspect}, :columns_across) %>" + choice(:help, help_help) do |_command, topic| topic.strip! topic.downcase! if topic.empty? @@ -306,7 +306,7 @@ class HighLine # a help message. # @param help [String] the help message to be associated with the menu # item/title/name. - def help( topic, help ) + def help(topic, help) @help[topic] = help end @@ -339,14 +339,14 @@ class HighLine # will default to <tt>:none</tt> and _flow_ will default to # <tt>:inline</tt>. # - def layout=( new_layout ) + def layout=(new_layout) @layout = new_layout # Default settings. case @layout when :one_line, :menu_only self.index = :none - @flow = :inline + @flow = :inline end end @@ -392,7 +392,7 @@ class HighLine # @param details additional parameter to be passed when in shell mode. # @return [nil, Object] if @nil_on_handled is set it returns +nil+, # else it returns the action return value. - def select( highline_context, selection, details = nil ) + def select(highline_context, selection, details = nil) # add in any hidden menu commands items = all_items @@ -424,17 +424,17 @@ class HighLine item = items.find { |i| i.name == selection } return item if item l_index = "`" # character before the letter "a" - index = items.map { "#{l_index.succ!}" }.index(selection) + index = items.map { l_index.succ!.to_s }.index(selection) items[index] end def value_for_selected_item(item, details) if item.action - if @shell - result = item.action.call(item.name, details) - else - result = item.action.call(item.name) - end + result = if @shell + item.action.call(item.name, details) + else + item.action.call(item.name) + end @nil_on_handled ? nil : result else item.name @@ -451,7 +451,7 @@ class HighLine elsif selections.is_a?(Hash) value_for_hash_selections(items, selections, details) else - fail ArgumentError, 'selections must be either Array or Hash' + raise ArgumentError, 'selections must be either Array or Hash' end end @@ -512,23 +512,23 @@ class HighLine # Allows Menu to behave as a String, just like Question. Returns the # _layout_ to be rendered, which is used by HighLine.say(). # - def to_s( ) + def to_s case @layout when :list %(<%= header ? "#{header}:\n" : '' %>) + - parse_list + - show_default_if_any + - "<%= prompt %>" + parse_list + + show_default_if_any + + "<%= prompt %>" when :one_line %(<%= header ? "#{header}: " : '' %>) + - "<%= prompt %>" + - "(" + parse_list + ")" + - show_default_if_any + - "<%= prompt[/\s*$/] %>" + "<%= prompt %>" \ + "(" + parse_list + ")" + + show_default_if_any + + "<%= prompt[/\s*$/] %>" when :menu_only parse_list + - show_default_if_any + - "<%= prompt %>" + show_default_if_any + + "<%= prompt %>" else @layout end @@ -536,11 +536,11 @@ class HighLine def parse_list "<%= list( menu, #{@flow.inspect}, - #{@list_option.inspect} ) %>" + #{@list_option.inspect} ) %>" end def show_default_if_any - return default.to_s.empty? ? "" : "(#{default}) " + default.to_s.empty? ? "" : "(#{default}) " end # diff --git a/lib/highline/paginator.rb b/lib/highline/paginator.rb index 48792af..9be3821 100644 --- a/lib/highline/paginator.rb +++ b/lib/highline/paginator.rb @@ -3,7 +3,6 @@ class HighLine # Take the task of paginating some piece of text given a HighLine context class Paginator - # @return [HighLine] HighLine context attr_reader :highline @@ -36,7 +35,7 @@ class HighLine # Return last line if user wants to abort paging return "...\n#{lines.last}" unless continue_paging? end - return lines.join + lines.join end # @@ -47,7 +46,7 @@ class HighLine command = highline.new_scope.ask( "-- press enter/return to continue or q to stop -- " ) { |q| q.character = true } - command !~ /\A[qQ]\Z/ # Only continue paging if Q was not hit. + command !~ /\A[qQ]\Z/ # Only continue paging if Q was not hit. end end -end
\ No newline at end of file +end diff --git a/lib/highline/question.rb b/lib/highline/question.rb index 4f9560c..4d390dc 100755 --- a/lib/highline/question.rb +++ b/lib/highline/question.rb @@ -59,11 +59,11 @@ class HighLine @case = nil @in = nil @first_answer = nil - @directory = Pathname.new(File.expand_path(File.dirname($0))) + @directory = Pathname.new(File.expand_path(File.dirname($PROGRAM_NAME))) @glob = "*" - @user_responses = Hash.new + @user_responses = {} @internal_responses = default_responses_hash - @overwrite = false + @overwrite = false # allow block to override settings yield self if block_given? @@ -148,11 +148,11 @@ class HighLine # # Asks a yes or no confirmation question, to ensure a user knows what # they have just agreed to. The confirm attribute can be set to : - # +true+ : In this case the question will be, "Are you sure?". - # Proc : The Proc is yielded the answer given. The Proc must - # output a string which is then used as the confirm - # question. - # String : The String must use ERB syntax. The String is + # +true+ : In this case the question will be, "Are you sure?". + # Proc : The Proc is yielded the answer given. The Proc must + # output a string which is then used as the confirm + # question. + # String : The String must use ERB syntax. The String is # evaluated with access to question and answer and # is then used as the confirm question. # When set to +false+ or +nil+ (the default), answers are not confirmed. @@ -261,8 +261,8 @@ class HighLine def default_responses_hash { - :ask_on_error => "? ", - :mismatch => "Your entries didn't match." + ask_on_error: "? ", + mismatch: "Your entries didn't match." } end @@ -270,15 +270,15 @@ class HighLine # @param message_source (see #build_responses) # @return [Hash] responses hash def build_responses_new_hash(message_source) - { :ambiguous_completion => "Ambiguous choice. Please choose one of " + - choice_error_str(message_source) + '.', - :invalid_type => "You must enter a valid #{message_source}.", - :no_completion => "You must choose one of " + - choice_error_str(message_source) + '.', - :not_in_range => "Your answer isn't within the expected range " + - "(#{expected_range}).", - :not_valid => "Your answer isn't valid (must match " + - "#{validate.inspect})." } + { ambiguous_completion: "Ambiguous choice. Please choose one of " + + choice_error_str(message_source) + '.', + invalid_type: "You must enter a valid #{message_source}.", + no_completion: "You must choose one of " + + choice_error_str(message_source) + '.', + not_in_range: "Your answer isn't within the expected range " \ + "(#{expected_range}).", + not_valid: "Your answer isn't valid (must match " \ + "#{validate.inspect})." } end # This is the actual responses hash that gets used in determining output @@ -306,9 +306,9 @@ class HighLine # @return [String] upcased, downcased, capitalized # or unchanged answer String. def change_case(answer_string) - if [:up, :upcase].include?(@case) + if %i[up upcase].include?(@case) answer_string.upcase - elsif [:down, :downcase].include?(@case) + elsif %i[down downcase].include?(@case) answer_string.downcase elsif @case == :capitalize answer_string.capitalize @@ -369,7 +369,7 @@ class HighLine # Returns an English explanation of the current range settings. def expected_range - expected = [ ] + expected = [] expected << "above #{above}" if above expected << "below #{below}" if below @@ -402,9 +402,9 @@ class HighLine # are not checked. # def in_range? - (!above or answer > above) and - (!below or answer < below) and - (!@in or @in.include?(answer)) + (!above || answer > above) && + (!below || answer < below) && + (!@in || @in.include?(answer)) end # @@ -431,11 +431,11 @@ class HighLine def remove_whitespace(answer_string) if !whitespace answer_string - elsif [:strip, :chomp].include?(whitespace) + elsif %i[strip chomp].include?(whitespace) answer_string.send(whitespace) elsif whitespace == :collapse answer_string.gsub(/\s+/, " ") - elsif [:strip_and_collapse, :chomp_and_collapse].include?(whitespace) + elsif %i[strip_and_collapse chomp_and_collapse].include?(whitespace) result = answer_string.send(whitespace.to_s[/^[a-z]+/]) result.gsub(/\s+/, " ") elsif whitespace == :remove @@ -468,7 +468,7 @@ class HighLine File.basename(file) end else - [ ] + [] end end @@ -485,9 +485,9 @@ class HighLine # and case handling. # def valid_answer? - !validate or - (validate.is_a?(Regexp) and answer =~ validate) or - (validate.is_a?(Proc) and validate[answer]) + !validate || + (validate.is_a?(Regexp) && answer =~ validate) || + (validate.is_a?(Proc) && validate[answer]) end # @@ -534,11 +534,11 @@ class HighLine if confirm == true "Are you sure? " elsif confirm.is_a?(Proc) - confirm.call(self.answer) + confirm.call(answer) else # evaluate ERb under initial scope, so it will have # access to question and answer - template = ERB.new(confirm, nil, "%") + template = ERB.new(confirm, nil, "%") template_renderer = TemplateRenderer.new(template, self, highline) template_renderer.render end @@ -564,7 +564,7 @@ class HighLine # @param highline [HighLine] context # @return [void] def show_question(highline) - highline.say(self) unless (readline && (echo == true && !limit)) + highline.say(self) unless readline && (echo == true && !limit) end # Returns an echo string that is adequate for this Question settings. @@ -594,11 +594,11 @@ class HighLine # def append_default if template =~ /([\t ]+)\Z/ - template << "|#{default}|#{$1}" + template << "|#{default}|#{Regexp.last_match(1)}" elsif template == "" template << "|#{default}| " elsif template[-1, 1] == "\n" - template[-2, 0] = " |#{default}|" + template[-2, 0] = " |#{default}|" else template << " |#{default}|" end @@ -606,7 +606,7 @@ class HighLine def choice_error_str(message_source) if message_source.is_a? Array - '[' + message_source.join(', ') + ']' + '[' + message_source.join(', ') + ']' else message_source.inspect end diff --git a/lib/highline/question/answer_converter.rb b/lib/highline/question/answer_converter.rb index d4067f1..0bd0a78 100644 --- a/lib/highline/question/answer_converter.rb +++ b/lib/highline/question/answer_converter.rb @@ -100,4 +100,4 @@ class HighLine end end end -end
\ No newline at end of file +end diff --git a/lib/highline/question_asker.rb b/lib/highline/question_asker.rb index 06e6647..845914a 100644 --- a/lib/highline/question_asker.rb +++ b/lib/highline/question_asker.rb @@ -33,11 +33,9 @@ class HighLine if question.confirm raise NoConfirmationQuestionError unless @highline.send(:confirm, question) end - rescue ExplainableError => e explain_error(e.explanation_key) retry - rescue ArgumentError => error case error.message when /ambiguous/ @@ -68,7 +66,7 @@ class HighLine original_question_template = question.template verify_match = question.verify_match - begin # when verify_match is set this loop will repeat until unique_answers == 1 + begin # when verify_match is set this loop will repeat until unique_answers == 1 question.template = original_question_template answers = gather_answers_based_on_type @@ -87,7 +85,7 @@ class HighLine # @return [Array] answers def gather_integer gather_with_array do |answers| - (question.gather-1).times { answers << ask_once } + (question.gather - 1).times { answers << ask_once } end end @@ -112,7 +110,6 @@ class HighLine end end - private ## Delegate to Highline @@ -134,7 +131,7 @@ class HighLine if question.gather.is_a?(::String) || question.gather.is_a?(Symbol) answer.to_s == question.gather.to_s else question.gather.is_a?(Regexp) - answer.to_s =~ question.gather + answer.to_s =~ question.gather end end diff --git a/lib/highline/simulate.rb b/lib/highline/simulate.rb index c1ee6df..c0bb585 100644 --- a/lib/highline/simulate.rb +++ b/lib/highline/simulate.rb @@ -10,12 +10,9 @@ # # adapted from https://gist.github.com/194554 - class HighLine - # Simulates Highline input for use in tests. class Simulate - # Creates a simulator with an array of Strings as a script # @param strings [Array<String>] preloaded string to be used # as input buffer when simulating. @@ -31,7 +28,7 @@ class HighLine # Simulate StringIO#getbyte by shifting a single character off of the next line of the script def getbyte line = gets - if line.length > 0 + unless line.empty? char = line.slice! 0 @strings.unshift line char diff --git a/lib/highline/statement.rb b/lib/highline/statement.rb index 5e6e2f2..b5938a9 100644 --- a/lib/highline/statement.rb +++ b/lib/highline/statement.rb @@ -52,14 +52,14 @@ class HighLine end def format_statement - return template_string unless template_string.length > 0 + return template_string if template_string.empty? statement = render_template statement = HighLine::Wrapper.wrap(statement, highline.wrap_at) statement = HighLine::Paginator.new(highline).page_print(statement) - statement = statement.gsub(/\n(?!$)/,"\n#{highline.indentation}") if highline.multi_indent + statement = statement.gsub(/\n(?!$)/, "\n#{highline.indentation}") if highline.multi_indent statement end @@ -79,4 +79,4 @@ class HighLine HighLine.const_get(constant) end end -end
\ No newline at end of file +end diff --git a/lib/highline/string.rb b/lib/highline/string.rb index 162cfeb..7ceb244 100644 --- a/lib/highline/string.rb +++ b/lib/highline/string.rb @@ -3,7 +3,6 @@ require "highline/string_extensions" class HighLine - # # HighLine::String is a subclass of String with convenience methods added for colorization. # @@ -32,4 +31,4 @@ class HighLine class String < ::String include StringExtensions end -end
\ No newline at end of file +end diff --git a/lib/highline/string_extensions.rb b/lib/highline/string_extensions.rb index d2f2de4..95c8bd5 100644 --- a/lib/highline/string_extensions.rb +++ b/lib/highline/string_extensions.rb @@ -57,18 +57,18 @@ class HighLine # @todo Chain existing method_missing? undef :method_missing if method_defined? :method_missing - def method_missing(method, *args, &blk) + def method_missing(method, *_args) if method.to_s =~ /^(on_)?rgb_([0-9a-fA-F]{6})$/ color(method) else - raise NoMethodError, "undefined method `#{method}' for #<#{self.class}:#{'%#x'%self.object_id}>" + raise NoMethodError, "undefined method `#{method}' for #<#{self.class}:#{format('%#x', object_id)}>" end end private def setup_color_code(*colors) - color_code = colors.map{|color| color.is_a?(Numeric) ? '%02x'%color : color.to_s}.join + color_code = colors.map { |color| color.is_a?(Numeric) ? format('%02x', color) : color.to_s }.join raise "Bad RGB color #{colors.inspect}" unless color_code =~ /^[a-fA-F0-9]{6}/ color_code end diff --git a/lib/highline/style.rb b/lib/highline/style.rb index c53024a..8d6cebc 100755 --- a/lib/highline/style.rb +++ b/lib/highline/style.rb @@ -8,16 +8,14 @@ # # This is Free Software. See LICENSE and COPYING for details - class HighLine - # Creates a style using {.find_or_create_style} or # {.find_or_create_style_list} # @param args [Array<Style, Hash, String>] style properties # @return [Style] def self.Style(*args) args = args.compact.flatten - if args.size==1 + if args.size == 1 find_or_create_style(args.first) else find_or_create_style_list(*args) @@ -36,7 +34,7 @@ class HighLine if styles = Style.code_index[arg] styles.first else - Style.new(:code=>arg) + Style.new(code: arg) end elsif style = Style.list[arg] style @@ -45,9 +43,9 @@ class HighLine elsif arg.is_a?(Hash) Style.new(arg) elsif arg.to_s.downcase =~ /^rgb_([a-f0-9]{6})$/ - Style.rgb($1) + Style.rgb(Regexp.last_match(1)) elsif arg.to_s.downcase =~ /^on_rgb_([a-f0-9]{6})$/ - Style.rgb($1).on + Style.rgb(Regexp.last_match(1)).on else raise NameError, "#{arg.inspect} is not a defined Style" end @@ -62,12 +60,11 @@ class HighLine def self.find_or_create_style_list(*args) name = args - Style.list[name] || Style.new(:list=>args) + Style.list[name] || Style.new(list: args) end # ANSI styles to be used by HighLine. class Style - # Index the given style. # Uses @code_index (Hash) as repository. # @param style [Style] @@ -77,10 +74,10 @@ class HighLine @styles ||= {} @styles[style.name] = style end - if !style.list + unless style.list @code_index ||= {} @code_index[style.code] ||= [] - @code_index[style.code].reject!{|indexed_style| indexed_style.name == style.name} + @code_index[style.code].reject! { |indexed_style| indexed_style.name == style.name } @code_index[style.code] << style end style @@ -91,9 +88,9 @@ class HighLine # @return [void] def self.clear_index # reset to builtin only styles - @styles = list.select { |name, style| style.builtin } + @styles = list.select { |_name, style| style.builtin } @code_index = {} - @styles.each { |name, style| index(style) } + @styles.each { |_name, style| index(style) } end # Converts all given color codes to hexadecimal and @@ -106,7 +103,7 @@ class HighLine # HighLine::Style.rgb_hex(9, 10, "11") # => "090a11" def self.rgb_hex(*colors) colors.map do |color| - color.is_a?(Numeric) ? '%02x'%color : color.to_s + color.is_a?(Numeric) ? format('%02x', color) : color.to_s end.join end @@ -117,7 +114,7 @@ class HighLine # HighLine::Style.rgb_parts("090A0B") # => [9, 10, 11] def self.rgb_parts(hex) - hex.scan(/../).map{|part| part.to_i(16)} + hex.scan(/../).map { |part| part.to_i(16) } end # Search for or create a new Style from the colors provided. @@ -137,7 +134,7 @@ class HighLine style else parts = rgb_parts(hex) - new(:name=>name, :code=>"\e[38;5;#{rgb_number(parts)}m", :rgb=>parts) + new(name: name, code: "\e[38;5;#{rgb_number(parts)}m", rgb: parts) end end @@ -146,15 +143,15 @@ class HighLine # @return [Numeric] to be used as escape code on ANSI terminals def self.rgb_number(*parts) parts = parts.flatten - 16 + parts.inject(0) {|kode, part| kode*6 + (part/256.0*6.0).floor} + 16 + parts.reduce(0) { |kode, part| kode * 6 + (part / 256.0 * 6.0).floor } end # From an ANSI number (color escape code), craft an 'rgb_hex' code of it # @param ansi_number [Integer] ANSI escape code # @return [String] all color codes joined as {.rgb_hex} def self.ansi_rgb_to_hex(ansi_number) - raise "Invalid ANSI rgb code #{ansi_number}" unless (16..231).include?(ansi_number) - parts = (ansi_number-16).to_s(6).rjust(3,'0').scan(/./).map{|d| (d.to_i*255.0/6.0).ceil} + raise "Invalid ANSI rgb code #{ansi_number}" unless (16..231).cover?(ansi_number) + parts = (ansi_number - 16).to_s(6).rjust(3, '0').scan(/./).map { |d| (d.to_i * 255.0 / 6.0).ceil } rgb_hex(*parts) end @@ -170,7 +167,7 @@ class HighLine # Remove any ANSI color escape sequence of the given String. # @param string [String] - # @return [String] + # @return [String] def self.uncolor(string) string.gsub(/\e\[\d+(;\d+)*m/, '') end @@ -232,7 +229,7 @@ class HighLine # @return [String] the Style code def code if @list - @list.map{|element| HighLine.Style(element).code}.join + @list.map { |element| HighLine.Style(element).code }.join else @code end @@ -257,22 +254,22 @@ class HighLine # @param new_name [Symbol] # @param options [Hash] Style attributes to be changed # @return [Style] new Style with changed attributes - def variant(new_name, options={}) + def variant(new_name, options = {}) raise "Cannot create a variant of a style list (#{inspect})" if @list new_code = options[:code] || code if options[:increment] raise "Unexpected code in #{inspect}" unless new_code =~ /^(.*?)(\d+)(.*)/ - new_code = $1 + ($2.to_i + options[:increment]).to_s + $3 + new_code = Regexp.last_match(1) + (Regexp.last_match(2).to_i + options[:increment]).to_s + Regexp.last_match(3) end new_rgb = options[:rgb] || @rgb - self.class.new(self.to_hash.merge(:name=>new_name, :code=>new_code, :rgb=>new_rgb)) + self.class.new(to_hash.merge(name: new_name, code: new_code, rgb: new_rgb)) end # Uses the color as background and return a new style. # @return [Style] def on - new_name = ('on_'+@name.to_s).to_sym - self.class.list[new_name] ||= variant(new_name, :increment=>10) + new_name = ('on_' + @name.to_s).to_sym + self.class.list[new_name] ||= variant(new_name, increment: 10) end # @return [Style] a brighter version of this Style @@ -289,10 +286,10 @@ class HighLine def create_bright_variant(variant_name) raise "Cannot create a #{name} variant of a style list (#{inspect})" if @list - new_name = ("#{variant_name}_"+@name.to_s).to_sym - new_rgb = @rgb == [0,0,0] ? [128, 128, 128] : @rgb.map {|color| color==0 ? 0 : [color+128,255].min } + new_name = ("#{variant_name}_" + @name.to_s).to_sym + new_rgb = @rgb == [0, 0, 0] ? [128, 128, 128] : @rgb.map { |color| color == 0 ? 0 : [color + 128, 255].min } - find_style(new_name) or variant(new_name, :increment=>60, :rgb=>new_rgb) + find_style(new_name) || variant(new_name, increment: 60, rgb: new_rgb) end def find_style(name) diff --git a/lib/highline/template_renderer.rb b/lib/highline/template_renderer.rb index 9ac3970..e77f51a 100644 --- a/lib/highline/template_renderer.rb +++ b/lib/highline/template_renderer.rb @@ -42,9 +42,9 @@ class HighLine # is not available. # @return [String] error message. def method_missing(method, *args) - "Method #{method} with args #{args.inspect} " + - "is not available on #{self.inspect}. " + - "Try #{methods(false).sort.inspect}" + "Method #{method} with args #{args.inspect} " \ + "is not available on #{inspect}. " \ + "Try #{methods(false).sort.inspect}" end # @return [Question, Menu] {#source} attribute. @@ -59,4 +59,4 @@ class HighLine HighLine.const_get(name) end end -end
\ No newline at end of file +end diff --git a/lib/highline/terminal.rb b/lib/highline/terminal.rb index a76a136..d2b61a0 100755 --- a/lib/highline/terminal.rb +++ b/lib/highline/terminal.rb @@ -16,7 +16,6 @@ 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 @@ -57,8 +56,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 +65,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 +77,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 # 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, _options = {}) 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, options = {}) + 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, _options = {}) + 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 +135,7 @@ class HighLine Readline.readline(prompt, true) end - $VERBOSE = old_verbose + $VERBOSE = old_verbose raw_answer end @@ -148,8 +143,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 @@ -190,7 +185,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 + nil + end end # Restores terminal state using shell stty command. diff --git a/lib/highline/terminal/io_console.rb b/lib/highline/terminal/io_console.rb index eee152f..699db91 100644 --- a/lib/highline/terminal/io_console.rb +++ b/lib/highline/terminal/io_console.rb @@ -26,4 +26,4 @@ class HighLine end end end -end
\ No newline at end of file +end diff --git a/lib/highline/terminal/ncurses.rb b/lib/highline/terminal/ncurses.rb index 817cc23..3f399e0 100644 --- a/lib/highline/terminal/ncurses.rb +++ b/lib/highline/terminal/ncurses.rb @@ -34,4 +34,4 @@ class HighLine end end end -end
\ No newline at end of file +end diff --git a/lib/highline/terminal/unix_stty.rb b/lib/highline/terminal/unix_stty.rb index 3b9668a..1b6f761 100644 --- a/lib/highline/terminal/unix_stty.rb +++ b/lib/highline/terminal/unix_stty.rb @@ -5,25 +5,28 @@ class HighLine # HighLine::Terminal option that uses external "stty" program # to control terminal options. class UnixStty < Terminal - # A Unix savvy method using stty to fetch the console columns, and rows. # ... stty does not work in JRuby # @return (see Terminal#terminal_size) def terminal_size begin require "io/console" - winsize = IO.console.winsize.reverse rescue nil + winsize = begin + IO.console.winsize.reverse + rescue + nil + end return winsize if winsize rescue LoadError end - if /solaris/ =~ RUBY_PLATFORM and - `stty` =~ /\brows = (\d+).*\bcolumns = (\d+)/ - [$2, $1].map { |x| x.to_i } + if /solaris/ =~ RUBY_PLATFORM && + `stty` =~ /\brows = (\d+).*\bcolumns = (\d+)/ + [Regexp.last_match(2), Regexp.last_match(1)].map(&:to_i) elsif `stty size` =~ /^(\d+)\s(\d+)$/ - [$2.to_i, $1.to_i] + [Regexp.last_match(2).to_i, Regexp.last_match(1).to_i] else - [ 80, 24 ] + [80, 24] end end @@ -40,9 +43,9 @@ class HighLine end # (see Terminal#get_character) - def get_character( input = STDIN ) + def get_character(input = STDIN) input.getc end end end -end
\ No newline at end of file +end diff --git a/lib/highline/wrapper.rb b/lib/highline/wrapper.rb index ae93db6..eb3c138 100644 --- a/lib/highline/wrapper.rb +++ b/lib/highline/wrapper.rb @@ -1,12 +1,10 @@ # coding: utf-8 class HighLine - # A simple Wrapper module that is aware of ANSI escape codes. # It compensates for the ANSI escape codes so it works on the # actual (visual) line length. module Wrapper - # # Wrap a sequence of _lines_ at _wrap_at_ characters per line. Existing # newlines will not be affected by this process, but additional newlines @@ -18,24 +16,24 @@ class HighLine return text unless wrap_at wrap_at = Integer(wrap_at) - wrapped = [ ] + wrapped = [] text.each_line do |line| # take into account color escape sequences when wrapping - wrap_at = wrap_at + (line.length - actual_length(line)) + wrap_at += (line.length - actual_length(line)) while line =~ /([^\n]{#{wrap_at + 1},})/ - search = $1.dup - replace = $1.dup + search = Regexp.last_match(1).dup + replace = Regexp.last_match(1).dup if index = replace.rindex(" ", wrap_at) replace[index, 1] = "\n" replace.sub!(/\n[ \t]+/, "\n") line.sub!(search, replace) else - line[$~.begin(1) + wrap_at, 0] = "\n" + line[$LAST_MATCH_INFO.begin(1) + wrap_at, 0] = "\n" end end wrapped << line end - return wrapped.join + wrapped.join end # @@ -45,8 +43,8 @@ class HighLine # @param string_with_escapes [String] any ANSI colored String # @return [Integer] length based on the visual size of the String # (without the escape codes) - def self.actual_length( string_with_escapes ) + def self.actual_length(string_with_escapes) string_with_escapes.to_s.gsub(/\e\[\d{1,2}m/, "").length end end -end
\ No newline at end of file +end |