Skip to content

Instantly share code, notes, and snippets.

@chew-z
Last active September 6, 2016 13:27
Show Gist options
  • Select an option

  • Save chew-z/ca6e5398d8d1fc5db07f067623f7bae1 to your computer and use it in GitHub Desktop.

Select an option

Save chew-z/ca6e5398d8d1fc5db07f067623f7bae1 to your computer and use it in GitHub Desktop.
Prints lines form mutt colorfile in designated colors. Usefull when tuning colors for mutt
#!/usr/bin/perl
# This simple perl scripts prints lines from mutt colorfile
# in actual designated colors.
# I have created that script for finetuning my mutt with
# iTerm color themes.
# I am using here mix of little known library Term::ExtendedColors
# for extended colors and escape codes for base16 colors.
# Term::ExtendedColors is weird with base16
# It looks fuzzy but works!
# Actual colors depend on definitions in terminal color palette first of all
# and ansi 256 colors are apoximate of true colors.
# I must admit all that - colors, terminals etc. are still a mystery to me.
# Script skips lines with comments (#) and empty lines
# but assumes that you have four columns separated by mix of
# spaces and tabs and optionally followed by inline comment starting with '#'
use strict;
use warnings;
use feature qw(say);
use Term::ExtendedColor qw(:all);
my $filename = "./mutt-colors-example.muttrc";
my @fgColors = (
'bold', 'black', 'red', 'blue', 'yellow', 'green',
'magenta', 'cyan', 'white', 'brightblack', 'brightred', 'brightblue',
'brightyellow', 'brightgreen', 'brightmagenta', 'brightcyan', 'brightwhite');
my @bgColors = (
'black', 'red', 'blue', 'yellow', 'green', 'magenta', 'cyan', 'white');
my %fg = (
# 'default' => "",
'bold' => "\e[1m",
'black' => "\e[30m",
'red' => "\e[31m",
'blue' => "\e[32m",
'yellow' => "\e[33m",
'green' => "\e[34m",
'magenta' => "\e[35m",
'cyan' => "\e[36m",
'white' => "\e[37m",
'brightblack' => "\e[1;30m",
'brightred' => "\e[1;31m",
'brightgreen' => "\e[1;32m",
'brightyellow' => "\e[1;33m",
'brightblue' => "\e[1;34m",
'brightmagenta' => "\e[1;35m",
'brightcyan' => "\e[1;36m",
'brightwhite' => "\e[1;37m",
);
my %bg = (
# 'default' => "",
'black' => "\e[40m",
'red' => "\e[41m",
'blue' => "\e[42m",
'yellow' => "\e[43m",
'green' => "\e[44m",
'magenta' => "\e[45m",
'cyan' => "\e[46m",
'white' => "\e[47m");
# Print palete 16
# foreach my $fgc (@fgColors)
# {
# print "$fg{$fgc}$bg{$_} Text \e[0m" for @bgColors;
# print "\n";
# }
my $default = 236; # declare default color = transparent = iTerm theme background
if ($#ARGV > -1) {
$filename = $ARGV[0];
}
say $filename;
open(my $fh, '<:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!";
my $linenumber = 0;
my $clear = clear();
while (my $line = <$fh>) {
$linenumber += 1;
$line =~ /^$/ and next; # skip empty line
$line =~ /^#/ and next; # skip comment
chomp($line);
my @row = split /\s+/, $line;
my ($fore, $back) = @row[2, 3]; # get fore- and background colors
print "$linenumber:\t";
if ($fore ~~ @fgColors) { # if fore is base16 print Esc chars
print "$fg{$fore}";
}
# if ($back eq 'default') { # if background is default (transparent)
# # print "\n$line";
# }
if ($back ~~ @bgColors ) { # if background is base16 print Esc chars
print "$bg{$back}";
}
# $fore = $default if $fore eq 'default';
$fore = substr($fore, 5) if substr($fore, 0, 5) eq 'color' ; # extract color number if $fore starts with 'color'
# $back = $default if $back eq 'default';
$back = substr($back, 5) if substr($back, 0, 5) eq 'color' ; # same for background
print fg($fore , bg($back , $line)) ; # prints line with fore- and background colors[1]
# [1] Term::ExtendedColors quietly skips arguments
# it cannot interpret (like base16 'red', 'cyan'..)
clear(); # reset colors via Term::ExtendedColors
print " \e[0m"; # print Esc character - reset (at end of line)
print "\n";
}
# vim: filetype=muttrc
# This is my attempt to have sane colors with Seoul256 as default in iTerm2 and
# vim.
# object can be one of:
# * attachment
# * body (match regexp in the body of messages)
# * bold (hiliting bold patterns in the body of messages)
# * error (error messages printed by Mutt)
# * header (match regexp in the message header)
# * hdrdefault (default color of the message header in the pager)
# * index (match pattern in the message index)
# * indicator (arrow or bar used to indicate the current item in a menu)
# * markers (the '+' markers at the beginning of wrapped lines in the pager)
# * message (informational messages)
# * normal (normal (not quoted) text
# * quoted (text matching $quote_regexp in the body of a message)
# * quoted1, quotedN (higher levels of quoting)
# * search (hiliting of words in the pager)
# * signature
# * status (mode lines used to display info about the mailbox or message)
# * tilde (the '~' used to pad blank lines in the pager)
# * tree (thread tree drawn in the message index and attachment menu)
# * underline (hiliting underlined patterns in the body of messages)
# default = transparent = iTerm theme background color
# basic colors ---------------------------------------------------------
color normal color252 default
color status magenta default
color message brightblue black
color indicator magenta color59
color error red default
color search yellow black
color tree color150 default
color markers brightyellow default
# index ----------------------------------------------------------------
color index color101 default "~N" # new messages
color index color203 default "~O" # old messages
color index color203 default "~D(!~p|~p)" # deleted
color index color203 default "~F" # flagged
color index color139 default "~T" # tagged messages
color index color203 default "~D" # deleted messages
color index color139 default "~Q" # messages that have been replied to
color index color139 default "~R" # read messages
color index color139 default "~U" # unread messages
color index color203 default "~P" # messages from me
color index color139 default "~N~p!~F" # new messages to me
color index color139 default "~U~p!~F" # unread messages to me
color index color139 default "~R~p!~F" # messages to me
# message headers ------------------------------------------------------
color hdrdefault yellow default
color header brightgreen default ^From:
color header brightgreen default ^To:
color header color152 default ^Reply-To:
color header color152 default ^Cc:
color header brightgreen default ^Subject:
# body -----------------------------------------------------------------
color normal color111 default
color tilde white default
color bold color244 default
color underline color73 default
color quoted color65 default
color attachment color221 default
color signature color117 default
# Border lines.
color body color33 default "( *[-+=#*~_]){6,}"
# highlight my name and other personally relevant strings
color body brightgreen default "(myself|me)"
# emoticons
color body color209 default "[;:][-o][)/(|]"
# email addresses
color body color152 default "((@(([0-9a-z-]+\\.)*[0-9a-z-]+\\.?|#[0-9]+|\\[[0-9]?[0-9]?[0-9]\\.[0-9]?[0-9]?[0-9]\\.[0-9]?[0-9]?[0-9]\\.[0-9]?[0-9]?[0-9]\\]),)*@(([0-9a-z-]+\\.)*[0-9a-z-]+\\.?|#[0-9]+|\\[[0-9]?[0-9]?[0-9]\\.[0-9]?[0-9]?[0-9]\\.[0-9]?[0-9]?[0-9]\\.[0-9]?[0-9]?[0-9]\\]):)?[0-9a-z_.+%$-]+@(([0-9a-z-]+\\.)*[0-9a-z-]+\\.?|#[0-9]+|\\[[0-2]?[0-9]?[0-9]\\.[0-2]?[0-9]?[0-9]\\.[0-2]?[0-9]?[0-9]\\.[0-2]?[0-9]?[0-9]\\])"
# URLs
color body color25 default "([a-z][a-z0-9+-]*://(((([a-z0-9_.!~*'();:&=+$,-]|%[0-9a-f][0-9a-f])*@)?((([a-z0-9]([a-z0-9-]*[a-z0-9])?)\\.)*([a-z]([a-z0-9-]*[a-z0-9])?)\\.?|[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)(:[0-9]+)?)|([a-z0-9_.!~*'()$,;:@&=+-]|%[0-9a-f][0-9a-f])+)(/([a-z0-9_.!~*'():@&=+$,-]|%[0-9a-f][0-9a-f])*(;([a-z0-9_.!~*'():@&=+$,-]|%[0-9a-f][0-9a-f])*)*(/([a-z0-9_.!~*'():@&=+$,-]|%[0-9a-f][0-9a-f])*(;([a-z0-9_.!~*'():@&=+$,-]|%[0-9a-f][0-9a-f])*)*)*)?(\\?([a-z0-9_.!~*'();/?:@&=+$,-]|%[0-9a-f][0-9a-f])*)?(#([a-z0-9_.!~*'();/?:@&=+$,-]|%[0-9a-f][0-9a-f])*)?|(www|ftp)\\.(([a-z0-9]([a-z0-9-]*[a-z0-9])?)\\.)*([a-z]([a-z0-9-]*[a-z0-9])?)\\.?(:[0-9]+)?(/([-a-z0-9_.!~*'():@&=+$,]|%[0-9a-f][0-9a-f])*(;([-a-z0-9_.!~*'():@&=+$,]|%[0-9a-f][0-9a-f])*)*(/([-a-z0-9_.!~*'():@&=+$,]|%[0-9a-f][0-9a-f])*(;([-a-z0-9_.!~*'():@&=+$,]|%[0-9a-f][0-9a-f])*)*)*)?(\\?([-a-z0-9_.!~*'();/?:@&=+$,]|%[0-9a-f][0-9a-f])*)?(#([-a-z0-9_.!~*'();/?:@&=+$,]|%[0-9a-f][0-9a-f])*)?)[^].,:;!)? \t\r\n<>\"]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment