App-ccdiff

 view release on metacpan or  search on metacpan

ccdiff  view on Meta::CPAN

	  "emacs!"		=> \$emacs,

	"a|ascii"		=> sub { $opt_a ^= 1 },
	"m|markers"		=> sub { $opt_m ^= 1 },
	"r|reverse|invert"	=> sub { $opt_r ^= 1 },
	"s|swap!"		=> sub { $opt_s ^= 1 },

	"i|ignore-case!"			=> \$opt_i,
	"w|ignore-all-space!"			=> \$opt_w,
	"b|ignore-ws|ignore-space-change!"	=> \$opt_b,
	"Z|ignore-trailing-space!"		=> \$opt_Z,
	"E|ignore-tab-expansion!"		=> \$opt_E, # NYI
	"B|ignore-blank-lines!"			=> \$opt_B, # Partly implemented

	  "old-label|label-old=s"		=> \$old_label,
	  "new-label|label-new=s"		=> \$new_label,

	"p|pink!"		=> sub { $old_color = "magenta" },
	  "old=s"		=> \$old_color,
	  "new=s"		=> \$new_color,
	  "bg=s"		=> \$rev_color,
	  "no-colors"		=> \$no_colors,
	  "list-colors!"	=> \$list_colors,
	  "settings|defaults"	=> sub {
		binmode STDOUT, ":encoding(utf-8)";
		printf "%-10s : %s\n", $_, $rc{$_} // "<undef>" for sort keys %rc;
		exit 0;
		},

	"v|verbose:1"	=> \$opt_v,
	) or usage (1);
    }

$opt_w      and $opt_b = $opt_Z = $opt_E = $opt_B = 1;
$opt_h >= 1 and $opt_h /= 100;

sub pod_text {
    require Pod::Text::Color;
    my $m = $no_colors ? "Pod::Text" : "Pod::Text::Color";
    my $p = $m->new ();
    open my $fh, ">", \my $out;
    $p->parse_from_file ($0, $fh);
    close $fh;
    print $out;
    exit 0;
    } # pod_text

sub pod_nroff {
    first { -x "$_/nroff" } grep { -d } split m/:+/ => $ENV{PATH} or pod_text ();

    require Pod::Man;
    my $p = Pod::Man->new ();
    open my $fh, "|-", "nroff", "-man";
    $p->parse_from_file ($0, $fh);
    close $fh;
    exit 0;
    } # pod_nroff

# Color initialization
for ($old_color, $new_color, $rev_color) {
    s/^(.*)[ _]bold$/bold $1/i;
    s/^bold_/bold /i;
    }
my %clr = map { $_ => color (s{^(.*)[ _]bold$}{bold $1}ir =~
                             s{^bold[ _]}{bold }ir) }
	  map {( $_, "on_$_", "bold $_" )}
    qw( red green blue black white cyan magenta yellow );
$clr{$_} //= color ($_) for tac_colors ();
$no_colors and $clr{$_} = "" for keys %clr;
$clr{none} = $clr{on_none} = "";

my ($reset,   $bg_new,  $bg_old,
    $chr_cml, $chr_cmr, $chr_ctx, $chr_eli, $chr_eql, $chr_lft,
    $chr_new, $chr_old, $chr_rgt,
    $clr_dbg, $clr_grn, $clr_new, $clr_old, $clr_red, $clr_rev,
    $cmp_sub) = (RESET);

