• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

neomutt / neomutt / 12308706524

12 Dec 2024 04:06PM UTC coverage: 49.224% (-0.02%) from 49.243%
12308706524

push

github

flatcap
merge: colour refactoring

 * color: split out qstyle
 * color: move color_is_header()
 * color: factor out sidebar init
 * color: remove expando '%' hack
 * color: move notify parent
 * color: add macro COLOR_QUOTED()
 * color: make NumQuotedColors static
 * color: create a deprecated colours section
 * color: distinguish color_reset/cleanup()

31 of 210 new or added lines in 8 files covered. (14.76%)

2 existing lines in 1 file now uncovered.

8875 of 18030 relevant lines covered (49.22%)

232.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.08
/color/simple.c
1
/**
2
 * @file
3
 * Simple colour
4
 *
5
 * @authors
6
 * Copyright (C) 2021-2023 Richard Russon <rich@flatcap.org>
7
 *
8
 * @copyright
9
 * This program is free software: you can redistribute it and/or modify it under
10
 * the terms of the GNU General Public License as published by the Free Software
11
 * Foundation, either version 2 of the License, or (at your option) any later
12
 * version.
13
 *
14
 * This program is distributed in the hope that it will be useful, but WITHOUT
15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17
 * details.
18
 *
19
 * You should have received a copy of the GNU General Public License along with
20
 * this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22

23
/**
24
 * @page color_simple Simple colour
25
 *
26
 * Manage the colours of the 'simple' graphical objects -- those that can only
27
 * have one colour, plus attributes.
28
 */
29

30
#include "config.h"
31
#include <stdbool.h>
32
#include <stddef.h>
33
#include "mutt/lib.h"
34
#include "gui/lib.h"
35
#include "attr.h"
36
#include "color.h"
37
#include "command2.h"
38
#include "debug.h"
39
#include "notify2.h"
40
#include "simple2.h"
41

42
struct AttrColor SimpleColors[MT_COLOR_MAX]; ///< Array of Simple colours
43

44
/**
45
 * simple_colors_init - Initialise the simple colour definitions
46
 */
47
void simple_colors_init(void)
4✔
48
{
49
  for (int i = 0; i < MT_COLOR_MAX; i++)
212✔
50
  {
51
    SimpleColors[i].fg.color = COLOR_DEFAULT;
208✔
52
    SimpleColors[i].bg.color = COLOR_DEFAULT;
208✔
53
  }
54

55
  // Set some defaults
56
  color_debug(LL_DEBUG5, "init indicator, markers, etc\n");
57
  SimpleColors[MT_COLOR_BOLD].attrs = A_BOLD;
4✔
58
  SimpleColors[MT_COLOR_INDICATOR].attrs = A_REVERSE;
4✔
59
  SimpleColors[MT_COLOR_ITALIC].attrs = A_ITALIC;
4✔
60
  SimpleColors[MT_COLOR_MARKERS].attrs = A_REVERSE;
4✔
61
  SimpleColors[MT_COLOR_SEARCH].attrs = A_REVERSE;
4✔
62
  SimpleColors[MT_COLOR_STATUS].attrs = A_REVERSE;
4✔
63
  SimpleColors[MT_COLOR_STRIPE_EVEN].attrs = A_BOLD;
4✔
64
  SimpleColors[MT_COLOR_UNDERLINE].attrs = A_UNDERLINE;
4✔
65
}
4✔
66

67
/**
68
 * simple_colors_reset - Reset the simple colour definitions
69
 */
70
void simple_colors_reset(void)
2✔
71
{
72
  color_debug(LL_DEBUG5, "reset defs\n");
73
  for (size_t i = 0; i < MT_COLOR_MAX; i++)
106✔
74
  {
75
    attr_color_clear(&SimpleColors[i]);
104✔
76
  }
77
  simple_colors_init();
2✔
78
}
2✔
79

80
/**
81
 * simple_colors_cleanup - Cleanup the simple colour definitions
82
 */
83
void simple_colors_cleanup(void)
2✔
84
{
85
  simple_colors_reset();
2✔
86
}
2✔
87

88
/**
89
 * simple_color_get - Get the colour of an object by its ID
90
 * @param cid Colour Id, e.g. #MT_COLOR_SEARCH
91
 * @retval ptr AttrColor of the object
92
 *
93
 * @note Do not free the returned object
94
 */
95
struct AttrColor *simple_color_get(enum ColorId cid)
183✔
96
{
97
  if (cid >= MT_COLOR_MAX)
183✔
98
  {
99
    mutt_debug(LL_DEBUG1, "color overflow %d/%d", cid, MT_COLOR_MAX);
4✔
100
    return NULL;
4✔
101
  }
102
  if (cid <= MT_COLOR_NONE)
179✔
103
  {
UNCOV
104
    mutt_debug(LL_DEBUG1, "color underflow %d/%d", cid, MT_COLOR_NONE);
×
UNCOV
105
    return NULL;
×
106
  }
107

108
  return &SimpleColors[cid];
179✔
109
}
110

111
/**
112
 * simple_color_is_set - Is the object coloured?
113
 * @param cid Colour Id, e.g. #MT_COLOR_SEARCH
114
 * @retval true Yes, a 'color' command has been used on this object
115
 */
116
bool simple_color_is_set(enum ColorId cid)
1✔
117
{
118
  return attr_color_is_set(simple_color_get(cid));
1✔
119
}
120

121
/**
122
 * simple_color_set - Set the colour of a simple object
123
 * @param cid    Colour Id, e.g. #MT_COLOR_SEARCH
124
 * @param ac_val Colour value to use
125
 * @retval ptr Colour
126
 */
127
struct AttrColor *simple_color_set(enum ColorId cid, struct AttrColor *ac_val)
9✔
128
{
129
  struct AttrColor *ac = simple_color_get(cid);
9✔
130
  if (!ac)
9✔
131
    return NULL;
132

133
  attr_color_overwrite(ac, ac_val);
8✔
134

135
  struct Buffer *buf = buf_pool_get();
8✔
136
  get_colorid_name(cid, buf);
8✔
137
  color_debug(LL_DEBUG5, "NT_COLOR_SET: %s\n", buf->data);
138
  buf_pool_release(&buf);
8✔
139

140
  struct EventColor ev_c = { cid, NULL };
8✔
141
  notify_send(ColorsNotify, NT_COLOR, NT_COLOR_SET, &ev_c);
8✔
142

143
  return ac;
8✔
144
}
145

146
/**
147
 * simple_color_reset - Clear the colour of a simple object
148
 * @param cid Colour Id, e.g. #MT_COLOR_SEARCH
149
 */
150
void simple_color_reset(enum ColorId cid)
2✔
151
{
152
  struct AttrColor *ac = simple_color_get(cid);
2✔
153
  if (!ac)
2✔
154
    return;
1✔
155

156
  struct Buffer *buf = buf_pool_get();
1✔
157
  get_colorid_name(cid, buf);
1✔
158
  color_debug(LL_DEBUG5, "NT_COLOR_RESET: %s\n", buf->data);
159
  buf_pool_release(&buf);
1✔
160

161
  attr_color_clear(ac);
1✔
162

163
  struct EventColor ev_c = { cid, ac };
1✔
164
  notify_send(ColorsNotify, NT_COLOR, NT_COLOR_RESET, &ev_c);
1✔
165
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc