slang::OS class

A collection of various OS-specific utility functions.

Public static functions

static void setupConsole()
Does initial one-time setup of OS console.
static auto tryEnableColors() -> bool
Tries to enable color output support for stdout and stderr.
static auto fileSupportsColors(int fd) -> bool
static auto fileSupportsColors(FILE* file) -> bool
static void setStdoutColorsEnabled(bool enabled)
Sets whether color output should be enabled for the print() functions.
static auto readFile(const std::filesystem::path& path, SmallVector<char>& buffer) -> std::error_code
Reads a file from path into memory.
static void writeFile(const std::filesystem::path& path, std::string_view contents)
Writes the given contents to the specified file.
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()

Tries to enable color output support for stdout and stderr.

Returns true if successful and false otherwise.

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 std::error_code slang::OS::readFile(const std::filesystem::path& path, SmallVector<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.