if ($list_colors) {
    my @clr = map { sprintf "%s%-18s%s", $clr{$_}, $_, $reset } sort keys %clr;
    while (@clr) {
	say join "  " => map { $_ // "" } splice @clr, 0, 4;
	}
    exit;
    }

sub set_options {
    for ([ \$old_color, $rc{old} ], [ \$new_color, $rc{new} ], [ \$rev_color, $rc{bg} ]) {
	my ($c, $def) = @$_;
	$$c && exists $clr{$$c} and next;
	warn "color ", $$c // "(undefined)", " is unknown, using $def instead\n";
	$$c = $def;
	}
    $clr_red = $clr{$old_color};
    $clr_grn = $clr{$new_color};
    $clr_rev = $clr{$rev_color};
    $clr_dbg = $opt_r && exists $clr{"on_$rc{verbose}"} ? $clr{"on_$rc{verbose}"} : $clr{$rc{verbose}};
    $reset   = $no_colors ? "" : RESET;

    $bg_old = $clr{$rc{bg_old} || ($opt_r ? "on_$old_color" =~ s/bold //ir :
					       "on_$rev_color" =~ s/bold //ir)};
    $bg_new = $clr{$rc{bg_new} || ($opt_r ? "on_$new_color" =~ s/bold //ir :
					       "on_$rev_color" =~ s/bold //ir)};
    $clr_old = $opt_r ? $clr_rev . $bg_old : $clr_red . $bg_old;
    $clr_new = $opt_r ? $clr_rev . $bg_new : $clr_grn . $bg_new;
    $opt_s and ($clr_new, $clr_old) = ($clr_old, $clr_new);
    # Indicators
    if ($opt_a) {
	@rc{qw( chr_old chr_new chr_cml chr_cmr chr_eli chr_eli_v )} = qw( ^ ^ > < - <> );
	}
    elsif (!$opt_U) {
	$rc{$_} = encode ("utf-8", $rc{$_}) for qw( chr_old chr_new chr_cml chr_cmr chr_eli chr_eli_v );
	}
    $chr_old = $clr_old . $rc{chr_old} . $reset;
    $chr_new = $clr_new . $rc{chr_new} . $reset;
    $chr_cml = $clr_dbg . $rc{chr_cml} . $reset;
    $chr_cmr = $clr_dbg . $rc{chr_cmr} . $reset;
    $chr_eql =            $rc{chr_eql};
    $chr_lft = $clr_old . (defined $opt_u ? "-" : "< ") . $reset;
    $chr_rgt = $clr_new . (defined $opt_u ? "+" : "> ") . $reset;
    $chr_ctx =             defined $opt_u ? " " : "  ";
    $chr_eli = $opt_v >= 2 ? $rc{chr_eli_v} : $rc{chr_eli};
    $opt_m && $opt_v > 1 && length ($chr_eli) > 1 and $opt_m = 0;

    if ($opt_i || $opt_b || $opt_Z) {
	$rc{iwbzusepp} and $diff_class = "Algorithm::Diff";
	$cmp_sub = {
	    keyGen => sub {
		my $line = shift;
		$opt_i and $line = lc $line;
		$opt_Z and $line =~ s/[ \t\r]+$//g;
		$opt_b and $line =~ s/[ \t]+/ /g;
		return $line;
		}
	    };
	}
    } # set_options

if ($diff_class) {
    if ($diff_class =~ m/^(?:ad|pp|algorithm(?:-|::)diff(?:(?:-|::)pp)?)$/i) {
	$diff_class =
	    eval { require Algorithm::Diff;     "Algorithm::Diff";     }
	}
    elsif ($diff_class =~ m/^(?:adx|xs|algorithm(?:-|::)diff(?:-|::)xs)$/i) {
	$diff_class = "Algorithm::Diff::XS";
	$diff_class =
	    eval { require Algorithm::Diff::XS; "Algorithm::Diff::XS"; }
	}
    else {
	die "$diff_class is an unsupported Diff class\n";
	}
    }
else {
    $diff_class =
	eval { require Algorithm::Diff::XS; "Algorithm::Diff::XS"; }
     || eval { require Algorithm::Diff;     "Algorithm::Diff";     };
    }
$diff_class or die "Cannot load Algorithm::Diff:\n";

unless (caller) {
    if (@ARGV == 2 && -d $ARGV[0] && -d $ARGV[1]) {
	my ($d_from, $d_to) = @ARGV;
	my %fn;

ccdiff  view on Meta::CPAN

 - -- verbose : SPACE, LATIN CAPITAL LETTER C, LATIN CAPITAL LETTER D, SPACE
 + A B>cd<E>​<Fg
 + -- verbose : LATIN SMALL LETTER C, LATIN SMALL LETTER D, ZERO WIDTH SPACE

the word "verbose" and the character markers will be displayed using the
C<verbose> color. The characters used for the markers can be defined in your
configuration file as C<chr_cml> (the character used as marker on the left)
and C<chr_cmr> (the character used as marker on the right).

=item --markers -m

Use markers under each changed character in change-chunks.

C<--markers> is especially useful if the terminal does not support colors, or
if you want to copy/paste the output to (ASCII) mail. See also C<--ascii>. The
markers will have the same color as added or deleted text.

This will look like (with unified diff):

 5,5c5,5
 -Sat Dec 18 07:08:33 1998,I.O.D.U.,,756194433,1442539
 -               â–¼       â–¼
 +Sat Dec 18 07:00:33 1993,I.O.D.U.,,756194433,1442539
 +               â–²       â–²

The characters used for the markers can be defined in your configuration file
as C<chr_old> (the character used as marker under removed characters) and
C<chr_new> (the character used as marker under added characters).

If C<--ellipsis> is also in effect and either the C<chr_eli> is longer than
one character or C<--verbose> level is over 2, this option is automatically
disabled.

=item --ascii -a

Use (colored) ASCII indicators instead of Unicode. The default indicators are
Unicode characters that stand out better. The markers will have the same color
as added or deleted text.

For the vertical markers (C<-m>) that would look like:

 5,5c5,5
 -Sat Dec 18 07:08:33 1998,I.O.D.U.,,756194433,1442539
 -               ^       ^
 +Sat Dec 18 07:00:33 1993,I.O.D.U.,,756194433,1442539
 +               ^       ^

For the positional indicators, I did consider using U+034e (COMBINING UPWARDS
ARROW BELOW), but as most terminals are probably unable to show it due to line
height changes, I did not pursue the idea.

=item --pink -p

Change the default C<red> for deleted text to the color closest to pink that
is supported by L<Term::ANSIColor>: C<magenta>.

=item --reverse -r

Reverse/invert the foreground and background for the colored indicators.

If the foreground color has C<bold>, it will be stripped from the new background
color.

=item --swap -s

Swap the colors for new and old.

=item --list-colors

List available colors and exit.

=item --no-colors

Disable all colors. Useful for redirecting the diff output to a file that is to
be included in documentation.

This is the default if the environment variable C<$NO_COLOR> has a true value or
if the environment variable C<$CLICOLOR> is set to a false value.  If set,
C<$CLICOLOR_FORCE> will overrule the default of C<$NO_COLOR>.

=item --old=color

Define the foreground color for deleted text.

=item --new=color

Define the foreground color for added text.

=item --bg=color

Define the background color for changed text.

=item --index --idx -I

Prefix position indicators with an index.

 [001] 5,5c5,5
 -Sat Dec 18 07:08:33 1998,I.O.D.U.,,756194433,1442539
 +Sat Dec 18 07:00:33 1993,I.O.D.U.,,756194433,1442539

If a positive number is passed (C<--index=4> or C<-I 4>), display just the
chunk with that index, using the C<verbose> color:

This is useful in combination with C<--verbose>.

=item --threshold=2 -t 2

Defines the number of lines a change block may differ before the fall-back of
horizontal diff to vertical diff.

If a chunk describes a change, and the number of lines in the original block
has fewer or more lines than the new block and that difference exceeds this
threshold, C<ccdiff> will fall-back to vertical diff.

=item --heuristics=n -h n

Defines the percentage of character-changes a change block may differ before
the fall-back of horizontal diff to vertical diff.

This percentage is calculated as C<(characters removed + characters added) /
(2 * characters unchanged))>.

ccdiff  view on Meta::CPAN

The syntax of the file is one option per line, where leading and trailing
white-space is ignored. If that line then starts with one of the options
listed below, followed by optional white-space followed by either an C<=> or
a C<:>, followed by optional white-space and the values, the value is assigned
to the option. The values C<no> and C<false> (case insensitive) are aliases
for C<0>. The values C<yes> and C<true> are aliases to C<-1> (C<-1> being a
true value).

Between parens is the corresponding command-line option.

=over 2

=item unified (-u)

If you prefer unified-diff over old-style diff by default, set this to the
desired number of context lines:

 unified : 3

The default is undefined

=item markers (-m)

 markers : false

Defines if markers should be used under changed characters. The default is to
use colors only. The C<-m> command line option will toggle the option when set
from a configuration file.

=item ascii (-a)

 ascii   : false

Defines to use ASCII markers instead of Unicode markers. The default is to use
Unicode markers.

=item reverse (-r)

 reverse : false

Defines if changes are displayed as foreground-color over background-color
or background-color over foreground-color. The default is C<false>, so it will
color the changes with the appropriate color (C<new> or C<old>) over the
default background color.

=item swap (-s)

 swap    : false

Swap the colors for new and old.

=item new (--new)

 new     : green

Defines the color to be used for added text. The default is C<green>.

The color C<none> is also accepted and disables this color.

Any color accepted by L<Term::ANSIColor> is allowed. Any other color will
result in a warning. This option can include C<bold> either as prefix or
as suffix.

This option may also be specified as

 new-color
 new_color
 new-colour
 new_colour

=item old (--old)

 old     : red

Defines the color to be used for deleted text. The default is C<red>.

The color C<none> is also accepted and disables this color.

Any color accepted by L<Term::ANSIColor> is allowed. Any other color will
result in a warning. This option can include C<bold> either as prefix or
as suffix.

This option may also be specified as

 old-color
 old_color
 old-colour
 old_colour

=item bg (--bg)

 bg      : white

Defines the color to be used as background for changed text. The default is
C<white>.

The color C<none> is also accepted and disables this color.

Any color accepted by L<Term::ANSIColor> is allowed. Any other color will
result in a warning. The C<bold> attribute is not allowed.

This option may also be specified as

 bg-color
 bg_color
 bg-colour
 bg_colour
 background
 background-color
 background_color
 background-colour
 background_colour

=item header (-H --header --HC=color --header-color=color)

 header  : 1
 header  : blue_on_white

Defines if a header is displayed above the diff (default is 1), supported
colors are allowed.

If the value is a valid supported color, it will show the header in that
color scheme.  To disable the header set it to C<0> in the RC file or use
C<--no-header> as a command line argument.

=item old-label

=item new-label

Defines the tag(s) in the header for the source file(s)/stream(s).

 App::ccdiff::ccdiff ($left, $right);

 =>

 < *STDIN  Fri Nov  7 10:14:51 2025
 > *STDIN  Fri Nov  7 10:14:51 2025

 App::ccdiff::ccdiff ($left, $right,
    { "old-label" => "OLD", "new-label" => "NEW" });

 =>

 < OLD     Fri Nov  7 10:14:51 2025
 > NEW     Fri Nov  7 10:14:51 2025

=item verbose

 verbose : cyan

Defines the color to be used as color for the verbose tag. The default is
C<cyan>. This color will only be used under C<--verbose>.

The color C<none> is also accepted and disables this color.

Any color accepted by L<Term::ANSIColor> is allowed. Any other color will
result in a warning.

This option may also be specified as



( run in 0.545 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )