Module: Glark::Format
- Includes:
- Highlight
- Included in:
- Lines, UnfilteredLines
- Defined in:
- lib/glark/output/glark_format.rb
Constant Summary
Constants included from Highlight
Instance Method Summary collapse
- #initialize(file, spec) ⇒ 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.
- #print_line_number(lnum) ⇒ Object
- #println(ln, ch) ⇒ Object
- #show_file_header ⇒ Object
Methods included from Highlight
Instance Method Details
#initialize(file, spec) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/glark/output/glark_format.rb', line 14 def initialize file, spec @file_header = nil # not nil after file header written @fname_highlighter = spec.highlight && spec.file_highlight @lnum_highlighter = spec.line_number_highlight super 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.
54 55 56 57 58 59 60 |
# File 'lib/glark/output/glark_format.rb', line 54 def print_line lnum, ch = nil lnums = @file.get_region lnum return unless lnums lnums.each do |ln| println ln, ch end end |
#print_line_number(lnum) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/glark/output/glark_format.rb', line 29 def print_line_number lnum if @lnum_highlighter lnumstr = (lnum + 1).to_s pad = " " * ([4 - lnumstr.length, 0].max) @out.print pad + " " + adorn(@lnum_highlighter, lnumstr) + " " else super end end |
#println(ln, ch) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/glark/output/glark_format.rb', line 39 def println ln, ch if @show_line_numbers print_line_number ln end if ch && @print_context @out.printf "%s ", ch end line = get_line_to_print ln @out.puts line end |
#show_file_header ⇒ Object
22 23 24 25 26 27 |
# File 'lib/glark/output/glark_format.rb', line 22 def show_file_header if @show_file_name && @file_header.nil? && displayed_name @file_header = FileHeader.new displayed_name, @fname_highlighter @file_header.print @out end end |