use utf8;

my $esc = ['g9 mode', '+']; # globally label escape as meta key

my %commondef = (
	"\e"=> $esc,

	'H' => ['g2', "screen top"], # top-page
	'j' => ['g2', "entry <down>"], # next-entry, next-undeleted
	'k' => ['g2', "entry <up>"], # previous-entry, previous-undeleted
	'L' => ['g2', "screen bottom"], # bottom-page
	'^l'=> ['g1', "redraw"], # refresh
	'M' => ['g2', "screen middle"], # middle-page
	'^m'=> ['g6 mode^m', "select"], # select-entry, display-message
	'n' => ['g3', "search <down>"], # search-next
	'q' => ['g8 mode', "exit"], # exit
	't' => ['g4', "tag"], # tag-entry
	'z' => ['g2', "page <down>"], # next-page
	'Z' => ['g2', "page <up>"], # previous-page

	'*' => ['g2', "last entry"], # last-entry
	'=' => ['g2', "first entry"], # first-entry
	':' => ['g6', "enter command"], # enter-command
	';' => ['g6 arg', "apply to tagged"], # tag-prefix
	'>' => ['g2', "line <down>"], # next-line
	'<' => ['g2', "line <up>"], # previous-line
	']' => ['g2', "half page <down>"], # half-down
	'[' => ['g2', "half page <up>"], # half-up
	'?' => ['g1', "help"], # help
	'!' => ['g1 arg', "invoke shell"], # shell
	'/' => ['g3 arg mode/~', "search <down>"], # search
	'+/'=> ['g3 arg mode/~', "search <up>"], # search
);

