mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-10-18 11:10:05 +00:00
spirv-dis: Add --color option to force color disassembly
Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/1170
This commit is contained in:
parent
5e70d20d80
commit
3604c0b71d
@ -43,7 +43,9 @@ Options:
|
|||||||
Output goes to standard output if this option is
|
Output goes to standard output if this option is
|
||||||
not specified, or if the filename is "-".
|
not specified, or if the filename is "-".
|
||||||
|
|
||||||
--no-color Don't print in color.
|
--color Force color output. The default when printing to a terminal.
|
||||||
|
Overrides a previous --no-color option.
|
||||||
|
--no-color Don't print in color. Overrides a previous --color option.
|
||||||
The default when output goes to something other than a
|
The default when output goes to something other than a
|
||||||
terminal (e.g. a file, a pipe, or a shell redirection).
|
terminal (e.g. a file, a pipe, or a shell redirection).
|
||||||
|
|
||||||
@ -64,10 +66,15 @@ int main(int argc, char** argv) {
|
|||||||
const char* inFile = nullptr;
|
const char* inFile = nullptr;
|
||||||
const char* outFile = nullptr;
|
const char* outFile = nullptr;
|
||||||
|
|
||||||
bool allow_color = false;
|
bool color_is_possible =
|
||||||
#ifdef SPIRV_COLOR_TERMINAL
|
#if SPIRV_COLOR_TERMINAL
|
||||||
allow_color = true;
|
true;
|
||||||
|
#else
|
||||||
|
false;
|
||||||
#endif
|
#endif
|
||||||
|
bool force_color = false;
|
||||||
|
bool force_no_color = false;
|
||||||
|
|
||||||
bool allow_indent = true;
|
bool allow_indent = true;
|
||||||
bool show_byte_offsets = false;
|
bool show_byte_offsets = false;
|
||||||
bool no_header = false;
|
bool no_header = false;
|
||||||
@ -90,7 +97,11 @@ int main(int argc, char** argv) {
|
|||||||
case '-': {
|
case '-': {
|
||||||
// Long options
|
// Long options
|
||||||
if (0 == strcmp(argv[argi], "--no-color")) {
|
if (0 == strcmp(argv[argi], "--no-color")) {
|
||||||
allow_color = false;
|
force_no_color = true;
|
||||||
|
force_color = false;
|
||||||
|
} else if (0 == strcmp(argv[argi], "--color")) {
|
||||||
|
force_no_color = false;
|
||||||
|
force_color = true;
|
||||||
} else if (0 == strcmp(argv[argi], "--no-indent")) {
|
} else if (0 == strcmp(argv[argi], "--no-indent")) {
|
||||||
allow_indent = false;
|
allow_indent = false;
|
||||||
} else if (0 == strcmp(argv[argi], "--offsets")) {
|
} else if (0 == strcmp(argv[argi], "--offsets")) {
|
||||||
@ -148,12 +159,15 @@ int main(int argc, char** argv) {
|
|||||||
if (!outFile || (0 == strcmp("-", outFile))) {
|
if (!outFile || (0 == strcmp("-", outFile))) {
|
||||||
// Print to standard output.
|
// Print to standard output.
|
||||||
options |= SPV_BINARY_TO_TEXT_OPTION_PRINT;
|
options |= SPV_BINARY_TO_TEXT_OPTION_PRINT;
|
||||||
bool output_is_tty = true;
|
|
||||||
|
if (color_is_possible && !force_no_color) {
|
||||||
|
bool output_is_tty = true;
|
||||||
#if defined(_POSIX_VERSION)
|
#if defined(_POSIX_VERSION)
|
||||||
output_is_tty = isatty(fileno(stdout));
|
output_is_tty = isatty(fileno(stdout));
|
||||||
#endif
|
#endif
|
||||||
if (allow_color && output_is_tty) {
|
if (output_is_tty || force_color) {
|
||||||
options |= SPV_BINARY_TO_TEXT_OPTION_COLOR;
|
options |= SPV_BINARY_TO_TEXT_OPTION_COLOR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user