mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Use colored/styled text output for diagnostics and usage info (#1775)
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#define STDERR_FILENO 2
|
||||
#define ssize_t int
|
||||
#define SSIZE_MAX INT_MAX
|
||||
#define isatty _isatty
|
||||
#else
|
||||
#include <fcntl.h> // IWYU pragma: export
|
||||
#include <limits.h> // IWYU pragma: export
|
||||
|
||||
42
include/style.hpp
Normal file
42
include/style.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#ifndef RGBDS_STYLE_HPP
|
||||
#define RGBDS_STYLE_HPP
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__)
|
||||
#define STYLE_ANSI 0
|
||||
#else
|
||||
#define STYLE_ANSI 1
|
||||
#endif
|
||||
|
||||
enum StyleColor {
|
||||
#if STYLE_ANSI
|
||||
// Values analogous to ANSI foreground and background SGR colors
|
||||
STYLE_BLACK,
|
||||
STYLE_RED,
|
||||
STYLE_GREEN,
|
||||
STYLE_YELLOW,
|
||||
STYLE_BLUE,
|
||||
STYLE_MAGENTA,
|
||||
STYLE_CYAN,
|
||||
STYLE_GRAY,
|
||||
#else
|
||||
// Values analogous to `FOREGROUND_*` constants from `windows.h`
|
||||
STYLE_BLACK,
|
||||
STYLE_BLUE, // bit 0
|
||||
STYLE_GREEN, // bit 1
|
||||
STYLE_CYAN, // STYLE_BLUE | STYLE_GREEN
|
||||
STYLE_RED, // bit 2
|
||||
STYLE_MAGENTA, // STYLE_BLUE | STYLE_RED
|
||||
STYLE_YELLOW, // STYLE_GREEN | STYLE_RED
|
||||
STYLE_GRAY, // STYLE_BLUE | STYLE_GREEN | STYLE_RED
|
||||
#endif
|
||||
};
|
||||
|
||||
void style_Enable(bool enable);
|
||||
void style_Set(FILE *file, StyleColor color, bool bold);
|
||||
void style_Reset(FILE *file);
|
||||
|
||||
#endif // RGBDS_STYLE_HPP
|
||||
@@ -4,12 +4,14 @@
|
||||
#define RGBDS_USAGE_HPP
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
class Usage {
|
||||
char const *usage;
|
||||
|
||||
public:
|
||||
Usage(char const *usage_) : usage(usage_) {}
|
||||
struct Usage {
|
||||
std::string name;
|
||||
std::vector<std::string> flags;
|
||||
std::vector<std::pair<std::vector<std::string>, std::vector<std::string>>> options;
|
||||
|
||||
[[noreturn]]
|
||||
void printAndExit(int code) const;
|
||||
|
||||
Reference in New Issue
Block a user