module Diakonos

This file is completely overwritten by install.rb upon installation. This copy is here to permit the tests to execute.

Constants

ADJUST_ROW
AFTER_CHAR
ASK_REPLACEMENT
ASK_REVERT
BACKSPACE
BOL_ALT_FIRST_CHAR
BOL_ALT_ZERO
BOL_FIRST_CHAR
BOL_ZERO
CASE_INSENSITIVE
CASE_SENSITIVE
CHOICE_ALL
CHOICE_CANCEL
CHOICE_DELETE
CHOICE_NO

TODO: Turn the CHOICE_* constants into one or more Hashes?

CHOICE_NO_TO_ALL
CHOICE_WITHIN_SELECTION
CHOICE_YES
CHOICE_YES_AND_STOP
CHOICE_YES_TO_ALL
CLEAR_STACK_POINTER
CTRL_C
CTRL_D
CTRL_H
CTRL_K
CTRL_Q
CTRL_W
DEFAULT_TAB_SIZE
DIFFERENT_FILE
DONT_ADJUST_ROW
DONT_CLEAR_STACK_POINTER
DONT_COMPLETE
DONT_PROMPT_OVERWRITE
DONT_REDRAW
DO_REDRAW
ENTER
EOL_ALT_END
EOL_ALT_LAST_CHAR
EOL_END
EOL_LAST_CHAR
ESCAPE
FORCE_REVERT
INCLUSIVE
INSTALL_SETTINGS
LANG_TEXT
LAST_MODIFIED
NOISY
NOT_DIFFERENT_FILE
NOT_INCLUSIVE
NO_REPLACEMENT
ON_CHAR
PROMPT_OVERWRITE
QUIET
RESIZE2
TAB
VERSION

Public Class Methods

check_ruby_version() click to toggle source
# File lib/diakonos/version.rb, line 11
def self.check_ruby_version
  ruby_version = parse_version( RUBY_VERSION )
  if ruby_version < [ 2, 1 ]
    $stderr.puts "This version of Diakonos (#{Diakonos::VERSION}) requires Ruby 2.1 or higher."
    if ruby_version >= [ 2, 0 ]
      $stderr.puts "Version 0.9.5 is the last version of Diakonos which can run under Ruby 2.0."
    elsif ruby_version >= [ 1, 9 ]
      $stderr.puts "Version 0.9.2 is the last version of Diakonos which can run under Ruby 1.9."
    elsif ruby_version >= [ 1, 8 ]
      $stderr.puts "Version 0.8.9 is the last version of Diakonos which can run under Ruby 1.8."
    end
    exit 1
  end
end
grep_array( regexp, array, lines_of_context, prefix, filepath ) click to toggle source
# File lib/diakonos/grep.rb, line 2
def self.grep_array( regexp, array, lines_of_context, prefix, filepath )
  num_lines = array.size
  line_numbers = []
  array.each_with_index do |line,index|
    next if line !~ regexp
    start_index = [ 0, index - lines_of_context ].max
    end_index = [ index + lines_of_context, num_lines-1 ].min
    (start_index..end_index).each do |i|
      line_numbers << i
    end
  end

  line_numbers.uniq!
  results = []
  last_i = line_numbers[ 0 ]
  one_result = []
  line_numbers.each do |i|
    if i - last_i > 1
      results << one_result.join( "\n" )
      one_result = []
    end
    one_result << ( "#{prefix}#{i+1}: " << ( "%-300s | #{filepath}:#{i+1}" % array[ i ] ) )
    last_i = i
  end
  if ! one_result.empty?
    results << one_result.join( "\n" )
  end

  results
end
parse_filename_and_line_number( s ) click to toggle source

@return [Array] the filename and line number parsed

# File lib/diakonos.rb, line 126
def self.parse_filename_and_line_number( s )
  if(
    # Ruby
    s =~ /from (.+):(\d+)/ ||
    # Python
    s =~ /File "(.+)", line (\d+)/ ||
    # Perl
    s =~ /at (.+) line (\d+)/ ||
    # generic
    s =~ /^(.+):(\d+)/
  )
    [ $1, ( $2.to_i - 1 ) ]
  else
    [ s, nil ]
  end
end
parse_version( s ) click to toggle source
# File lib/diakonos/version.rb, line 5
def self.parse_version( s )
  if s
    s.split( '.' ).map { |part| part.to_i }.extend( Comparable )
  end
end