diff --git a/README.md b/README.md index 963671e..28ac84c 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ maretf info input.vtf ## Full CLI Help Text ``` -Usage: maretf [--help] [--output PATH] [--yes] [--no] [--quiet] [--no-recurse] +Usage: maretf [--help] [--output PATH] [--yes] [--no] [--quiet] [--verbose] [--no-recurse] [--no-pretty-formatting] [--watch] [--version X.Y] [--format IMAGE_FORMAT] [--quality COMPRESSION_QUALITY] [--filter RESIZE_FILTER] [--flag FLAG]... [--no-automatic-transparency-flags] [--no-mips] [--no-animation] @@ -146,15 +146,22 @@ Optional arguments: -o, --output PATH The path to the output file (if the current mode outputs a file). Ignored if the input path is a directory. - -y, --yes Automatically say yes to any prompts. + -y, --yes Automatically say yes to any prompts. Enabled + by default if no TTY is detected. --no Automatically say no to any prompts. Overrides --yes. --quiet Don't print anything to stdout or stderr (assuming program arguments are parsed - successfully). + successfully). Enabled by default if no TTY is + detected. + --verbose Allow printing to stdout or stderr, even when + no TTY is detected (assuming program arguments + are parsed successfully). --no-recurse If the input path is a directory, do not enter subdirectories when scanning for files. --no-pretty-formatting Disables printing ANSI color codes and emojis. + Pretty formatting is disabled by default if no + TTY is detected. "create" mode (detailed usage): --watch After creation is complete, watch the input diff --git a/res/logo.ico b/res/logo.ico index af53c58..148dafe 100644 Binary files a/res/logo.ico and b/res/logo.ico differ diff --git a/src/cli/MareTF.cpp b/src/cli/MareTF.cpp index 0112a0d..41e8d1c 100644 --- a/src/cli/MareTF.cpp +++ b/src/cli/MareTF.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -20,9 +21,12 @@ #include #include -#ifdef _WIN32 +#if defined(_WIN32) +#include #define WIN32_LEAN_AND_MEAN #include +#elif defined(__linux__) +#include #endif #include @@ -41,6 +45,17 @@ using namespace std::literals; namespace { +[[nodiscard]] bool runningInTTY() { +#if defined(_WIN32) + static const bool check = _isatty(_fileno(stdout)) && _isatty(_fileno(stderr)); +#elif defined(__linux__) + static const bool check = isatty(STDOUT_FILENO) && isatty(STDERR_FILENO); +#else + static constexpr bool check = true; +#endif + return check; +} + [[nodiscard]] std::string_view randomDeviantArtTFTrope() { static constexpr std::array DEVIANTART_TF_TROPES{ "Splicing DNA", @@ -226,7 +241,7 @@ int main(int argc, const char* const argv[]) { bool overwrite; cli .add_argument("-y", "--yes") - .help("Automatically say yes to any prompts.") + .help("Automatically say yes to any prompts. Enabled by default if no TTY is detected.") .flag() .store_into(overwrite); @@ -240,10 +255,19 @@ int main(int argc, const char* const argv[]) { bool quiet; cli .add_argument("--quiet") - .help("Don't print anything to stdout or stderr (assuming program arguments are parsed successfully).") + .help("Don't print anything to stdout or stderr (assuming program arguments are parsed successfully)." + " Enabled by default if no TTY is detected.") .flag() .store_into(quiet); + bool verbose; + cli + .add_argument("--verbose") + .help("Allow printing to stdout or stderr, even when no TTY is detected (assuming program arguments" + " are parsed successfully).") + .flag() + .store_into(verbose); + bool noRecurse; cli .add_argument("--no-recurse") @@ -254,7 +278,8 @@ int main(int argc, const char* const argv[]) { bool noPrettyFormatting; cli .add_argument("--no-pretty-formatting") - .help("Disables printing ANSI color codes and emojis.") + .help("Disables printing ANSI color codes and emojis. Pretty formatting is disabled by default" + " if no TTY is detected.") .flag() .store_into(noPrettyFormatting); @@ -994,9 +1019,17 @@ int main(int argc, const char* const argv[]) { try { cli.parse_args(argc, argv); - if (quiet) { + if (!::runningInTTY()) { + overwrite = true; + quiet = true; + noPrettyFormatting = true; + } + + if (quiet && !verbose) { tfout_t::QUIET = true; tferr_t::QUIET = true; + } else { + quiet = false; } // Pretty formatting colors