Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
Binary file modified res/logo.ico
Binary file not shown.
43 changes: 38 additions & 5 deletions src/cli/MareTF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <algorithm>
#include <chrono>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <filesystem>
#include <format>
Expand All @@ -20,9 +21,12 @@
#include <unordered_map>
#include <utility>

#ifdef _WIN32
#if defined(_WIN32)
#include <io.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#elif defined(__linux__)
#include <unistd.h>
#endif

#include <argparse/argparse.hpp>
Expand All @@ -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<std::string_view, 23> DEVIANTART_TF_TROPES{
"Splicing DNA",
Expand Down Expand Up @@ -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);

Expand All @@ -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")
Expand All @@ -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);

Expand Down Expand Up @@ -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
Expand Down