edlang/owo_colors/index.html

75 lines
16 KiB
HTML
Raw Normal View History

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Quick Links`OwoColorize``Style``StyledList``github`This crate provides `OwoColorize`, an extension trait for colorizing a given type."><title>owo_colors - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="owo_colors" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0 (051478957 2024-07-21)" data-channel="1.80.0" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../static.files/storage-118b08c4c78b968e.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-df360f571f6edeae.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../owo_colors/index.html"><img src="https://jam1.re/img/rust_owo.svg" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../owo_colors/index.html"><img src="https://jam1.re/img/rust_owo.svg" alt="logo"></a><h2><a href="../owo_colors/index.html">owo_colors</a><span class="version">4.0.0</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#modules">Modules</a></li><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#traits">Traits</a></li><li><a href="#functions">Functions</a></li></ul></section></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Crate <a class="mod" href="#">owo_colors</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><a class="src" href="../src/owo_colors/lib.rs.html#1-532">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>&#x2212;</span>]</button></span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><div><table><thead><tr><th><strong>Quick Links</strong></th><th><a href="trait.OwoColorize.html" title="trait owo_colors::OwoColorize"><code>OwoColorize</code></a></th><th><a href="struct.Style.html" title="struct owo_colors::Style"><code>Style</code></a></th><th><a href="struct.StyledList.html" title="struct owo_colors::StyledList"><code>StyledList</code></a></th><th><a href="https://github.com/jam1garner/owo-colors"><code>github</code></a></th></tr></thead><tbody>
</tbody></table>
</div>
<hr />
<p>This crate provides <a href="trait.OwoColorize.html" title="trait owo_colors::OwoColorize"><code>OwoColorize</code></a>, an extension trait for colorizing a
given type.</p>
<h3 id="example"><a class="doc-anchor" href="#example">§</a>Example</h3>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>owo_colors::OwoColorize;
<span class="kw">fn </span>main() {
<span class="comment">// Foreground colors
</span><span class="macro">println!</span>(<span class="string">"My number is {:#x}!"</span>, <span class="number">10</span>.green());
<span class="comment">// Background colors
</span><span class="macro">println!</span>(<span class="string">"My number is not {}!"</span>, <span class="number">4</span>.on_red());
}</code></pre></div>
<h3 id="generically-color"><a class="doc-anchor" href="#generically-color">§</a>Generically color</h3>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>owo_colors::OwoColorize;
<span class="kw">use </span>owo_colors::colors::<span class="kw-2">*</span>;
<span class="kw">fn </span>main() {
<span class="comment">// Generically color
</span><span class="macro">println!</span>(<span class="string">"My number might be {}!"</span>, <span class="number">4</span>.fg::&lt;Black&gt;().bg::&lt;Yellow&gt;());
}</code></pre></div>
<h3 id="stylize"><a class="doc-anchor" href="#stylize">§</a>Stylize</h3>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>owo_colors::OwoColorize;
<span class="macro">println!</span>(<span class="string">"{}"</span>, <span class="string">"strikethrough"</span>.strikethrough());</code></pre></div>
<h3 id="only-style-on-supported-terminals"><a class="doc-anchor" href="#only-style-on-supported-terminals">§</a>Only Style on Supported Terminals</h3>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>owo_colors::{OwoColorize, Stream::Stdout};
<span class="macro">println!</span>(
<span class="string">"{}"</span>,
<span class="string">"colored blue if a supported terminal"
</span>.if_supports_color(Stdout, |text| text.bright_blue())
);</code></pre></div>
<p>Supports <code>NO_COLOR</code>/<code>FORCE_COLOR</code> environment variables, checks if its a tty, checks
if its running in CI (and thus likely supports color), and checks which terminal is being
used. (Note: requires <code>supports-colors</code> feature)</p>
<h3 id="style-objects"><a class="doc-anchor" href="#style-objects">§</a>Style Objects</h3>
<p>owo-colors also features the ability to create a <a href="struct.Style.html" title="struct owo_colors::Style"><code>Style</code></a> object and use it to
apply the same set of colors/effects to any number of things to display.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>owo_colors::{OwoColorize, Style};
<span class="kw">let </span>my_style = Style::new()
.red()
.on_white()
.strikethrough();
<span class="kw">let </span>text = <span class="string">"red text, white background, struck through"</span>;
<span class="macro">println!</span>(<span class="string">"{}"</span>, text.style(my_style));</code></pre></div>
</div></details><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="colored/index.html" title="mod owo_colors::colored">colored</a></div><div class="desc docblock-short">Module for drop-in <a href="https://docs.rs/colored"><code>colored</code></a> support to aid in porting code from
<a href="https://docs.rs/colored"><code>colored</code></a> to owo-colors.</div></li><li><div class="item-name"><a class="mod" href="colors/index.html" title="mod owo_colors::colors">colors</a></div><div class="desc docblock-short">Color types for used for being generic over the color</div></li><li><div class="item-name"><a class="mod" href="styles/index.html" title="mod owo_colors::styles">styles</a></div><div class="desc docblock-short">Different display styles (strikethrough, bold, etc.)</div></li></ul><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.BgColorDisplay.html" title="struct owo_colors::BgColorDisplay">BgColorDisplay</a></div><div class="desc docblock-short">Transparent wrapper around a type which implements all the formatters the wrapped type does,
with the addition of changing the background color. Recommended to be constructed using
<a href="trait.OwoColorize.html" title="trait owo_colors::OwoColorize"><code>OwoColorize</code></a>.</div></li><li><div class="item-name"><a class="struct" href="struct.BgDynColorDisplay.html" title="struct owo_colors::BgDynColorDisplay">BgDynColorDisplay</a></div><div class="desc docblock-short">Wrapper around a type which implements all the formatters the wrapped type does,
with the addition of changing the background color. Is not recommended unless compile-time
coloring is not an option.</div></li><li><div class="item-name"><a class="struct" href="struct.ComboColorDisplay.html" title="struct owo_colors::ComboColorDisplay">ComboColorDisplay</a></div><div class="desc docblock-short">A wrapper type which applies both a foreground and background color</div></li><li><div class="item-name"><a class="struct" href="struct.FgColorDisplay.html" title="struct owo_colors::FgColorDisplay">FgColorDisplay</a></div><div class="desc docblock-short">Transparent wrapper around a type which implements all the formatters the wrapped type does,
with the addition of changing the foreground color. Recommended to be constructed using
<a href="trait.OwoColorize.html" title="trait owo_colors::OwoColorize"><code>OwoColorize</code></a>.</div></li><li><div class="item-name"><a class="struct" href="struct.FgDynColorDisplay.html" title="struct owo_colors::FgDynColorDisplay">FgDynColorDisplay</a></div><div class="desc docblock-short">Wrapper around a type which implements all the formatters the wrapped type does,
with the addition of changing the foreground color. Is not recommended unless compile-time
coloring is not an option.</div></li><li><div class="item-name"><a class="struct" href="struct.ParseColorError.html" title="struct owo_colors::ParseColorError">ParseColorError</a></div><div class="desc docblock-short">An error for when the color can not be parsed from a string at runtime</div></li><li><div class="item-name"><a class="struct" href="struct.Rgb.html" title="struct owo_colors::Rgb">Rgb</a></div><div class="desc docblock-short">Available RGB colors for use with <a href="trait.OwoColorize.html#method.color" title="method owo_colors::OwoColorize::color"><code>OwoColorize::color</code></a>
or <a href="trait.OwoColorize.html#method.on_color" title="method owo_colors::OwoColorize::on_color"><code>OwoColorize::on_color</code></a></div></li><li><div class="item-name"><a class="struct" href="struct.Style.html" title="struct owo_colors::Style">Style</a></div><div class="desc docblock-short">A pre-computed style that can be applied to a struct using <a href="trait.OwoColorize.html#method.style" title="method owo_colors::OwoColorize::style"><code>OwoColorize::style</code></a>. Its
interface mimics that of <a href="trait.OwoColorize.html" title="trait owo_colors::OwoColorize"><code>OwoColorize</code></a>, but instead of chaining methods on your
object, you instead chain them on the <code>Style</code> object before applying it.</div></li><li><div class="item-name"><a class="struct" href="struct.Styled.html" title="struct owo_colors::Styled">Styled</a></div><div class="desc docblock-short">A wrapper type which applies a <a href="struct.Style.html" title="struct owo_colors::Style"><code>Style</code></a> when displaying the inner type</div></li><li><div class="item-name"><a class="struct" href="struct.StyledList.html" title="struct owo_colors::StyledList">StyledList</a></div><div class="desc docblock-short">A collection of <a href="struct.Styled.html" title="struct owo_colors::Styled"><code>Styled</code></a> items that are displayed in such a way as to minimize the amount of characters
that are written when displayed.</div></li></ul><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.AnsiColors.html" title="enum owo_colors::AnsiColors">AnsiColors</a></div><div class="desc docblock-short">Available standard ANSI colors for use with <a href="trait.OwoColorize.html#method.color" title="method owo_colors::OwoColorize::color"><code>OwoColorize::color</code></a>
or <a href="trait.OwoColorize.html#method.on_color" title="method owo_colors::OwoColorize::on_color"><code>OwoColorize::on_color</code></a></div></li><li><div class="item-name"><a class="enum" href="enum.CssColors.html" title="enum owo_colors::CssColors">CssColors</a></div><div class="desc docblock-short">Available CSS colors for use with <a href="trait.OwoColorize.html#method.color" title="method owo_colors::OwoColorize::color"><code>OwoColorize::color</code></a>
or <a href="trait.OwoColorize.html#method.on_color" title="method owo_colors::OwoColorize::on_color"><code>OwoColorize::on_color</code></a></div></li><li><div class="item-name"><a class="enum" href="enum.DynColors.html" title="enum owo_colors::DynColors">DynColors</a></div><div class="desc docblock-short">An enum describing runtime-configurable colors which can be displayed using <a href="struct.FgDynColorDisplay.html" title="struct owo_colors::FgDynColorDisplay"><code>FgDynColorDisplay</code></a>
or <a href="struct.BgDynColorDisplay.html" title="struct owo_colors::BgDynColorDisplay"><code>BgDynColorDisplay</code></a>, allowing for multiple types of colors to be used
at runtime.</div></li><li><div class="item-name"><a class="enum" href="enum.Effect.html" title="enum owo_colors::Effect">Effect</a></div><div class="desc docblock-short">A runtime-configurable text effect for use with <a href="struct.Style.html" title="struct owo_colors::Style"><code>Style</code></a></div></li><li><div class="item-name"><a class="enum" href="enum.XtermColors.html" title="enum owo_colors::XtermColors">XtermColors</a></div><div class="desc docblock-short">Available Xterm colors for use with <a href="trait.OwoColorize.html#method.color" title="method owo_colors::OwoColorize::color"><code>OwoColorize::color</code></a>
or <a href="trait.OwoColorize.html#method.on_color" title="method owo_colors::OwoColorize::on_color"><code>OwoColorize::on_color</code></a></div></li></ul><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.Color.html" title="trait owo_colors::Color">Color</a></div><div class="desc docblock-short">A trait for describing a type which can be used with <a href="struct.FgColorDisplay.html" title="struct owo_colors::FgColorDisplay"><code>FgColorDisplay</code></a> or
<a href="struct.BgColorDisplay.html" title="struct owo_colors::BgColorDisplay"><code>BgColorDisplay</code></a></div></li><li><div class="item-name"><a class="trait" href="trait.DynColor.html" title="trait owo_colors::DynColor">DynColor</a></div><div class="desc docblock-short">A trait describing a runtime-configurable color which can displayed using <a href="struct.FgDynColorDisplay.html" title="struct owo_colors::FgDynColorDisplay"><code>FgDynColorDisplay</code></a>
or <a href="struct.BgDynColorDisplay.html" title="struct owo_colors::BgDynColorDisplay"><code>BgDynColorDisplay</code></a>. If your color will be known at compile time it
is recommended you avoid this.</div></li><li><div class="item-name"><a class="trait" href="trait.OwoColorize.html" title="trait owo_colors::OwoColorize">OwoColorize</a></div><div class="desc docblock-short">Extension trait for colorizing a type which implements any std formatter
(<a href="https://doc.rust-lang.org/1.80.0/core/fmt/trait.Display.html" title="trait core::fmt::Display"><code>Display</code></a>, <a href="https://doc.rust-lang.org/1.80.0/core/fmt/trait.Debug.html" title="trait core::fmt::Debug"><code>Debug</code></a>, <a href="https://doc.rust-lang.org/1.80.0/core/fmt/trait.UpperHex.html" title="trait core::fmt::UpperHex"><code>UpperHex</code></a>,
etc.)</div></li></ul><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.style.html" title="fn owo_colors::style">style</a></div><div class="desc docblock-short">Helper to create <a href="struct.Style.html" title="struct owo_colors::Style"><code>Style</code></a>s more ergonomically</div></li></ul></section></div></main></body></html>