snipt

Ctrl+h for KB shortcuts
Notice: Snipt is moving away from free accounts on May 1st, 2014. Read more about the transition here.
#29821

C++

Color struct in C for colored terminal output. Just append to stdout and all text after wil be colored.

1
2
3
4
5
6
struct color {
// A structure with variables to color terminal output.
char red[] = "\033[0;31m";
char white[] = "\033[0;37m";
char yellow[] = "\033[0;33m";
}
https://snipt.net/embed/d81e88d928f9dc9c4a7bae284819df3e/
https://snipt.net/raw/d81e88d928f9dc9c4a7bae284819df3e/
d81e88d928f9dc9c4a7bae284819df3e
cpp
C++
6
2014-04-23T16:42:22
True
False
/api/public/snipt/29821/
color-struct-in-c-for-colored-terminal-output-just-append-to-stdout-and-all-text-after-wil-be-colored
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="k">struct</span> <span class="n">color</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a><span class="c1">// A structure with variables to color terminal output.</span> </span><span id="L-3"><a name="L-3"></a><span class="kt">char</span> <span class="n">red</span><span class="p">[]</span> <span class="o">=</span> <span class="s">&quot;</span><span class="se">\033</span><span class="s">[0;31m&quot;</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="kt">char</span> <span class="n">white</span><span class="p">[]</span> <span class="o">=</span> <span class="s">&quot;</span><span class="se">\033</span><span class="s">[0;37m&quot;</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="kt">char</span> <span class="n">yellow</span><span class="p">[]</span> <span class="o">=</span> <span class="s">&quot;</span><span class="se">\033</span><span class="s">[0;33m&quot;</span><span class="p">;</span> </span><span id="L-6"><a name="L-6"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
c, color, stdout, terminal