1package Text::WordDiff::ANSIColor;
2
3use strict;
4use Term::ANSIColor qw(:constants);
5use vars qw($VERSION @ISA);
6
7# Term::ANSIColor doesn't support STRIKETHROUGH, so we'll do it ourselves.
8use constant STRIKETHROUGH => "\e[9m";
9
10$VERSION = '0.08';
11@ISA = qw(Text::WordDiff::Base);
12
13sub same_items {
14    shift;
15    return join '', @_;
16}
17
18sub delete_items {
19    shift;
20    return join '', BOLD, RED, STRIKETHROUGH, @_, RESET;
21}
22
23sub insert_items {
24    shift;
25    return join '', BOLD, GREEN, UNDERLINE, @_, RESET;
26}
27
281;
29__END__
30
31=begin comment
32
33Fake-out Module::Build. Delete if it ever changes to support =head1 headers
34other than all uppercase.
35
36=head1 NAME
37
38Text::WordDiff::ANSIColor - ANSI colored formatting for Text::WordDiff
39
40=end comment
41
42=head1 Name
43
44Text::WordDiff::ANSIColor - ANSI colored formatting for Text::WordDiff
45
46=head1 Synopsis
47
48    use Text::WordDiff;
49
50    my $diff = word_diff 'file1.txt', 'file2.txt';
51    my $diff = word_diff \$string1,   \$string2,   { STYLE => 'ANSIColor' };
52    my $diff = word_diff \*FH1,       \*FH2;       \%options;
53    my $diff = word_diff \&reader1,   \&reader2;
54    my $diff = word_diff \@records1,  \@records2;
55
56    # May also mix input types:
57    my $diff = word_diff \@records1,  'file_B.txt';
58
59=head1 Description
60
61This class subclasses Text::WordDiff::Base to provide a formatting class for
62Text::WordDiff that uses ANSI-standard terminal escape sequences to highlight
63deleted and inserted text. This formatting class is the default class used by
64L<Text::WordDiff|Text::WordDiff>; see its documentation for details on its
65interface. This class should never be used directly.
66
67Text::WordDiff::ANSIColor formats word diffs for viewing in an ANSI-standard
68terminal session. The diff content is highlighted as follows:
69
70=over
71
72=item Deletes
73
74Deleted words will display in bold-faced red. The ANSI standard for
75strikethrough is also used, but since it is not supported by most terminals,
76likely will not show up.
77
78=item Inserts
79
80Inserted words will display in bold-faced, underlined green.
81
82=back
83
84All other content is simply returned.
85
86=head1 See Also
87
88=over
89
90=item L<Text::WordDiff|Text::WordDiff>
91
92=item L<Text::WordDiff::HTML|Text::WordDiff::HTML>
93
94=back
95
96=head1 Support
97
98This module is stored in an open repository at the following address:
99
100L<https://svn.kineticode.com/Text-WordDiff/trunk/>
101
102Patches against Text::WordDiff are welcome. Please send bug reports to
103<bug-text-worddiff@rt.cpan.org>.
104
105=head1 Author
106
107=begin comment
108
109Fake-out Module::Build. Delete if it ever changes to support =head1 headers
110other than all uppercase.
111
112=head1 AUTHOR
113
114=end comment
115
116David Wheeler <david@kineticode.com>
117
118=head1 Copyright and License
119
120Copyright (c) 2005-2011 David E. Wheeler. Some Rights Reserved.
121
122This module is free software; you can redistribute it and/or modify it under the
123same terms as Perl itself.
124
125=cut
126