FE 0.15.0
A C++23 toolkit for writing compiler/interpreter frontends.
Loading...
Searching...
No Matches
term.h File Reference
#include <iostream>
#include <optional>
#include <sstream>
#include <stdexcept>
#include <string>
#include <string_view>
#include <type_traits>
#include "fe/api.h"
#include "fe/assert.h"
#include "fe/format.h"
#include "fe/restore.h"
Include dependency graph for term.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  fe::term::Cited
 An owning message fragment that spells `citations` of its own; what format_cite yields. More...
class  fe::term::Cite
 A borrowed fragment whose backticks stay markup; format_cite escapes every other argument. More...
class  fe::Cite
 A borrowed fragment whose backticks stay markup; format_cite escapes every other argument. More...
class  fe::Cited
 An owning message fragment that spells `citations` of its own; what format_cite yields. More...

Namespaces

namespace  fe
namespace  fe::term
 Lightweight stream-based terminal colors for diagnostics and CLI output.

Typedefs

using fe::term::ScopedMode = Restore<Mode, &mode, &set_mode>
 Overrides the color mode for the duration of the scope.
template<class... Args>
using fe::term::cite_string = std::format_string<detail::cite_arg_t<Args>...>
 A std::format_string whose backticks delimit a `citation` while those of its arguments are data.
template<class... Args>
using fe::cite_string
 <

Enumerations

enum class  fe::term::Mode {
  fe::term::Auto ,
  fe::term::Never ,
  fe::term::Always
}
 Controls whether color escape sequences are emitted. More...
enum class  fe::term::FG {
  fe::term::Black ,
  fe::term::Red ,
  fe::term::Green ,
  fe::term::Yellow ,
  fe::term::Blue ,
  fe::term::Magenta ,
  fe::term::Cyan ,
  fe::term::Gray ,
  fe::term::Grey = Gray ,
  fe::term::Reset
}
 Foreground colors that can be streamed into an std::ostream. More...

Functions

FE_API Mode fe::term::mode () noexcept
 Returns the current terminal color mode.
FE_API bool fe::term::auto_detached () noexcept
 Whether Mode::Auto emits colors into a detached buffer - anything a std::formatter writes into.
FE_API void fe::term::set_auto_detached (bool b) noexcept
 Overrides auto_detached.
FE_API bool fe::term::use_color (std::ostream &os) noexcept
 Whether color escape sequences are emitted for os right now.
FE_API std::optional< size_t > fe::term::width (std::ostream &os) noexcept
 Number of columns of the terminal os refers to.
FE_API void fe::term::set_mode (Mode m) noexcept
 Overrides the current terminal color mode.
FE_API void fe::term::resolve_mode (std::ostream &os=std::cerr) noexcept
 Decides Mode::Auto for detached buffers, depending on whether os refers to a terminal.
FE_API std::ostream & fe::term::operator<< (std::ostream &os, FG color)
 Streams the ANSI escape sequence for color when colors are enabled for os.
template<class O>
fe::term::escape_cite_to (O out, std::string_view str)
 Escapes str into out so that render_cite reproduces it verbatim instead of reading it as markup.
FE_API std::string fe::term::escape_cite (std::string_view str)
 As above but into a fresh std::string.
template<class... Args>
Cited fe::term::format_cite (cite_string< Args... > fmt, Args &&... args)
 std::format for a message that follows that convention; assemble a fragment of your own with it.
FE_API void fe::term::render_cite (std::ostream &os, std::string_view str, bool color)
 Streams str into os, coloring each `citation` and dropping its backticks - or keeping them verbatim without color; \` is a literal backtick and \\ a literal backslash.
FE_API void fe::term::render_cite (std::ostream &os, std::string_view str)
 As above but lets os decide the coloring; mirrors cite_width.
FE_API size_t fe::term::cite_width (std::string_view str, bool color)
 Number of columns str actually occupies once render_cite renders it with color - fewer than str.size() by the backticks/backslashes render_cite drops.
template<class T = std::logic_error, class... Args>
void fe::throwf (cite_string< Args... > fmt, Args &&... args)
 <
template<class... Args>
Cited fe::format_cite (cite_string< Args... > fmt, Args &&... args)
 <