• Home
Name
Date
Size
#Lines
LOC

..--

.github/workflows/12-May-2024-7977

src/12-May-2024-2,3511,636

wincolor/12-May-2024-415278

.gitignoreD12-May-202452 65

BUILD.gnD12-May-2024906 2723

COPYINGD12-May-2024126 42

Cargo.tomlD12-May-2024734 2723

LICENSE-MITD12-May-20241.1 KiB2217

OAT.xmlD12-May-20244.3 KiB6814

README.OpenSourceD12-May-2024312 1111

README.mdD12-May-20244.3 KiB11685

UNLICENSED12-May-20241.2 KiB2520

rustfmt.tomlD12-May-202444 32

README.OpenSource

1 [
2   {
3     "Name": "termcolor",
4     "License": "MIT",
5     "License File": "LICENSE-MIT",
6     "Version Number": "1.2.0",
7     "Owner": "fangting12@huawei.com",
8     "Upstream URL": "https://github.com/BurntSushi/termcolor",
9     "Description": "A Rust library that provides support for colored terminal output."
10   }
11 ]

README.md

1 termcolor
2 =========
3 A simple cross platform library for writing colored text to a terminal. This
4 library writes colored text either using standard ANSI escape sequences or
5 by interacting with the Windows console. Several convenient abstractions
6 are provided for use in single-threaded or multi-threaded command line
7 applications.
8 
9 [![Build status](https://github.com/BurntSushi/termcolor/workflows/ci/badge.svg)](https://github.com/BurntSushi/termcolor/actions)
10 [![](https://img.shields.io/crates/v/termcolor.svg)](https://crates.io/crates/termcolor)
11 
12 Dual-licensed under MIT or the [UNLICENSE](https://unlicense.org/).
13 
14 ### Documentation
15 
16 [https://docs.rs/termcolor](https://docs.rs/termcolor)
17 
18 ### Usage
19 
20 Add this to your `Cargo.toml`:
21 
22 ```toml
23 [dependencies]
24 termcolor = "1.1"
25 ```
26 
27 ### Organization
28 
29 The `WriteColor` trait extends the `io::Write` trait with methods for setting
30 colors or resetting them.
31 
32 `StandardStream` and `StandardStreamLock` both satisfy `WriteColor` and are
33 analogous to `std::io::Stdout` and `std::io::StdoutLock`, or `std::io::Stderr`
34 and `std::io::StderrLock`.
35 
36 `Buffer` is an in memory buffer that supports colored text. In a parallel
37 program, each thread might write to its own buffer. A buffer can be printed to
38 stdout or stderr using a `BufferWriter`. The advantage of this design is that
39 each thread can work in parallel on a buffer without having to synchronize
40 access to global resources such as the Windows console. Moreover, this design
41 also prevents interleaving of buffer output.
42 
43 `Ansi` and `NoColor` both satisfy `WriteColor` for arbitrary implementors of
44 `io::Write`. These types are useful when you know exactly what you need. An
45 analogous type for the Windows console is not provided since it cannot exist.
46 
47 ### Example: using `StandardStream`
48 
49 The `StandardStream` type in this crate works similarly to `std::io::Stdout`,
50 except it is augmented with methods for coloring by the `WriteColor` trait.
51 For example, to write some green text:
52 
53 ```rust
54 use std::io::{self, Write};
55 use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
56 
57 fn write_green() -> io::Result<()> {
58     let mut stdout = StandardStream::stdout(ColorChoice::Always);
59     stdout.set_color(ColorSpec::new().set_fg(Some(Color::Green)))?;
60     writeln!(&mut stdout, "green text!")
61 }
62 ```
63 
64 ### Example: using `BufferWriter`
65 
66 A `BufferWriter` can create buffers and write buffers to stdout or stderr. It
67 does *not* implement `io::Write` or `WriteColor` itself. Instead, `Buffer`
68 implements `io::Write` and `termcolor::WriteColor`.
69 
70 This example shows how to print some green text to stderr.
71 
72 ```rust
73 use std::io::{self, Write};
74 use termcolor::{BufferWriter, Color, ColorChoice, ColorSpec, WriteColor};
75 
76 fn write_green() -> io::Result<()> {
77     let mut bufwtr = BufferWriter::stderr(ColorChoice::Always);
78     let mut buffer = bufwtr.buffer();
79     buffer.set_color(ColorSpec::new().set_fg(Some(Color::Green)))?;
80     writeln!(&mut buffer, "green text!")?;
81     bufwtr.print(&buffer)
82 }
83 ```
84 
85 ### Automatic color selection
86 
87 When building a writer with termcolor, the caller must provide a
88 [`ColorChoice`](https://docs.rs/termcolor/1.*/termcolor/enum.ColorChoice.html)
89 selection. When the color choice is `Auto`, termcolor will attempt to determine
90 whether colors should be enabled by inspecting the environment. Currently,
91 termcolor will inspect the `TERM` and `NO_COLOR` environment variables:
92 
93 * If `NO_COLOR` is set to any value, then colors will be suppressed.
94 * If `TERM` is set to `dumb`, then colors will be suppressed.
95 * In non-Windows environments, if `TERM` is not set, then colors will be
96   suppressed.
97 
98 This decision procedure may change over time.
99 
100 Currently, `termcolor` does not attempt to detect whether a tty is present or
101 not. To achieve that, please use the [`atty`](https://crates.io/crates/atty)
102 crate.
103 
104 ### Minimum Rust version policy
105 
106 This crate's minimum supported `rustc` version is `1.34.0`.
107 
108 The current policy is that the minimum Rust version required to use this crate
109 can be increased in minor version updates. For example, if `crate 1.0` requires
110 Rust 1.20.0, then `crate 1.0.z` for all values of `z` will also require Rust
111 1.20.0 or newer. However, `crate 1.y` for `y > 0` may require a newer minimum
112 version of Rust.
113 
114 In general, this crate will be conservative with respect to the minimum
115 supported version of Rust.
116