Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
.github/workflows/ | 12-May-2024 | - | 79 | 77 | ||
src/ | 12-May-2024 | - | 2,351 | 1,636 | ||
wincolor/ | 12-May-2024 | - | 415 | 278 | ||
.gitignore | D | 12-May-2024 | 52 | 6 | 5 | |
BUILD.gn | D | 12-May-2024 | 906 | 27 | 23 | |
COPYING | D | 12-May-2024 | 126 | 4 | 2 | |
Cargo.toml | D | 12-May-2024 | 734 | 27 | 23 | |
LICENSE-MIT | D | 12-May-2024 | 1.1 KiB | 22 | 17 | |
OAT.xml | D | 12-May-2024 | 4.3 KiB | 68 | 14 | |
README.OpenSource | D | 12-May-2024 | 312 | 11 | 11 | |
README.md | D | 12-May-2024 | 4.3 KiB | 116 | 85 | |
UNLICENSE | D | 12-May-2024 | 1.2 KiB | 25 | 20 | |
rustfmt.toml | D | 12-May-2024 | 44 | 3 | 2 |
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 [](https://github.com/BurntSushi/termcolor/actions) 10 [](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