mirror of
https://github.com/gbdev/rgbds.git
synced 2026-08-26 08:44:35 +00:00
Support the COLUMNS environment variable for help/usage output
This commit is contained in:
@@ -177,6 +177,9 @@ or
|
|||||||
The defaults are 0123.
|
The defaults are 0123.
|
||||||
.It Fl h , Fl \-help
|
.It Fl h , Fl \-help
|
||||||
Print help text for the program and exit.
|
Print help text for the program and exit.
|
||||||
|
(Help text wraps to the value of the
|
||||||
|
.Dv COLUMNS
|
||||||
|
environment variable if that is defined as nonzero; or else to the console window width if output is to a TTY.)
|
||||||
.It Fl I Ar path , Fl \-include Ar path
|
.It Fl I Ar path , Fl \-include Ar path
|
||||||
Add a new
|
Add a new
|
||||||
.Dq include path ;
|
.Dq include path ;
|
||||||
|
|||||||
@@ -152,6 +152,9 @@ Trash the global checksum.
|
|||||||
.El
|
.El
|
||||||
.It Fl h , Fl \-help
|
.It Fl h , Fl \-help
|
||||||
Print help text for the program and exit.
|
Print help text for the program and exit.
|
||||||
|
(Help text wraps to the value of the
|
||||||
|
.Dv COLUMNS
|
||||||
|
environment variable if that is defined as nonzero; or else to the console window width if output is to a TTY.)
|
||||||
.It Fl i Ar game_id , Fl \-game-id Ar game_id
|
.It Fl i Ar game_id , Fl \-game-id Ar game_id
|
||||||
Set the game ID string
|
Set the game ID string
|
||||||
.Pq Ad 0x13F Ns \(en Ns Ad 0x142
|
.Pq Ad 0x13F Ns \(en Ns Ad 0x142
|
||||||
|
|||||||
@@ -257,6 +257,9 @@ Set the bit depth of the output tile data, in bits per pixel (bpp), either 1 or
|
|||||||
This changes how tile data is output, and the maximum number of colors per palette (2 and 4 respectively).
|
This changes how tile data is output, and the maximum number of colors per palette (2 and 4 respectively).
|
||||||
.It Fl h , Fl \-help
|
.It Fl h , Fl \-help
|
||||||
Print help text for the program and exit.
|
Print help text for the program and exit.
|
||||||
|
(Help text wraps to the value of the
|
||||||
|
.Dv COLUMNS
|
||||||
|
environment variable if that is defined as nonzero; or else to the console window width if output is to a TTY.)
|
||||||
.It Fl i Ar input_tiles , Fl \-input-tileset Ar input_tiles
|
.It Fl i Ar input_tiles , Fl \-input-tileset Ar input_tiles
|
||||||
Use the specified input tiles in addition to having
|
Use the specified input tiles in addition to having
|
||||||
.Nm
|
.Nm
|
||||||
|
|||||||
@@ -152,6 +152,9 @@ This option automatically enables
|
|||||||
.Fl w .
|
.Fl w .
|
||||||
.It Fl h , Fl \-help
|
.It Fl h , Fl \-help
|
||||||
Print help text for the program and exit.
|
Print help text for the program and exit.
|
||||||
|
(Help text wraps to the value of the
|
||||||
|
.Dv COLUMNS
|
||||||
|
environment variable if that is defined as nonzero; or else to the console window width if output is to a TTY.)
|
||||||
.It Fl l Ar linker_script , Fl \-linkerscript Ar linker_script
|
.It Fl l Ar linker_script , Fl \-linkerscript Ar linker_script
|
||||||
Specify a linker script file that tells the linker how sections must be placed in the ROM.
|
Specify a linker script file that tells the linker how sections must be placed in the ROM.
|
||||||
The attributes assigned in the linker script must be consistent with any assigned in the code.
|
The attributes assigned in the linker script must be consistent with any assigned in the code.
|
||||||
|
|||||||
+18
-13
@@ -10,6 +10,7 @@
|
|||||||
#include "helpers.hpp"
|
#include "helpers.hpp"
|
||||||
#include "platform.hpp"
|
#include "platform.hpp"
|
||||||
#include "style.hpp"
|
#include "style.hpp"
|
||||||
|
#include "util.hpp" // parseWholeNumber
|
||||||
#include "version.hpp"
|
#include "version.hpp"
|
||||||
|
|
||||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
@@ -24,20 +25,19 @@ void Usage::printVersion(bool error) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Usage::printAndExit(int code) const {
|
void Usage::printAndExit(int code) const {
|
||||||
FILE *file;
|
// Usage flags can be long lines, so wrap them at a maximum line length
|
||||||
bool isTerminal;
|
uint64_t maxLineLen = 0;
|
||||||
if (code) {
|
// Use the conventional COLUMNS environment variable, if it is defined and nonzero
|
||||||
file = stderr;
|
if (char const *columnsStr = getenv("COLUMNS"); columnsStr) {
|
||||||
isTerminal = isatty(STDERR_FILENO);
|
if (std::optional<uint64_t> columns = parseWholeNumber(columnsStr, BASE_10);
|
||||||
} else {
|
columns && *columns > 0) {
|
||||||
file = stdout;
|
maxLineLen = *columns;
|
||||||
isTerminal = isatty(STDOUT_FILENO);
|
} else {
|
||||||
|
warnx("Ignoring invalid `COLUMNS` value \"%s\"", columnsStr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// Otherwise, use the console window width minus 1, if the output is to a console TTY
|
||||||
// Use the console window width minus 1 as the maximum line length for flags,
|
if (maxLineLen == 0 && isatty(code ? STDERR_FILENO : STDOUT_FILENO)) {
|
||||||
// or the historically common 80 minus 1 if the output is not to a console TTY
|
|
||||||
size_t maxLineLen = 79;
|
|
||||||
if (isTerminal) {
|
|
||||||
// LCOV_EXCL_START
|
// LCOV_EXCL_START
|
||||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||||
@@ -54,8 +54,13 @@ void Usage::printAndExit(int code) const {
|
|||||||
#endif
|
#endif
|
||||||
// LCOV_EXCL_STOP
|
// LCOV_EXCL_STOP
|
||||||
}
|
}
|
||||||
|
// Otherwise, just use the historically common 80 minus 1
|
||||||
|
if (maxLineLen == 0) {
|
||||||
|
maxLineLen = 79;
|
||||||
|
}
|
||||||
|
|
||||||
// Print "Usage: <program name>"
|
// Print "Usage: <program name>"
|
||||||
|
FILE *file = code ? stderr : stdout;
|
||||||
style_Set(file, STYLE_GREEN, true);
|
style_Set(file, STYLE_GREEN, true);
|
||||||
fputs("Usage: ", file);
|
fputs("Usage: ", file);
|
||||||
style_Set(file, STYLE_CYAN, true);
|
style_Set(file, STYLE_CYAN, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user