Files
toml11/docs/reference/color/index.html

110 lines
22 KiB
HTML
Raw Normal View History

<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="
color.hpp
#
In color.hpp, functions related to colorizing error messages are defined.
Colors are specified using ANSI escape code.
In terminals or other output destinations that do not support ANSI escape code, the output may become difficult to read.
Macros
#
TOML11_COLORIZE_ERROR_MESSAGE
#
If this macro is defined during compilation (-DTOML11_COLORIZE_ERROR_MESASGE), error messages are colored by default.
If not defined, colors are not applied by default. You need to specify them using toml::color::enable()."><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/reference/color/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="color.hpp"><meta property="og:description" content="color.hpp # In color.hpp, functions related to colorizing error messages are defined.
Colors are specified using ANSI escape code. In terminals or other output destinations that do not support ANSI escape code, the output may become difficult to read.
Macros # TOML11_COLORIZE_ERROR_MESSAGE # If this macro is defined during compilation (-DTOML11_COLORIZE_ERROR_MESASGE), error messages are colored by default.
If not defined, colors are not applied by default. You need to specify them using toml::color::enable()."><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>color.hpp | toml11</title><link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/reference/color/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/reference/color/ title=color.hpp><link rel=stylesheet href=/toml11/book.min.6d8037b375fe949eee1b70501c5fb9478914c9c5eb3ef7696163fd3031c69421.css integrity="sha256-bYA3s3X+lJ7uG3BQHF+5R4kUycXrPvdpYWP9MDHGlCE=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.87bec23503963d7026bfa3a917b92707789d315c9c9e005e23226b35dce643f5.js integrity="sha256-h77CNQOWPXAmv6OpF7knB3idMVycngBeIyJrNdzmQ/U=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/reference/color/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle>
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle checked>
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/ class=active>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
</label><strong>color.hpp</strong>
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#colorhpp>color.hpp</a><ul><li><a href=#macros>Macros</a><ul><li><a href=#toml11_colorize_error_message><code>TOML11_COLORIZE_ERROR_MESSAGE</code></a></li><li><a href=#toml11_use_thread_local_colorization><code>TOML11_USE_THREAD_LOCAL_COLORIZATION</code></a></li></ul></li><li><a href=#functions>Functions</a><ul><li><a href=#enable><code>enable()</code></a></li><li><a href=#disable><code>disable()</code></a></li><li><a href=#should_color><code>should_color()</code></a></li></ul></li><li><a href=#manipulators>Manipulators</a><ul><li></li></ul></li></ul></li><li><a href=#related>Related</a></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=colorhpp>color.hpp
<a class=anchor href=#colorhpp>#</a></h1><p>In <code>color.hpp</code>, functions related to colorizing error messages are defined.</p><p>Colors are specified using ANSI escape code.
In terminals or other output destinations that do not support ANSI escape code, the output may become difficult to read.</p><h2 id=macros>Macros
<a class=anchor href=#macros>#</a></h2><h3 id=toml11_colorize_error_message><code>TOML11_COLORIZE_ERROR_MESSAGE</code>
<a class=anchor href=#toml11_colorize_error_message>#</a></h3><p>If this macro is defined during compilation (<code>-DTOML11_COLORIZE_ERROR_MESASGE</code>), error messages are colored by default.</p><p>If not defined, colors are not applied by default. You need to specify them using <code>toml::color::enable()</code>.</p><h3 id=toml11_use_thread_local_colorization><code>TOML11_USE_THREAD_LOCAL_COLORIZATION</code>
<a class=anchor href=#toml11_use_thread_local_colorization>#</a></h3><p>If this macro is defined during compilation (<code>-DTOML11_USE_THREAD_LOCAL_COLORIZATION</code>), the colorization flag becomes <code>thread_local</code>.
In this case, <code>toml::color::enable()</code> or <code>toml::color::disable()</code> will only affect the colorization flag in the thread that called it.
This means that if you want to use a different setting from the default, you will need to set it again when starting a new thread.
This makes <code>toml::color::enable()</code> and <code>toml::color::disable()</code> thread safe.</p><p>By default, the setting is global.
When it is global, if one thread executes <code>toml::color::enable()</code>, the error messages will be colored in all threads.
However, if one thread executes <code>enable()</code> or <code>disable()</code> while another executes <code>enable()</code>, <code>disable()</code> or <code>should_color()</code>, the result is undefined.</p><h2 id=functions>Functions
<a class=anchor href=#functions>#</a></h2><h3 id=enable><code>enable()</code>
<a class=anchor href=#enable>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml {
</span></span><span style=display:flex><span><span style=color:#66d9ef>namespace</span> color {
</span></span><span style=display:flex><span><span style=color:#66d9ef>void</span> <span style=color:#a6e22e>enable</span>();
</span></span><span style=display:flex><span>} <span style=color:#75715e>// color
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>} <span style=color:#75715e>// toml
</span></span></span></code></pre></div><p>Enables colorization using ANSI escape code.</p><h4 id=example>Example
<a class=anchor href=#example>#</a></h4><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e>&lt;toml.hpp&gt;</span><span style=color:#75715e>
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
</span></span><span style=display:flex><span>{
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>color<span style=color:#f92672>::</span>enable(); <span style=color:#75715e>// All subsequent errors will be colored.
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(<span style=color:#e6db74>&#34;input.toml&#34;</span>);
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><h3 id=disable><code>disable()</code>
<a class=anchor href=#disable>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml {
</span></span><span style=display:flex><span><span style=color:#66d9ef>namespace</span> color {
</span></span><span style=display:flex><span><span style=color:#66d9ef>void</span> <span style=color:#a6e22e>disable</span>();
</span></span><span style=display:flex><span>} <span style=color:#75715e>// color
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>} <span style=color:#75715e>// toml
</span></span></span></code></pre></div><p>Disables colorization using ANSI escape code.</p><h4 id=example-1>Example
<a class=anchor href=#example-1>#</a></h4><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e>&lt;toml.hpp&gt;</span><span style=color:#75715e>
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
</span></span><span style=display:flex><span>{
</span></span><span style=display:flex><span> toml<span style=color:#f92672>::</span>color<span style=color:#f92672>::</span>disable(); <span style=color:#75715e>// All subsequent errors will not be colored.
</span></span></span><span style=display:flex><span><span style=color:#75715e></span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> input <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(<span style=color:#e6db74>&#34;input.toml&#34;</span>);
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><h3 id=should_color><code>should_color()</code>
<a class=anchor href=#should_color>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml {
</span></span><span style=display:flex><span><span style=color:#66d9ef>namespace</span> color {
</span></span><span style=display:flex><span><span style=color:#66d9ef>bool</span> <span style=color:#a6e22e>should_color</span>();
</span></span><span style=display:flex><span>} <span style=color:#75715e>// color
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>} <span style=color:#75715e>// toml
</span></span></span></code></pre></div><p>Returns <code>true</code> if colorization is enabled, <code>false</code> otherwise.</p><h4 id=example-2>Example
<a class=anchor href=#example-2>#</a></h4><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e>&lt;toml.hpp&gt;</span><span style=color:#75715e>
</span></span></span><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e>&lt;iomanip&gt;</span><span style=color:#75715e>
</span></span></span><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e>&lt;iostream&gt;</span><span style=color:#75715e>
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
</span></span><span style=display:flex><span>{
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672>&lt;&lt;</span> <span style=color:#e6db74>&#34;colorized? : &#34;</span> <span style=color:#f92672>&lt;&lt;</span> std<span style=color:#f92672>::</span>boolalpha <span style=color:#f92672>&lt;&lt;</span> toml<span style=color:#f92672>::</span>color<span style=color:#f92672>::</span>should_color() <span style=color:#f92672>&lt;&lt;</span> std<span style=color:#f92672>::</span>endl;
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><h2 id=manipulators>Manipulators
<a class=anchor href=#manipulators>#</a></h2><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#66d9ef>namespace</span> toml {
</span></span><span style=display:flex><span><span style=color:#66d9ef>namespace</span> color {
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&amp;</span> reset (std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&amp;</span>);
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&amp;</span> bold (std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&amp;</span>);
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&amp;</span> grey (std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&amp;</span>);
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&amp;</span> gray (std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&amp;</span>);
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&amp;</span> red (std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&amp;</span>);
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&amp;</span> green (std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&amp;</span>);
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&amp;</span> yellow (std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&amp;</span>);
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&amp;</span> blue (std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&amp;</span>);
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&amp;</span> magenta(std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&amp;</span>);
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&amp;</span> cyan (std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&amp;</span>);
</span></span><span style=display:flex><span>std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&amp;</span> white (std<span style=color:#f92672>::</span>ostream<span style=color:#f92672>&amp;</span>);
</span></span><span style=display:flex><span>} <span style=color:#75715e>// color
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>} <span style=color:#75715e>// toml
</span></span></span></code></pre></div><p>Colorizes the foreground with ANSI escape code.</p><h4 id=example-3>Example
<a class=anchor href=#example-3>#</a></h4><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e>&lt;toml.hpp&gt;</span><span style=color:#75715e>
</span></span></span><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e>&lt;iostream&gt;</span><span style=color:#75715e>
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
</span></span><span style=display:flex><span>{
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672>&lt;&lt;</span> toml<span style=color:#f92672>::</span>color<span style=color:#f92672>::</span>red <span style=color:#f92672>&lt;&lt;</span> <span style=color:#e6db74>&#34;red!&#34;</span> <span style=color:#f92672>&lt;&lt;</span> toml<span style=color:#f92672>::</span>color<span style=color:#f92672>::</span>reset <span style=color:#f92672>&lt;&lt;</span> std<span style=color:#f92672>::</span>endl;
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><h1 id=related>Related
<a class=anchor href=#related>#</a></h1><ul><li><a href=https://toruniina.github.io/toml11/docs/reference/error_info/>error_info.hpp</a></li></ul></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#colorhpp>color.hpp</a><ul><li><a href=#macros>Macros</a><ul><li><a href=#toml11_colorize_error_message><code>TOML11_COLORIZE_ERROR_MESSAGE</code></a></li><li><a href=#toml11_use_thread_local_colorization><code>TOML11_USE_THREAD_LOCAL_COLORIZATION</code></a></li></ul></li><li><a href=#functions>Functions</a><ul><li><a href=#enable><code>enable()</code></a></li><li><a href=#disable><code>disable()</code></a></li><li><a href=#should_color><code>should_color()</code></a></li></ul></li><li><a href=#manipulators>Manipulators</a><ul><li></li></ul></li></ul></li><li><a href=#related>Related</a></li></ul></nav></div></aside></main></body></html>