summaryrefslogtreecommitdiffstats
path: root/color/quoted.h
blob: ccca2c4cb7162077acba1ade116feffa002d76e2 (plain) (blame)
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
/**
 * @file
 * Quoted-Email colours
 *
 * @authors
 * Copyright (C) 2021 Richard Russon <rich@flatcap.org>
 *
 * @copyright
 * 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/>.
 */

#ifndef MUTT_COLOR_QUOTED_H
#define MUTT_COLOR_QUOTED_H

#include "config.h"
#include <stddef.h>
#include <stdbool.h>
#include "core/lib.h"
#include "attr.h"
#include "color.h"
#include "curses2.h"

struct Buffer;

/// Ten colours, quoted0..quoted9 (quoted and quoted0 are equivalent)
#define COLOR_QUOTES_MAX 10

extern struct AttrColor QuotedColors[];
extern int NumQuotedColors;

/**
 * struct QuoteStyle - Style of quoted text
 *
 * NeoMutt will store a tree of all the different email quoting levels it
 * detects in an Email.  If `$quote_regex` matches, say both "> " and "| ",
 * and the Email has three levels of indent, then the tree will contain two
 * siblings each with a child and grandchild.
 *
 * @dot
 * digraph QuoteStyle
 * {
 *   node [ shape="box" style="filled" fillcolor="#e0ffff" ]
 *   angle1 [ label=<"&gt;"> ]
 *   angle2 [ label=<"&gt; &gt;"> ]
 *   angle3 [ label=<"&gt; &gt; &gt;"> ]
 *   bar1 [ label=<"|"> ]
 *   bar2 [ label=<"| |"> ]
 *   bar3 [ label=<"| | |"> ]
 *   angle1 -> angle2 -> angle3
 *   bar1 -> bar2 -> bar3
 *   angle1 -> bar1
 *   { rank=same angle1 bar1 }
 * }
 * @enddot
 */
struct QuoteStyle
{
  int quote_n;                      ///< The quoteN colour index for this level
  struct AttrColor *attr_color;     ///< Colour and attribute of the text
  char *prefix;                     ///< Prefix string, e.g. "> "
  size_t prefix_len;                ///< Length of the prefix string
  struct QuoteStyle *prev, *next;   ///< Different quoting styles at the same level
  struct QuoteStyle *up, *down;     ///< Parent (less quoted) and child (more quoted) levels
};

void               quoted_colors_cleanup(void);
struct AttrColor * quoted_colors_get(int q);
int                quoted_colors_num_used(void);

bool               quoted_colors_parse_color  (enum ColorId cid, color_t fg, color_t bg, int attrs, int q_level, int *rc, struct Buffer *err);
enum CommandResult quoted_colors_parse_uncolor(enum ColorId cid, int q_level, struct Buffer *err);

struct QuoteStyle *qstyle_classify (struct QuoteStyle **quote_list, const char *qptr, size_t length, bool *force_redraw, int *q_level);
void               qstyle_free_tree(struct QuoteStyle **quote_list);
void               qstyle_recolour (struct QuoteStyle *quote_list);

#endif /* MUTT_COLOR_QUOTED_H */