If @var{is_foreground} is @code{#t}, then the returned sequence will change
foreground color. Otherwise, the returned sequence will change background
color.
+
+If styling is currently disabled (@pxref{Output Styling,,@kbd{set style
+enabled}}), then this procedure will return an empty string.
@end deffn
When color is initialized, its color space must be specified. The
If @var{is_foreground} is @code{True}, then the returned sequence will change
foreground color. Otherwise, the returned sequence will change background
color.
+
+If styling is currently disabled (@pxref{Output Styling,,@kbd{set style
+enabled}}), then this method will return an empty string.
@end defun
When color is initialized, its color space must be specified. The
#include "language.h"
#include "arch-utils.h"
#include "guile-internal.h"
+#include "cli/cli-style.h"
/* A GDB color. */
const ui_file_style::color &color = coscm_get_color (self);
SCM_ASSERT_TYPE (gdbscm_is_bool (is_fg_scm), is_fg_scm, SCM_ARG2, FUNC_NAME,
_("boolean"));
- bool is_fg = gdbscm_is_true (is_fg_scm);
- std::string s = color.to_ansi (is_fg);
+
+ std::string s;
+ if (term_cli_styling ())
+ {
+ bool is_fg = gdbscm_is_true (is_fg_scm);
+ s = color.to_ansi (is_fg);
+ }
+
return gdbscm_scm_from_host_string (s.c_str (), s.size ());
}
#include "python-internal.h"
#include "py-color.h"
#include "cli/cli-decode.h"
+#include "cli/cli-style.h"
/* Colorspace constants and their values. */
static struct {
/* The argument parsing ensures we have a bool. */
gdb_assert (PyBool_Check (is_fg_obj));
- bool is_fg = is_fg_obj == Py_True;
- std::string s = gdbpy_get_color (self).to_ansi (is_fg);
+ std::string s;
+ if (term_cli_styling ())
+ {
+ bool is_fg = is_fg_obj == Py_True;
+ s = gdbpy_get_color (self).to_ansi (is_fg);
+ }
return host_string_to_python_string (s.c_str ()).release ();
}
require allow_guile_tests
-clean_restart
+# Start GDB with styling support.
+with_ansi_styling_terminal {
+ clean_restart
+}
gdb_install_guile_utils
gdb_install_guile_module
"\033\\\[31m\033\\\[42mred on green\033\\\[49m red on default\033\\\[39m" \
"escape sequences"
+# Ensure that turning styling off means no escape sequences.
+gdb_test_no_output "set style enabled off"
+gdb_test_no_output "guile (display (color-escape-sequence c_red #t))"
+gdb_test_no_output "guile (display (color-escape-sequence c_red #f))"
+gdb_test_no_output "set style enabled on"
require allow_python_tests
-# Start with a fresh gdb.
-clean_restart
+# Start with a fresh GDB, but enable color support.
+with_ansi_styling_terminal {
+ clean_restart
+}
gdb_test_no_output "python get_color_attrs = lambda c: \"%s %s %s %s %s\" % (str(c), c.colorspace, c.is_none, c.is_indexed, c.is_direct)" \
"get_color_attrs helper"
"\033\\\[31m\033\\\[42mred on green\033\\\[49m red on default\033\\\[39m" \
"escape sequences using keyword arguments"
+# Ensure that turning styling off means no escape sequences.
+gdb_test_no_output "set style enabled off"
+gdb_test_no_output "python print (c_red.escape_sequence (True), end='')"
+gdb_test_no_output "python print (c_red.escape_sequence (False), end='')"
+gdb_test_no_output "set style enabled on"
+
gdb_test_multiline "Try to sub-class gdb.Color" \
"python" "" \
"class my_color(gdb.Color):" "" \