{
title => 'Mutt',
version => '1.3',
description => [
	"Cheat sheet for the Mutt v2.2 e-mail client,",
	"showing the default binding for each key.",
],
keywords => [qw' mutt MUA email client '],

mode => {
	'' => 'index',
	'm' => 'compose (m)',
	w => 'message flags (w)',
	'/~' => 'search patterns (/~)',
},

flag => {
	g1 => [aside   => "Temporarily display something without changing state."],
	g2 => [select  => "Scroll list and/or select a different line."],
	g3 => [search  => "Go to a specific message entry."],
	g4 => [edit    => "Modify message flags or contents."],
	g6 => [command => "Any other action which does not alter an existing message."],
	g7 => [send    => "Prepare and/or send a (new) message."],
	g8 => [leave   => "Exit the opened folder."],
	g9 => [display => "Permanently alter/toggle current view."],

	arg => ["key<arg>" => "Commands with a dot need an argument afterwards."],
},

def => {
	'' => {
		%commondef,

		'@' => ['g1', "display sender"], # display-address
		'.' => ['g8', "list new mail"], # buffy-list #TODO
		'|' => ['g6', "pipe to shell"], # pipe-message
		'$' => ['g4', "save mailbox"], # sync-mailbox
		'#' => ['g4', "split up thread"], # break-thread
		'&' => ['g4', "thread tagged"], # link-threads
		'%' => ['g4', "toggle reado<>nl<>y"], # toggle-write
		'-' => ['g9', "collapse thread"],
		'_' => ['g9', "collapse all"],
		'~' => ['g4 arg', "save mark"], # mark-message #TODO
		"'" => ['g3 arg', "marked mes<>sag<>e"],
		' ' => \'^m',

		'a' => ['g6', "create alias"], # create-alias
		'b' => ['g7', "bounce"], # bounce-message
		'^b'=> ['g1', "url<>view"],
		'+b'=> [undef, "search bodies"], # M <search>~b
		'c' => ['g8', "open folder"], # change-folder
		'C' => ['g6', "copy messag<>e"], # copy-message
		'+c'=> ['g8', "open reado<>nly"], # change-folder-readonly
		'+C'=> [undef, "make plain copy"], # decode-copy
		'd' => ['g4', "delete"], # delete-message
		'D' => ['g4 arg mode/~', "delete patt<>er<>n"], # delete-pattern
		'^d'=> ['g4', "delete thread"], # delete-thread
		'+d'=> ['g4', "delete subthread"], # delete-subthread
		'e' => ['g4 linkvi', "edit"], # edit
		'^e'=> ['g4', "edit con<>tent type"], # edit-type
		'+e'=> [undef, "edit+send copy"], # resend-message
		'f' => ['g7 modem', "forward"], # forward-message
		'F' => ['g4', "toggle important"], # flag-message
		'^f'=> ['g6', "forget pass<>phras<>e"], # forget-passphrase
		'g' => ['g7 modem', "reply to all\nGroup reply"], # group-reply
		'G' => ['g6', "fetch POP\nGather new mail"], # fetch-mail
		'i' => ['g6', "fetch IMAP"], # imap-fetch-mail
		'^i'=> ['g3', "unread msg <down>"], # next-new-then-unread
		'+^i'=> [undef, "unread msg <up>"], # previous-new-then-unread
		'j' => ['g2', "messag<>e <down>"], # next-undeleted
		'k' => ['g2', "messag<>e <up>"], # previous-undeleted
		'J' => ['g3', "any <down>"], # next-entry
		'K' => ['g3', "any <up>"], # previous-entry
		'^k'=> ['g1', "extract pub keys"], # extract-keys
		'+k'=> ['g7 modem', "send public key"], # mail-key
		'l' => ['g9 arg mode/~', "limit pattern"], # limit
		'L' => ['g7 modem', "reply to list"], # list-reply
		'+l'=> ['g1', "mlist actions"], # list-actions/show-limit
		#'+l'=> [, "show current limit"],
		'm' => ['g7 modem', "compo<>s<>e mail"], # mail
		'N' => ['g4', "toggle new"], # toggle-new
		'^n'=> ['g3', "thread <down>"], # next-thread
		'+n'=> ['g3', "subthr<>ead <down>"], # next-subthread
		'o' => ['g9 modeo', "sort"], # sort-mailbox
		'O' => ['g9 modeo', "sort reverse"], # sort-reverse
		'p' => ['g1', "print"], # print-message
		'P' => ['g3', "to parent"], # parent-message
		'^p'=> ['g3', "thread <up>"], # previous-thread
		'+p'=> ['g3', "subthr<>ead <up>"], # previous-subthread
		'+P'=> [undef, "check for pgp"], # check-traditional-pgp
		'q' => ['g8', "quit"], # quit
		'Q' => ['g1 arg', "query addr<>ess<>es"], # query
		'r' => ['g7 modem', "reply to sender"], # reply
		'R' => ['g7 modem', "recall postpon<>e<>d"], # recall-message
		'^r'=> ['g4', "mark thread read"], # read-thread
		'+r'=> ['g4', "mark sub<>thread r<>ead"], # read-subthread
		's' => ['g4', "move"], # save-message
		'+s'=> ['g4', "save and delete"], # decode-save
		'T' => ['g4 arg mode/~', "tag patt<>er<>n"], # tag-pattern
		'^t'=> ['g4 arg mode/~', "untag pattern"], # untag-pattern
		'+t'=> ['g4', "tag thread"], # tag-thread
		'u' => ['g4', "undo delete"], # undelete-message
		'U' => ['g4 arg mode/~', "res<>tore pat<>t<>er<>n"], # undelete-pattern
		'^u'=> ['g4', "restore thread"], # undelete-thread
		'+u'=> ['g4', "restore subthread"], # undelete-subthread
		'v' => ['g1', "attach<>ments"], # view-attachments
		'V' => ['g1', "version"], # show-version
		'+v'=> ['g9', "(un)collapse thread"], # collapse-thread
		'+V'=> ['g9', "(un)collapse threads"], # collapse-all
		'w' => ['g4 arg modew', "set flag"], # set-flag
		'W' => ['g4 arg modew', "clear flag"], # clear-flag
		'x' => ['g8', "abort"], # exit
		'y' => ['g8', "list incoming mailboxes"], # M <change-folder>?<toggle-mailboxes>
		'Y' => ['g4 arg', "edit label"], # edit-label
	}, # index

	'm' => {
		%commondef,

		'|' => ['g4', "pipe attach<>m<>ent"],
		'a' => ['g4', "attach file"],
		'A' => ['g4', "attach messag<>e"],
		'b' => ['g4', "edit bcc"],
		'^b'=> ['g1', "url<>view"],
		'c' => ['g4', "edit cc"],
		'C' => ['g6', "copy file"],
		'd' => ['g4', "desc<>ribe attach<>m<>ent"],
		'D' => ['g4', "delete attach<>m<>ent"],
		'^d'=> ['g4', "dispo<>sition tog<>gle"],
		'e' => ['g4 linkvi', "edit body"],
		'E' => ['g4 linkvi', "edit all"],
		'^e'=> ['g4', "edit encoding"],
		'f' => ['g4', "edit fcc"],
		'^f'=> ['g6', "forget pass<>phrase"],
		'+f'=> ['g4', "edit from"],
		'F' => ['g4', "filter attach<>m<>ent"],
		'G' => ['g1', "get attach<>m<>ent"],
		'h' => ['g1', "display message"],
		'i' => ['g6', "run ispell"],
		'+k'=> ['g4', "attach PGP key"],
		'l' => ['g1', "print attach<>m<>ent"],
		'm' => ['g4', "edit attach<>m<>ent\nMime-appropriate open"],
		'M' => ['g4', "edit mix"],
		'^m'=> ['g1', "view attach<>m<>ent"],
		'n' => ['g6', "new attach<>m<>ent"],
		'o' => ['g4 ext', "autocrypt toggle"], #TODO
		'^o'=> ['g4', "rename attach<>m<>ent"],
		'p' => ['g1', "PGP menu"], #TODO
		'P' => ['g8 mode', "post<>pone"],
		'r' => ['g4', "edit reply<>-to"],
		'R' => ['g4', "rename attach<>m<>ent"],
		's' => ['g4', "edit subject"],
		'S' => ['g4 menumS', "s/mime options"],
		't' => ['g4', "edit to"],
		'T' => ['g4', "enter tags"], #TODO
		'^t'=> ['g4', "ctype attach<>m<>ent"],
		'w' => ['g6', "copy to folder"],
		'u' => ['g6', "unlink toggle"],
		'v' => ['g1', "preview alt fil<>t<>er"], # m+v mV
		'+v'=> 'g1',
		'V' => ['g1', "preview mailcap filter"],
		'U' => ['g4', "encode attach<>m<>ent"],
		'y' => ['g7', "send"],
		# ^xe
	}, # compose

	w => {
		"\e"=> $esc,
		'D' => ['g4', "deleted"],
		'd' => \'wD',
		'N' => ['g4', "new"],
		'n' => \'wN',
		'O' => ['g4', "old"],
		'o' => \'wO',
		'r' => ['g4', "replied"],
		'R' => \'wr',
		'*' => ['g4', "tagged"],
		'!' => ['g4', "flagged"],
	}, # flag

	'/~' => {
		"\e"=> $esc,
		'A' => ['g3', => "all"],
		'b' => ['g3 arg', => "msg body"],
		'B' => ['g3 arg', => "whole msg"],
		'c' => ['g3 arg', => "cc address"],
		'C' => ['g3 arg', => "to or cc address"],
		'd' => ['g3 arg', => "date sent ran<>g<>e"],
		'D' => ['g3', => "deleted"],
		'e' => ['g3 arg', => "sender"],
		'E' => ['g3', => "expired"],
		'f' => ['g3 arg', => "from"],
		'F' => ['g3', => "flagged"],
		'g' => ['g3', => "signed"],
		'G' => ['g3', => "encryp<>ted"],
		'h' => ['g3 arg', => "header"],
		'H' => ['g3 arg', => "spam attr<>ib<>ute"],
		'i' => ['g3 arg', => "msg id"],
		'k' => ['g3', => "pgp key"],
		'L' => ['g3 arg', => "receiv<>d by"],
		'l' => ['g3', => "mailing list"],
		'm' => ['g3 arg', => "num<>ber ran<>g<>e"],
		'M' => ['g3 arg', => "mime type"],
		'n' => ['g3 arg', => "score range"],
		'N' => ['g3', => "new"],
		'O' => ['g3', => "old"],
		'p' => ['g3', => "to you"],
		'P' => ['g3', => "by you"],
		'Q' => ['g3', => "replies"],
		'r' => ['g3 arg', => "receive date ran<>ge"],
		'R' => ['g3', => "read"],
		's' => ['g3', => "subject"],
		'S' => ['g3', => "super<>seded"],
		't' => ['g3 arg', => "to address"],
		'T' => ['g3', => "tagged"],
		'u' => ['g3', => "subscr<>ibed list"],
		'U' => ['g3', => "unread"],
		'v' => ['g3', => "collapsed thread"],
		'V' => ['g3', => "verified"],
		'x' => ['g3 arg', => "refer<>ence"],
		'X' => ['g3 arg', => "attach<>ments"],
		'y' => ['g3 arg', => "x-label"],
		'z' => ['g3 arg', => "size range"],
		'=' => ['g3', => "dupli<>cate"],
		'$' => ['g3', => "unrefer<>enced"],
		'(' => ['g3 arg', => "in thread"],
		'<' => ['g3 arg', => "parent match"],
		'>' => ['g3 arg', => "child match"],
	}, # search option
},
}
