File: format.rb

package info (click to toggle)
ruby-diffy 3.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 216 kB
  • sloc: ruby: 1,049; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 909 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module Diffy
  module Format
    # ANSI color output suitable for terminal output
    def color
      map do |line|
        case line
        when /^(---|\+\+\+|\\\\)/
          "\033[90m#{line.chomp}\033[0m"
        when /^\+/
          "\033[32m#{line.chomp}\033[0m"
        when /^-/
          "\033[31m#{line.chomp}\033[0m"
        when /^@@/
          "\033[36m#{line.chomp}\033[0m"
        else
          line.chomp
        end
      end.join("\n") + "\n"
    end

    # Basic text output
    def text
      to_a.join
    end

    # Basic html output which does not attempt to highlight the changes
    # between lines, and is more performant.
    def html_simple
      HtmlFormatter.new(self, options).to_s
    end

    # Html output which does inline highlighting of changes between two lines.
    def html
      HtmlFormatter.new(self, options.merge(:highlight_words => true)).to_s
    end
  end
end