21
21
require 'ronin/web/cli/command'
22
22
require 'ronin/support/network/http'
23
23
24
+ require 'command_kit/colors'
24
25
require 'nokogiri/diff'
25
26
26
27
module Ronin
@@ -46,6 +47,8 @@ module Commands
46
47
#
47
48
class Diff < Command
48
49
50
+ include CommandKit ::Colors
51
+
49
52
usage '[options] {URL | FILE} {URL | FILE}'
50
53
51
54
argument :page1 , required : true ,
@@ -81,12 +84,37 @@ def run(page1,page2)
81
84
doc2 = parse_doc ( page2 )
82
85
83
86
doc1 . diff ( doc2 ) do |change , node |
84
- unless change == ' '
85
- puts " #{ change } #{ node } "
87
+ unless change == ' ' # ignroe unchanged nodes
88
+ print_change ( change , node )
86
89
end
87
90
end
88
91
end
89
92
93
+ #
94
+ # Prints a change to the document.
95
+ #
96
+ # @param ["+", "-"] change
97
+ # The type of change.
98
+ #
99
+ # * `+` - indicates an added node.
100
+ # * `-` - indicates a removed node.
101
+ #
102
+ # @param [Nokogiri::HTML::Node, Nokogiri::HTML::Node] node
103
+ # The node that was changed.
104
+ #
105
+ def print_change ( change , node )
106
+ color = case change
107
+ when '+' then colors . method ( :green )
108
+ when '-' then colors . method ( :red )
109
+ end
110
+
111
+ content = node . to_s
112
+
113
+ content . each_line ( chomp : true ) do |line |
114
+ puts color . call ( "#{ change } #{ line } " )
115
+ end
116
+ end
117
+
90
118
#
91
119
# Reads a web page.
92
120
#
0 commit comments