mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 22:03:42 -07:00
Yet another color management, settings autodetection done earlier
This commit is contained in:
parent
30c0345c31
commit
8c5be2678f
2 changed files with 26 additions and 29 deletions
|
@ -52,9 +52,7 @@ int preferences_load(void) {
|
||||||
session.overlay.y = 60 + session.plot.y + session.plot.h;
|
session.overlay.y = 60 + session.plot.y + session.plot.h;
|
||||||
session.overlay.h = 200;
|
session.overlay.h = 200;
|
||||||
session.overlay.w = session.plot.w;
|
session.overlay.w = session.plot.w;
|
||||||
session.emoji_mode = ALIAS;
|
|
||||||
session.show_hints = false;
|
session.show_hints = false;
|
||||||
session.supports_colors = false;
|
|
||||||
|
|
||||||
// setDefaultPath (spDefault, "");
|
// setDefaultPath (spDefault, "");
|
||||||
// setDefaultPath (spDump, "");
|
// setDefaultPath (spDump, "");
|
||||||
|
|
|
@ -726,6 +726,28 @@ int main(int argc, char *argv[]) {
|
||||||
set_my_executable_path();
|
set_my_executable_path();
|
||||||
set_my_user_directory();
|
set_my_user_directory();
|
||||||
|
|
||||||
|
// color management:
|
||||||
|
// 1. default = no color
|
||||||
|
// 2. enable colors if OS seems to support colors and if stdin/stdout aren't redirected
|
||||||
|
// 3. load prefs if available, overwrite colors choice if needed
|
||||||
|
// 4. disable colors anyway if stdin/stdout are redirected
|
||||||
|
//
|
||||||
|
// For info, grep --color=auto is doing sth like this, plus test getenv("TERM") != "dumb":
|
||||||
|
// struct stat tmp_stat;
|
||||||
|
// if ((fstat (STDOUT_FILENO, &tmp_stat) == 0) && (S_ISCHR (tmp_stat.st_mode)) && isatty(STDIN_FILENO))
|
||||||
|
session.stdinOnTTY = isatty(STDIN_FILENO);
|
||||||
|
session.stdoutOnTTY = isatty(STDOUT_FILENO);
|
||||||
|
session.supports_colors = false;
|
||||||
|
session.emoji_mode = ALTTEXT;
|
||||||
|
if (session.stdinOnTTY && session.stdoutOnTTY) {
|
||||||
|
#if defined(__linux__) || defined(__APPLE__)
|
||||||
|
session.supports_colors = true;
|
||||||
|
session.emoji_mode = EMOJI;
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
session.supports_colors = DetectWindowsAnsiSupport();
|
||||||
|
session.emoji_mode = ALTTEXT;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
|
|
||||||
if (argv[i][0] != '-') {
|
if (argv[i][0] != '-') {
|
||||||
|
@ -914,33 +936,10 @@ int main(int argc, char *argv[]) {
|
||||||
// settings_save ();
|
// settings_save ();
|
||||||
// End Settings
|
// End Settings
|
||||||
|
|
||||||
session.stdinOnTTY = isatty(STDIN_FILENO);
|
// even if prefs, we disable colors if stdin or stdout is not a TTY
|
||||||
session.stdoutOnTTY = isatty(STDOUT_FILENO);
|
if ((! session.stdinOnTTY) || (! session.stdoutOnTTY)) {
|
||||||
// it's okay to use color if:
|
session.supports_colors = false;
|
||||||
// * Linux or OSX
|
session.emoji_mode = ALTTEXT;
|
||||||
// * Not redirected to a file but printed to term
|
|
||||||
// For info, grep --color=auto is doing sth like this, plus test getenv("TERM") != "dumb":
|
|
||||||
// struct stat tmp_stat;
|
|
||||||
// if ((fstat (STDOUT_FILENO, &tmp_stat) == 0) && (S_ISCHR (tmp_stat.st_mode)) && isatty(STDIN_FILENO))
|
|
||||||
if (!session.preferences_loaded) {
|
|
||||||
if (session.stdinOnTTY && session.stdoutOnTTY) {
|
|
||||||
#if defined(__linux__) || defined(__APPLE__)
|
|
||||||
session.supports_colors = true;
|
|
||||||
session.emoji_mode = EMOJI;
|
|
||||||
#elif defined(_WIN32)
|
|
||||||
session.supports_colors = DetectWindowsAnsiSupport();
|
|
||||||
session.emoji_mode = ALTTEXT;
|
|
||||||
#else
|
|
||||||
session.supports_colors = false;
|
|
||||||
session.emoji_mode = ALTTEXT;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// even if prefs, we disable colors if stdin or stdout is not a TTY
|
|
||||||
if ((! session.stdinOnTTY) || (! session.stdoutOnTTY)) {
|
|
||||||
session.supports_colors = false;
|
|
||||||
session.emoji_mode = ALTTEXT;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let's take a baudrate ok for real UART, USB-CDC & BT don't use that info anyway
|
// Let's take a baudrate ok for real UART, USB-CDC & BT don't use that info anyway
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue