slang::OS class

A collection of various OS-specific utility functions.

Public static functions

static auto tryEnableColors() -> bool
static auto fileSupportsColors(int fd) -> bool
static auto fileSupportsColors(FILE* file) -> bool
static void setStdoutColorsEnabled(bool enabled)
static auto readFile(const std::filesystem::path& path, std::vector<char>& buffer) -> bool
static void print(std::string_view text)
Prints text to stdout.
static void print(const fmt::text_style& style, std::string_view text)
Prints colored formatted text to stdout.
static void printE(std::string_view text)
Prints formatted text to stderr.
static void printE(const fmt::text_style& style, std::string_view text)
Prints colored formatted text to stderr.

Function documentation

static bool slang::OS::tryEnableColors()

Returns true if successful and false otherwise.

Tries to enable color output support for stdout and stderr.

static bool slang::OS::fileSupportsColors(int fd)

Returns true if the given file descriptor supports color text output.

static bool slang::OS::fileSupportsColors(FILE* file)

Returns true if the given FILE supports color text output.

static void slang::OS::setStdoutColorsEnabled(bool enabled)

Sets whether color output should be enabled for the print() functions. This is off by default.

static bool slang::OS::readFile(const std::filesystem::path& path, std::vector<char>& buffer)

Reads a file from path into memory. If successful, the bytes are placed into buffer – otherwise, returns false. Note that the buffer will be null-terminated.