Fix tparm kludge

This just defines a constant to whichever tparm implementation we're
using (either the actual, working one the system provides, or our
kludge to paper over Solaris' inadequacies).

This means that there won't be so much ping-ponging of what "tparm"
stands for. "tparm" is the system's function. Only we don't use it,
just like we don't use wcstod directly.

Fixes #8780
This commit is contained in:
Fabian Homborg 2022-03-14 15:36:17 +01:00
parent cd62771d12
commit a76ed9942d
5 changed files with 23 additions and 27 deletions

View file

@ -38,7 +38,7 @@ static void print_modifiers(outputter_t &outp, bool bold, bool underline, bool i
bool reverse, rgb_color_t bg) {
if (bold && enter_bold_mode) {
// These casts are needed to work with different curses implementations.
writembs_nofail(outp, tparm(const_cast<char *>(enter_bold_mode)));
writembs_nofail(outp, fish_tparm(const_cast<char *>(enter_bold_mode)));
}
if (underline && enter_underline_mode) {
@ -59,7 +59,7 @@ static void print_modifiers(outputter_t &outp, bool bold, bool underline, bool i
writembs_nofail(outp, enter_standout_mode);
}
if (!bg.is_none() && bg.is_normal()) {
writembs_nofail(outp, tparm(const_cast<char *>(exit_attribute_mode)));
writembs_nofail(outp, fish_tparm(const_cast<char *>(exit_attribute_mode)));
}
}
@ -79,7 +79,7 @@ static void print_colors(io_streams_t &streams, bool bold, bool underline, bool
if (!bg.is_none()) {
// If we have a background, stop it after the color
// or it goes to the end of the line and looks ugly.
writembs_nofail(outp, tparm(const_cast<char *>(exit_attribute_mode)));
writembs_nofail(outp, fish_tparm(const_cast<char *>(exit_attribute_mode)));
}
outp.writech(L'\n');
} // conveniently, 'normal' is always the last color so we don't need to reset here
@ -233,12 +233,12 @@ maybe_t<int> builtin_set_color(parser_t &parser, io_streams_t &streams, const wc
print_modifiers(outp, bold, underline, italics, dim, reverse, bg);
if (bgcolor != nullptr && bg.is_normal()) {
writembs_nofail(outp, tparm(const_cast<char *>(exit_attribute_mode)));
writembs_nofail(outp, fish_tparm(const_cast<char *>(exit_attribute_mode)));
}
if (!fg.is_none()) {
if (fg.is_normal() || fg.is_reset()) {
writembs_nofail(outp, tparm(const_cast<char *>(exit_attribute_mode)));
writembs_nofail(outp, fish_tparm(const_cast<char *>(exit_attribute_mode)));
} else {
if (!outp.write_color(fg, true /* is_fg */)) {
// We need to do *something* or the lack of any output messes up

View file

@ -44,16 +44,10 @@
#include "fallback.h" // IWYU pragma: keep
#if defined(TPARM_SOLARIS_KLUDGE)
#undef tparm
char *tparm_solaris_kludge(char *str, long p1, long p2, long p3, long p4, long p5, long p6, long p7,
long p8, long p9) {
return tparm(str, p1, p2, p3, p4, p5, p6, p7, p8, p9);
}
// Re-defining just to make sure nothing breaks further down in this file.
#define tparm tparm_solaris_kludge
#endif
int fish_mkstemp_cloexec(char *name_template) {

View file

@ -68,9 +68,11 @@ struct winsize {
#if defined(TPARM_SOLARIS_KLUDGE)
/// Solaris tparm has a set fixed of parameters in its curses implementation, work around this here.
#define tparm tparm_solaris_kludge
#define fish_tparm tparm_solaris_kludge
char *tparm_solaris_kludge(char *str, long p1 = 0, long p2 = 0, long p3 = 0, long p4 = 0,
long p5 = 0, long p6 = 0, long p7 = 0, long p8 = 0, long p9 = 0);
#else
#define fish_tparm tparm
#endif
/// These functions are missing from Solaris 10, and only accessible from

View file

@ -36,7 +36,7 @@
/// Whether term256 and term24bit are supported.
static color_support_t color_support = 0;
/// Returns true if we think tparm can handle outputting a color index
/// Returns true if we think fish_tparm can handle outputting a color index
static bool term_supports_color_natively(unsigned int c) {
return static_cast<unsigned>(max_colors) >= c + 1;
}
@ -54,8 +54,8 @@ unsigned char index_for_color(rgb_color_t c) {
static bool write_color_escape(outputter_t &outp, const char *todo, unsigned char idx, bool is_fg) {
if (term_supports_color_natively(idx)) {
// Use tparm to emit color escape.
writembs(outp, tparm(const_cast<char *>(todo), idx));
// Use fish_tparm to emit color escape.
writembs(outp, fish_tparm(const_cast<char *>(todo), idx));
return true;
}
@ -116,7 +116,7 @@ bool outputter_t::write_color(rgb_color_t color, bool is_fg) {
return (is_fg ? write_foreground_color : write_background_color)(*this, idx);
}
// 24 bit! No tparm here, just ANSI escape sequences.
// 24 bit! No fish_tparm here, just ANSI escape sequences.
// Foreground: ^[38;2;<r>;<g>;<b>m
// Background: ^[48;2;<r>;<g>;<b>m
color24_t rgb = color.to_color24();
@ -242,7 +242,7 @@ void outputter_t::set_color(rgb_color_t fg, rgb_color_t bg) {
// Lastly, we set bold, underline, italics, dim, and reverse modes correctly.
if (is_bold && !was_bold && enter_bold_mode && enter_bold_mode[0] != '\0' && !bg_set) {
// The unconst cast is for NetBSD's benefit. DO NOT REMOVE!
writembs_nofail(*this, tparm(const_cast<char *>(enter_bold_mode)));
writembs_nofail(*this, fish_tparm(const_cast<char *>(enter_bold_mode)));
was_bold = is_bold;
}
@ -304,7 +304,7 @@ int outputter_t::term_puts(const char *str, int affcnt) {
scoped_push<outputter_t *> push(&s_tputs_receiver, this);
s_tputs_receiver->begin_buffering();
// On some systems, tputs takes a char*, on others a const char*.
// Like tparm, we just cast it to unconst, that should work everywhere.
// Like fish_tparm, we just cast it to unconst, that should work everywhere.
int res = tputs(const_cast<char *>(str), affcnt, tputs_writer);
s_tputs_receiver->end_buffering();
return res;

View file

@ -228,10 +228,10 @@ static bool is_visual_escape_seq(const wchar_t *code, size_t *resulting_length)
for (auto p : esc2) {
if (!p) continue;
// Test both padded and unpadded version, just to be safe. Most versions of tparm don't
// Test both padded and unpadded version, just to be safe. Most versions of fish_tparm don't
// actually seem to do anything these days.
size_t esc_seq_len =
std::max(try_sequence(tparm(const_cast<char *>(p)), code), try_sequence(p, code));
std::max(try_sequence(fish_tparm(const_cast<char *>(p)), code), try_sequence(p, code));
if (esc_seq_len) {
*resulting_length = esc_seq_len;
return true;
@ -599,7 +599,7 @@ void screen_t::move(int new_x, int new_y) {
bool use_multi = multi_str != nullptr && multi_str[0] != '\0' &&
abs(x_steps) * std::strlen(str) > std::strlen(multi_str);
if (use_multi && cur_term) {
char *multi_param = tparm(const_cast<char *>(multi_str), abs(x_steps));
char *multi_param = fish_tparm(const_cast<char *>(multi_str), abs(x_steps));
writembs(outp, multi_param);
} else {
for (i = 0; i < abs(x_steps); i++) {
@ -1255,7 +1255,7 @@ void screen_t::reset_abandoning_line(int screen_width) {
if (screen_width > non_space_width) {
bool justgrey = true;
if (cur_term && enter_dim_mode) {
std::string dim = tparm(const_cast<char *>(enter_dim_mode));
std::string dim = fish_tparm(const_cast<char *>(enter_dim_mode));
if (!dim.empty()) {
// Use dim if they have it, so the color will be based on their actual normal
// color and the background of the termianl.
@ -1267,24 +1267,24 @@ void screen_t::reset_abandoning_line(int screen_width) {
if (max_colors >= 238) {
// draw the string in a particular grey
abandon_line_string.append(
str2wcstring(tparm(const_cast<char *>(set_a_foreground), 237)));
str2wcstring(fish_tparm(const_cast<char *>(set_a_foreground), 237)));
} else if (max_colors >= 9) {
// bright black (the ninth color, looks grey)
abandon_line_string.append(
str2wcstring(tparm(const_cast<char *>(set_a_foreground), 8)));
str2wcstring(fish_tparm(const_cast<char *>(set_a_foreground), 8)));
} else if (max_colors >= 2 && enter_bold_mode) {
// we might still get that color by setting black and going bold for bright
abandon_line_string.append(
str2wcstring(tparm(const_cast<char *>(enter_bold_mode))));
str2wcstring(fish_tparm(const_cast<char *>(enter_bold_mode))));
abandon_line_string.append(
str2wcstring(tparm(const_cast<char *>(set_a_foreground), 0)));
str2wcstring(fish_tparm(const_cast<char *>(set_a_foreground), 0)));
}
}
abandon_line_string.append(get_omitted_newline_str());
if (cur_term && exit_attribute_mode) {
abandon_line_string.append(str2wcstring(tparm(
abandon_line_string.append(str2wcstring(fish_tparm(
const_cast<char *>(exit_attribute_mode)))); // normal text ANSI escape sequence
}