cli: clean-up crate

This does a variety of polishing.

1. Deprecate the tty methods in favor of std's IsTerminal trait.
2. Trim down un-needed dependencies.
3. Use bstr to implement escaping.
4. Various aesthetic polishing.

I'm doing this as prep work before adding more to this crate. And as
part of a general effort toward reducing ripgrep's dependencies.
This commit is contained in:
Andrew Gallant
2023-09-20 14:42:03 -04:00
parent 1a50324013
commit 19a08bee8a
11 changed files with 165 additions and 306 deletions

View File

@@ -1,9 +1,6 @@
use std::io;
use std::io::{self, IsTerminal};
use termcolor;
use termcolor::HyperlinkSpec;
use crate::is_tty_stdout;
use termcolor::{self, HyperlinkSpec};
/// A writer that supports coloring with either line or block buffering.
pub struct StandardStream(StandardStreamKind);
@@ -23,7 +20,7 @@ pub struct StandardStream(StandardStreamKind);
/// The color choice given is passed along to the underlying writer. To
/// completely disable colors in all cases, use `ColorChoice::Never`.
pub fn stdout(color_choice: termcolor::ColorChoice) -> StandardStream {
if is_tty_stdout() {
if std::io::stdout().is_terminal() {
stdout_buffered_line(color_choice)
} else {
stdout_buffered_block(color_choice)