mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-27 14:45:13 +08:00
Use bools in set_color()
This usage of ints is pretty common in pre-C++ fish code, which did not use (c99) bool often.
This commit is contained in:
parent
632a209685
commit
41bf002049
@ -155,19 +155,18 @@ void set_color(rgb_color_t c, rgb_color_t c2) {
|
|||||||
#if 0
|
#if 0
|
||||||
wcstring tmp = c.description();
|
wcstring tmp = c.description();
|
||||||
wcstring tmp2 = c2.description();
|
wcstring tmp2 = c2.description();
|
||||||
printf("set_color %ls : %ls\n", tmp.c_str(), tmp2.c_str());
|
debug(3, "set_color %ls : %ls\n", tmp.c_str(), tmp2.c_str());
|
||||||
#endif
|
#endif
|
||||||
ASSERT_IS_MAIN_THREAD();
|
ASSERT_IS_MAIN_THREAD();
|
||||||
|
|
||||||
const rgb_color_t normal = rgb_color_t::normal();
|
const rgb_color_t normal = rgb_color_t::normal();
|
||||||
static rgb_color_t last_color = rgb_color_t::normal();
|
static rgb_color_t last_color = rgb_color_t::normal();
|
||||||
static rgb_color_t last_color2 = rgb_color_t::normal();
|
static rgb_color_t last_color2 = rgb_color_t::normal();
|
||||||
static int was_bold = 0;
|
static bool was_bold = false;
|
||||||
static int was_underline = 0;
|
static bool was_underline = false;
|
||||||
int bg_set = 0, last_bg_set = 0;
|
bool bg_set = false, last_bg_set = false;
|
||||||
|
bool is_bold = false;
|
||||||
int is_bold = 0;
|
bool is_underline = false;
|
||||||
int is_underline = 0;
|
|
||||||
|
|
||||||
// Test if we have at least basic support for setting fonts, colors and related bits - otherwise
|
// Test if we have at least basic support for setting fonts, colors and related bits - otherwise
|
||||||
// just give up...
|
// just give up...
|
||||||
@ -183,8 +182,8 @@ void set_color(rgb_color_t c, rgb_color_t c2) {
|
|||||||
|
|
||||||
if (c.is_reset() || c2.is_reset()) {
|
if (c.is_reset() || c2.is_reset()) {
|
||||||
c = c2 = normal;
|
c = c2 = normal;
|
||||||
was_bold = 0;
|
was_bold = false;
|
||||||
was_underline = 0;
|
was_underline = false;
|
||||||
// If we exit attibute mode, we must first set a color, or previously coloured text might
|
// If we exit attibute mode, we must first set a color, or previously coloured text might
|
||||||
// lose it's color. Terminals are weird...
|
// lose it's color. Terminals are weird...
|
||||||
write_foreground_color(0);
|
write_foreground_color(0);
|
||||||
@ -197,18 +196,18 @@ void set_color(rgb_color_t c, rgb_color_t c2) {
|
|||||||
writembs(exit_attribute_mode);
|
writembs(exit_attribute_mode);
|
||||||
last_color = normal;
|
last_color = normal;
|
||||||
last_color2 = normal;
|
last_color2 = normal;
|
||||||
was_bold = 0;
|
was_bold = false;
|
||||||
was_underline = 0;
|
was_underline = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!last_color2.is_normal() && !last_color2.is_reset()) {
|
if (!last_color2.is_normal() && !last_color2.is_reset()) {
|
||||||
// Background was set.
|
// Background was set.
|
||||||
last_bg_set = 1;
|
last_bg_set = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!c2.is_normal()) {
|
if (!c2.is_normal()) {
|
||||||
// Background is set.
|
// Background is set.
|
||||||
bg_set = 1;
|
bg_set = true;
|
||||||
if (c == c2) c = (c2 == rgb_color_t::white()) ? rgb_color_t::black() : rgb_color_t::white();
|
if (c == c2) c = (c2 == rgb_color_t::white()) ? rgb_color_t::black() : rgb_color_t::white();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,8 +220,8 @@ void set_color(rgb_color_t c, rgb_color_t c2) {
|
|||||||
if (!bg_set && last_bg_set) {
|
if (!bg_set && last_bg_set) {
|
||||||
// Background color changed and is no longer set, so we exit bold mode.
|
// Background color changed and is no longer set, so we exit bold mode.
|
||||||
writembs(exit_attribute_mode);
|
writembs(exit_attribute_mode);
|
||||||
was_bold = 0;
|
was_bold = false;
|
||||||
was_underline = 0;
|
was_underline = false;
|
||||||
// We don't know if exit_attribute_mode resets colors, so we set it to something known.
|
// We don't know if exit_attribute_mode resets colors, so we set it to something known.
|
||||||
if (write_foreground_color(0)) {
|
if (write_foreground_color(0)) {
|
||||||
last_color = rgb_color_t::black();
|
last_color = rgb_color_t::black();
|
||||||
@ -236,8 +235,8 @@ void set_color(rgb_color_t c, rgb_color_t c2) {
|
|||||||
writembs(exit_attribute_mode);
|
writembs(exit_attribute_mode);
|
||||||
|
|
||||||
last_color2 = rgb_color_t::normal();
|
last_color2 = rgb_color_t::normal();
|
||||||
was_bold = 0;
|
was_bold = false;
|
||||||
was_underline = 0;
|
was_underline = false;
|
||||||
} else if (!c.is_special()) {
|
} else if (!c.is_special()) {
|
||||||
write_color(c, true /* foreground */);
|
write_color(c, true /* foreground */);
|
||||||
}
|
}
|
||||||
@ -254,8 +253,8 @@ void set_color(rgb_color_t c, rgb_color_t c2) {
|
|||||||
write_color(last_color, true /* foreground */);
|
write_color(last_color, true /* foreground */);
|
||||||
}
|
}
|
||||||
|
|
||||||
was_bold = 0;
|
was_bold = false;
|
||||||
was_underline = 0;
|
was_underline = false;
|
||||||
last_color2 = c2;
|
last_color2 = c2;
|
||||||
} else if (!c2.is_special()) {
|
} else if (!c2.is_special()) {
|
||||||
write_color(c2, false /* not foreground */);
|
write_color(c2, false /* not foreground */);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user