monotone

monotone Commit Details

Date:2011-11-23 12:46:38 (4 years 10 months ago)
Author:Richard Hopkins
Branch:net.venge.monotone
Commit:14cf20bd261593dbe98b0d5c64bc5690892f03f2
Parents: d69b6671da387f29b2acafba5ade90aaa190d0da
Message:Add colortone.pl which colors monotone output using ANSI escape codes

Windows users should probably create the '.bat' file as mentioned in the
file comments; makes using it much easier.
Changes:
Acontrib/colortone.pl (full)

File differences

contrib/colortone.pl
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env perl
use strict;
use warnings;
# colortone.pl - colors monotone output such as status, log and diff
#
# Reads input from STDIN and adds ANSI escape codes before outputting
# to STDOUT. Passing filenames on the command line is also supported.
#
# Windows systems need Win32::Console::ANSI installed to support showing
# color within cmd.exe.
#
# Usage
# mtn diff | colortone.pl
# mtn diff > diff.txt && colortone.pl diff.txt
#
# Windows Usage
# To make it easier to use, create a new file 'myname.bat' with the
# following contents (keeping quotes).
#
# @"C:\Program Files\monotone\mtn.exe" %* | perl "C:\Full\Path\To\colortone.pl"
#
# This allows you to use 'myname' as a replacement for mtn and output will
# be colored automatically. Only use it if your key passphrase is not
# required: diff, status, and log are fine.
#
# The piping has to be done through perl manually due to
# http://support.microsoft.com/kb/321788.
#
# Copyright 2011 Richard Hopkins
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use Term::ANSIColor;
if ( $^O eq 'MSWin32' ) {
use Win32::Console::ANSI;
}
# pattern => attributes
#
# pattern should contain a grouping as only the group will be colored.
#
# attributes is a single string containing any attributes supported by
# Term::ANSIColor separated with a space.
# eg. 'red on_white bold'
my %patterns = (
q/(^#.*)/ => 'yellow', # diff header
q/(^@@.*)/ => 'magenta', # diff encloser
q/(^\+.*)/ => 'green', # diff added
q/(^\|\s+\+.*)/ => 'green', # diff added (with graph)
q/(^-.*)/ => 'red', # diff removed
q/(^\|\s+-.*)/ => 'red', # diff removed (with graph)
q/([a-f0-9]{40})/ => 'magenta bold', # revision or file id
q/(^\| +\w+:)/ => 'white bold', # log header (with graph)
q/(^\w+:)/ => 'white bold', # status header
q/(^\*\*\*.+\*\*\*$)/ => 'yellow bold', # status warning
q/( added)/ => 'green', # status added
q/( patched)/ => 'cyan bold', # status patched
q/( dropped)/ => 'red', # status dropped
q/( renamed)/ => 'blue bold', # status renamed
);
my $reset = color('reset');
while (<>) {
# colorize any matching patterns in the current line.
foreach my $pattern ( keys %patterns ) {
my $color = color( $patterns{$pattern} );
$_ =~ s/$pattern/$color$1$reset/;
}
print colored $_;
}
exit(0);

Archive Download the corresponding diff file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status