Rename "can_display_colour" and "can_display_utf8" to "terminal_supports_colour" and "terminal_supports_utf8" to make it clearer that these are not operator-supplied option settings, they are derived from terminal capabilities (colour) and the environment (UTF-8).
This commit is contained in:
@@ -197,8 +197,8 @@ struct pvstate_s {
|
||||
bool no_splice; /* never use splice() */
|
||||
bool discard_input; /* write nothing to stdout */
|
||||
bool show_stats; /* show statistics on exit */
|
||||
bool can_display_utf8; /* whether UTF-8 output is permitted */
|
||||
bool can_display_colour; /* whether the terminal supports colour */
|
||||
bool terminal_supports_utf8; /* whether the terminal supports UTF-8 */
|
||||
bool terminal_supports_colour; /* whether the terminal supports colour */
|
||||
bool checked_colour_support; /* whether we have checked colour support yet */
|
||||
bool width_set_manually; /* width was set manually, not detected */
|
||||
bool height_set_manually; /* height was set manually, not detected */
|
||||
|
||||
+1
-1
@@ -237,7 +237,7 @@ extern void pv_state_watch_pid_set(pvstate_t, pid_t);
|
||||
extern void pv_state_watch_fd_set(pvstate_t, int);
|
||||
extern void pv_state_output_set(pvstate_t, int, const char *);
|
||||
extern void pv_state_average_rate_window_set(pvstate_t, unsigned int);
|
||||
extern void pv_state_set_can_display_utf8(pvstate_t, bool);
|
||||
extern void pv_state_set_terminal_supports_utf8(pvstate_t, bool);
|
||||
|
||||
extern void pv_state_inputfiles(pvstate_t, unsigned int, const char **);
|
||||
|
||||
|
||||
+4
-4
@@ -281,7 +281,7 @@ int main(int argc, char **argv)
|
||||
/*@only@ */ pvstate_t state = NULL;
|
||||
int retcode = 0;
|
||||
bool can_have_eta = true;
|
||||
bool can_display_utf8 = false;
|
||||
bool terminal_supports_utf8 = false;
|
||||
|
||||
#if ! HAVE_SETPROCTITLE
|
||||
initproctitle(argc, argv);
|
||||
@@ -295,7 +295,7 @@ int main(int argc, char **argv)
|
||||
#ifdef HAVE_LANGINFO_H
|
||||
/*@-mustfreefresh@ *//* splint thinks nl_langinfo() leaks memory */
|
||||
if (0 == strcmp(nl_langinfo(CODESET), "UTF-8"))
|
||||
can_display_utf8 = true;
|
||||
terminal_supports_utf8 = true;
|
||||
/*@+mustfreefresh@ */
|
||||
#endif
|
||||
#endif
|
||||
@@ -519,8 +519,8 @@ int main(int argc, char **argv)
|
||||
can_have_eta ? opts->fineta : false, opts->rate, opts->average_rate,
|
||||
opts->bytes, opts->bufpercent, opts->lastwritten, opts->name);
|
||||
|
||||
debug("%s: %s", "can_display_utf8", can_display_utf8 ? "true" : "false");
|
||||
pv_state_set_can_display_utf8(state, can_display_utf8);
|
||||
debug("%s: %s", "terminal_supports_utf8", terminal_supports_utf8 ? "true" : "false");
|
||||
pv_state_set_terminal_supports_utf8(state, terminal_supports_utf8);
|
||||
|
||||
/* Initialise the signal handling. */
|
||||
pv_sig_init(state);
|
||||
|
||||
+12
-12
@@ -591,7 +591,7 @@ char *pv_format_sequences(void)
|
||||
* Initialise the output format structure, based on the current options.
|
||||
*
|
||||
* May update control->checked_colour_support and
|
||||
* control->can_display_colour.
|
||||
* control->terminal_supports_colour.
|
||||
*/
|
||||
static void pv__format_init(pvcontrol_t control, readonly_pvtransferstate_t transfer, readonly_pvtransfercalc_t calc,
|
||||
/*@null@ */ const char *format_supplied, pvdisplay_t display)
|
||||
@@ -856,7 +856,7 @@ static void pv__format_init(pvcontrol_t control, readonly_pvtransferstate_t tran
|
||||
* supported if we're forcing output.
|
||||
*/
|
||||
if (true == control->force) {
|
||||
control->can_display_colour = true;
|
||||
control->terminal_supports_colour = true;
|
||||
debug("%s", "force mode - assuming terminal supports colour");
|
||||
} else {
|
||||
char *term_env = NULL;
|
||||
@@ -866,22 +866,22 @@ static void pv__format_init(pvcontrol_t control, readonly_pvtransferstate_t tran
|
||||
* flawfinder - here we pass responsibility to the
|
||||
* ncurses library to behave OK with $TERM.
|
||||
*/
|
||||
control->can_display_colour = false;
|
||||
control->terminal_supports_colour = false;
|
||||
if (NULL != term_env) {
|
||||
int setup_err = 0;
|
||||
|
||||
if ((0 == setupterm(term_env, STDERR_FILENO, &setup_err))
|
||||
&& (tigetnum("colors") > 1)
|
||||
) {
|
||||
control->can_display_colour = true;
|
||||
control->terminal_supports_colour = true;
|
||||
debug("%s: %s", term_env, "terminal supports colour");
|
||||
} else {
|
||||
control->can_display_colour = false;
|
||||
control->terminal_supports_colour = false;
|
||||
debug("%s: %s", term_env, "terminal does not support colour");
|
||||
}
|
||||
} else {
|
||||
/* If TERM is unset, disable colour. */
|
||||
control->can_display_colour = false;
|
||||
control->terminal_supports_colour = false;
|
||||
debug("%s", "no TERM variable - disabling colour support");
|
||||
}
|
||||
}
|
||||
@@ -893,7 +893,7 @@ static void pv__format_init(pvcontrol_t control, readonly_pvtransferstate_t tran
|
||||
* was supplied, in which case colour support is assumed.
|
||||
*/
|
||||
if (true == control->force) {
|
||||
control->can_display_colour = true;
|
||||
control->terminal_supports_colour = true;
|
||||
debug("%s", "force mode - assuming terminal supports colour");
|
||||
} else {
|
||||
FILE *command_fptr;
|
||||
@@ -909,21 +909,21 @@ static void pv__format_init(pvcontrol_t control, readonly_pvtransferstate_t tran
|
||||
*/
|
||||
|
||||
if (NULL == command_fptr) {
|
||||
control->can_display_colour = false;
|
||||
control->terminal_supports_colour = false;
|
||||
debug("%s (%s)", "popen failed - disabling colour support", strerror(errno));
|
||||
} else {
|
||||
int colour_count;
|
||||
if (1 == fscanf(command_fptr, "%d", &colour_count)) {
|
||||
if (colour_count > 1) {
|
||||
control->can_display_colour = true;
|
||||
control->terminal_supports_colour = true;
|
||||
debug("%s (%d)", "terminal supports colour", colour_count);
|
||||
} else {
|
||||
control->can_display_colour = false;
|
||||
control->terminal_supports_colour = false;
|
||||
debug("%s (%d)",
|
||||
"fewer than 2 colours available - disabling colour support");
|
||||
}
|
||||
} else {
|
||||
control->can_display_colour = false;
|
||||
control->terminal_supports_colour = false;
|
||||
debug("%s", "tput did not produce a number - disabling colour support");
|
||||
}
|
||||
/*@-unrecog@ *//* splint doesn't know pclose(). */
|
||||
@@ -936,7 +936,7 @@ static void pv__format_init(pvcontrol_t control, readonly_pvtransferstate_t tran
|
||||
* Without terminal info support, just assume colour is
|
||||
* available.
|
||||
*/
|
||||
control->can_display_colour = true;
|
||||
control->terminal_supports_colour = true;
|
||||
debug("%s", "terminal info support not compiled in - assuming colour support");
|
||||
#endif /* (! ENABLE_NCURSES) && (! USE_POPEN_TPUTS) */
|
||||
#endif /* ! ENABLE_NCURSES */
|
||||
|
||||
@@ -44,7 +44,7 @@ static bool pv_barstyle(pvformatter_args_t args, pvbarstyle_t style, const char
|
||||
|
||||
memset(style, 0, sizeof(*style));
|
||||
|
||||
if (args->control->can_display_utf8 && 0 == strcmp(name, "block")) {
|
||||
if (args->control->terminal_supports_utf8 && 0 == strcmp(name, "block")) {
|
||||
|
||||
style->style_id = 2;
|
||||
|
||||
@@ -58,7 +58,7 @@ static bool pv_barstyle(pvformatter_args_t args, pvbarstyle_t style, const char
|
||||
|
||||
return true;
|
||||
|
||||
} else if (args->control->can_display_utf8 && 0 == strcmp(name, "granular")) {
|
||||
} else if (args->control->terminal_supports_utf8 && 0 == strcmp(name, "granular")) {
|
||||
|
||||
style->style_id = 3;
|
||||
|
||||
@@ -79,7 +79,7 @@ static bool pv_barstyle(pvformatter_args_t args, pvbarstyle_t style, const char
|
||||
|
||||
return true;
|
||||
|
||||
} else if (args->control->can_display_utf8 && 0 == strcmp(name, "shaded")) {
|
||||
} else if (args->control->terminal_supports_utf8 && 0 == strcmp(name, "shaded")) {
|
||||
|
||||
style->style_id = 4;
|
||||
|
||||
|
||||
+1
-1
@@ -109,7 +109,7 @@ pvdisplay_bytecount_t pv_formatter_sgr(pvformatter_args_t args)
|
||||
|
||||
args->display->format_uses_colour = true;
|
||||
|
||||
if (!args->control->can_display_colour)
|
||||
if (!args->control->terminal_supports_colour)
|
||||
return 0;
|
||||
if (NULL == args->segment->string_parameter)
|
||||
return 0;
|
||||
|
||||
+2
-2
@@ -568,9 +568,9 @@ void pv_state_average_rate_window_set(pvstate_t state, unsigned int val)
|
||||
pv_alloc_history(state);
|
||||
}
|
||||
|
||||
void pv_state_set_can_display_utf8(pvstate_t state, bool val)
|
||||
void pv_state_set_terminal_supports_utf8(pvstate_t state, bool val)
|
||||
{
|
||||
state->control.can_display_utf8 = val;
|
||||
state->control.terminal_supports_utf8 = val;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user