Clean up terminal colour codes and partial prints on exit

Exiting a run partway through using ^C, SIGINT or SIGTERM can result in
unterminated colour codes.  Catching those signals and cleaning up the
line before exiting i a little safer.
Add support for search progress output

Add a new --show-progress option, which controls the output of search
progress during a search.  Each file being searched may be displayed as
a progress update; a new thread takes care of displaying progress
updates up to 20 times a second.  Progress is only shown in a terminal.
 Note that due to the additional tracking and updates required,
enabling --show-progress can make large searches a few percent slower,
but it may be perceived to be faster due to the progress output.
Fix a bug with shortoutput wrapping

The width of line numbers wasn't being checked correctly, resulting in
line wraps sometimes overflowing by a character.  This change should
correctly detect the width of line numbers.
Improved POSIX compliance, speed up progress thread termination

Move from the usleep() in the progress reporting thread to a
nanosleep() for POSIX.1-2001/POSIX.1-2008 compliance; leverage this to
also send a signal to the progress reporting thread at program end for
faster termination
Output linebreaks for lines not ending in linebreaks

When ag encountered lines which didn't end in a linebreak - for example
matching lines at the end of a file without a terminating linebreak -
the line was also output without a linebreak, causing run-together
output lines.  Fix this.