use Term::ANSIColor;

# Make pdflatex output prettier with QuieTeX
# <split>
if (rindex($pdflatex, "pdflatex", 0) == 0) {
    $pdflatex = "%(cmd)s $pdflatex";
} else {
    # $pdflatex doesn't start with "pdflatex", which means there's some other
    # customisation in latexmkrc already
    my $msg = 'It looks like $pdflatex is already customized in your latexmkrc, so ' .
        'QuieTeX will not insert itself.  To override this check, use ' .
        '`quietex --latexmkrc --force`.';
    if (-t STDERR) {
        # Only use color if a terminal is attached
        $msg = colored($msg, 'yellow')
    }
    print STDERR $msg, "\n";
}
# <split>
$pdflatex = "%(cmd)s $pdflatex";
# <split>

# Colour "Running pdflatex" etc messages
{
    no warnings 'redefine';
    my $old_warn_running = \&main::warn_running;
    sub color_warn_running {
        print STDERR color('green');
        $old_warn_running->(@_);
        print STDERR color('reset');
    }
    if (-t STDERR) {
        # Only use color if a terminal is attached
        *main::warn_running = \&color_warn_running;
    }
}
