Class: Grep::Lines
- Defined in:
- lib/glark/output/grep_lines.rb
Overview
This matches legacy grep, mostly. It is for running within emacs, thus, it does not support context or highlighting.
Instance Attribute Summary
Attributes inherited from Formatted
Attributes inherited from Results
Instance Method Summary collapse
- #add_match(startline, endline) ⇒ Object
- #print_file_name ⇒ Object
-
#print_line(lnum, ch = nil) ⇒ Object
prints the line, and adjusts for the fact that in our world, lines are 0-indexed, whereas they are displayed as if 1-indexed.
Methods inherited from Lines
#at_match_limit?, #display_matches?, #displayed_name, #initialize, #print_line_number, #process_end, #process_match, #set_status, #write_matches, #write_matching, #write_nonmatching
Methods inherited from Common
#at_match_limit?, #display_matches?, #displayed_name, #initialize, #process_match
Methods inherited from Formatted
#get_line_to_print, #initialize
Methods inherited from Results
Constructor Details
This class inherits a constructor from Lines
Instance Method Details
#add_match(startline, endline) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/glark/output/grep_lines.rb', line 35 def add_match startline, endline super # even with multi-line matches (--and expressions), we'll display # only the first matching line, not the range between the matches. set_status startline, startline end |
#print_file_name ⇒ Object
29 30 31 32 33 |
# File 'lib/glark/output/grep_lines.rb', line 29 def print_file_name if @show_file_name && displayed_name @out.print displayed_name, ":" end end |
#print_line(lnum, ch = nil) ⇒ Object
prints the line, and adjusts for the fact that in our world, lines are 0-indexed, whereas they are displayed as if 1-indexed.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/glark/output/grep_lines.rb', line 17 def print_line lnum, ch = nil ln = get_line_to_print lnum return unless ln print_file_name if @show_line_numbers @out.printf "%d: ", lnum + 1 end @out.print ln end |