Debian Codegraph @

src/wtr.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, IsTerminalrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/IsTerminal#};
2
3 use termcolorrust-analyzer cargo termcolor 1.4.1 crate/::HyperlinkSpecrust-analyzer cargo termcolor 1.4.1 HyperlinkSpec#;
4
5 /// A writer that supports coloring with either line or block buffering.
6 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
7 pub struct StandardStreamrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStream#(StandardStreamKindrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#);
8
9 /// Returns a possibly buffered writer to stdout for the given color choice.
10 ///
11 /// The writer returned is either line buffered or block buffered. The decision
12 /// between these two is made automatically based on whether a tty is attached
13 /// to stdout or not. If a tty is attached, then line buffering is used.
14 /// Otherwise, block buffering is used. In general, block buffering is more
15 /// efficient, but may increase the time it takes for the end user to see the
16 /// first bits of output.
17 ///
18 /// If you need more fine grained control over the buffering mode, then use one
19 /// of `stdout_buffered_line` or `stdout_buffered_block`.
20 ///
21 /// The color choice given is passed along to the underlying writer. To
22 /// completely disable colors in all cases, use `ColorChoice::Never`.
23 pub fn stdoutrust-analyzer cargo grep-cli 0.1.12 wtr/stdout().(color_choice: termcolorrust-analyzer cargo termcolor 1.4.1 crate/::ColorChoicerust-analyzer cargo termcolor 1.4.1 ColorChoice#) -> StandardStreamrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStream# {
24 if stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdout().().is_terminalrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stdout][IsTerminal]is_terminal().() {
25 stdout_buffered_linerust-analyzer cargo grep-cli 0.1.12 wtr/stdout_buffered_line().(color_choice)
26 } else {
27 stdout_buffered_blockrust-analyzer cargo grep-cli 0.1.12 wtr/stdout_buffered_block().(color_choice)
28 }
29 }
30
31 /// Returns a line buffered writer to stdout for the given color choice.
32 ///
33 /// This writer is useful when printing results directly to a tty such that
34 /// users see output as soon as it's written. The downside of this approach
35 /// is that it can be slower, especially when there is a lot of output.
36 ///
37 /// You might consider using [`stdout`] instead, which chooses the buffering
38 /// strategy automatically based on whether stdout is connected to a tty.
39 pub fn stdout_buffered_linerust-analyzer cargo grep-cli 0.1.12 wtr/stdout_buffered_line().(
40 color_choice: termcolorrust-analyzer cargo termcolor 1.4.1 crate/::ColorChoicerust-analyzer cargo termcolor 1.4.1 ColorChoice#,
41 ) -> StandardStreamrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStream# {
42 let out = termcolorrust-analyzer cargo termcolor 1.4.1 crate/::StandardStreamrust-analyzer cargo termcolor 1.4.1 StandardStream#::stdoutrust-analyzer cargo termcolor 1.4.1 impl#[StandardStream]stdout().(color_choice);
43 StandardStreamrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStream#(StandardStreamKindrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#::LineBufferedrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#LineBuffered#(out))
44 }
45
46 /// Returns a block buffered writer to stdout for the given color choice.
47 ///
48 /// This writer is useful when printing results to a file since it amortizes
49 /// the cost of writing data. The downside of this approach is that it can
50 /// increase the latency of display output when writing to a tty.
51 ///
52 /// You might consider using [`stdout`] instead, which chooses the buffering
53 /// strategy automatically based on whether stdout is connected to a tty.
54 pub fn stdout_buffered_blockrust-analyzer cargo grep-cli 0.1.12 wtr/stdout_buffered_block().(
55 color_choice: termcolorrust-analyzer cargo termcolor 1.4.1 crate/::ColorChoicerust-analyzer cargo termcolor 1.4.1 ColorChoice#,
56 ) -> StandardStreamrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStream# {
57 let out = termcolorrust-analyzer cargo termcolor 1.4.1 crate/::BufferedStandardStreamrust-analyzer cargo termcolor 1.4.1 BufferedStandardStream#::stdoutrust-analyzer cargo termcolor 1.4.1 impl#[BufferedStandardStream]stdout().(color_choice);
58 StandardStreamrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStream#(StandardStreamKindrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#::BlockBufferedrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#BlockBuffered#(out))
59 }
60
61 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
62 enum StandardStreamKindrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind# {
63 LineBufferedrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#LineBuffered#(termcolorrust-analyzer cargo termcolor 1.4.1 crate/::StandardStreamrust-analyzer cargo termcolor 1.4.1 StandardStream#),
64 BlockBufferedrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#BlockBuffered#(termcolorrust-analyzer cargo termcolor 1.4.1 crate/::BufferedStandardStreamrust-analyzer cargo termcolor 1.4.1 BufferedStandardStream#),
65 }
66
67 impl iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# for StandardStreamrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStream# {
68 #[inline]
69 fn writerust-analyzer cargo grep-cli 0.1.12 wtr/impl#[StandardStream][Write]write().(&mut self, buf: &[u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> {
70 use selfrust-analyzer cargo grep-cli 0.1.12 wtr/::StandardStreamKindrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#::*;
71
72 match self.0rust-analyzer cargo grep-cli 0.1.12 wtr/StandardStream#0. {
73 LineBufferedrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#LineBuffered#(ref mut w) => w.writerust-analyzer cargo termcolor 1.4.1 impl#[StandardStream][Write]write().(buf),
74 BlockBufferedrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#BlockBuffered#(ref mut w) => w.writerust-analyzer cargo termcolor 1.4.1 impl#[BufferedStandardStream][Write]write().(buf),
75 }
76 }
77
78 #[inline]
79 fn flushrust-analyzer cargo grep-cli 0.1.12 wtr/impl#[StandardStream][Write]flush().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
80 use selfrust-analyzer cargo grep-cli 0.1.12 wtr/::StandardStreamKindrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#::*;
81
82 match self.0rust-analyzer cargo grep-cli 0.1.12 wtr/StandardStream#0. {
83 LineBufferedrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#LineBuffered#(ref mut w) => w.flushrust-analyzer cargo termcolor 1.4.1 impl#[StandardStream][Write]flush().(),
84 BlockBufferedrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#BlockBuffered#(ref mut w) => w.flushrust-analyzer cargo termcolor 1.4.1 impl#[BufferedStandardStream][Write]flush().(),
85 }
86 }
87 }
88
89 impl termcolorrust-analyzer cargo termcolor 1.4.1 crate/::WriteColorrust-analyzer cargo termcolor 1.4.1 WriteColor# for StandardStreamrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStream# {
90 #[inline]
91 fn supports_colorrust-analyzer cargo grep-cli 0.1.12 wtr/impl#[StandardStream][WriteColor]supports_color().(&self) -> bool {
92 use selfrust-analyzer cargo grep-cli 0.1.12 wtr/::StandardStreamKindrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#::*;
93
94 match self.0rust-analyzer cargo grep-cli 0.1.12 wtr/StandardStream#0. {
95 LineBufferedrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#LineBuffered#(ref w) => w.supports_colorrust-analyzer cargo termcolor 1.4.1 impl#[StandardStream][WriteColor]supports_color().(),
96 BlockBufferedrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#BlockBuffered#(ref w) => w.supports_colorrust-analyzer cargo termcolor 1.4.1 impl#[BufferedStandardStream][WriteColor]supports_color().(),
97 }
98 }
99
100 #[inline]
101 fn supports_hyperlinksrust-analyzer cargo grep-cli 0.1.12 wtr/impl#[StandardStream][WriteColor]supports_hyperlinks().(&self) -> bool {
102 use selfrust-analyzer cargo grep-cli 0.1.12 wtr/::StandardStreamKindrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#::*;
103
104 match self.0rust-analyzer cargo grep-cli 0.1.12 wtr/StandardStream#0. {
105 LineBufferedrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#LineBuffered#(ref w) => w.supports_hyperlinksrust-analyzer cargo termcolor 1.4.1 impl#[StandardStream][WriteColor]supports_hyperlinks().(),
106 BlockBufferedrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#BlockBuffered#(ref w) => w.supports_hyperlinksrust-analyzer cargo termcolor 1.4.1 impl#[BufferedStandardStream][WriteColor]supports_hyperlinks().(),
107 }
108 }
109
110 #[inline]
111 fn set_colorrust-analyzer cargo grep-cli 0.1.12 wtr/impl#[StandardStream][WriteColor]set_color().(&mut self, spec: &termcolorrust-analyzer cargo termcolor 1.4.1 crate/::ColorSpecrust-analyzer cargo termcolor 1.4.1 ColorSpec#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
112 use selfrust-analyzer cargo grep-cli 0.1.12 wtr/::StandardStreamKindrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#::*;
113
114 match self.0rust-analyzer cargo grep-cli 0.1.12 wtr/StandardStream#0. {
115 LineBufferedrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#LineBuffered#(ref mut w) => w.set_colorrust-analyzer cargo termcolor 1.4.1 impl#[StandardStream][WriteColor]set_color().(spec),
116 BlockBufferedrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#BlockBuffered#(ref mut w) => w.set_colorrust-analyzer cargo termcolor 1.4.1 impl#[BufferedStandardStream][WriteColor]set_color().(spec),
117 }
118 }
119
120 #[inline]
121 fn set_hyperlinkrust-analyzer cargo grep-cli 0.1.12 wtr/impl#[StandardStream][WriteColor]set_hyperlink().(&mut self, link: &HyperlinkSpecrust-analyzer cargo termcolor 1.4.1 HyperlinkSpec#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
122 use selfrust-analyzer cargo grep-cli 0.1.12 wtr/::StandardStreamKindrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#::*;
123
124 match self.0rust-analyzer cargo grep-cli 0.1.12 wtr/StandardStream#0. {
125 LineBufferedrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#LineBuffered#(ref mut w) => w.set_hyperlinkrust-analyzer cargo termcolor 1.4.1 impl#[StandardStream][WriteColor]set_hyperlink().(link),
126 BlockBufferedrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#BlockBuffered#(ref mut w) => w.set_hyperlinkrust-analyzer cargo termcolor 1.4.1 impl#[BufferedStandardStream][WriteColor]set_hyperlink().(link),
127 }
128 }
129
130 #[inline]
131 fn resetrust-analyzer cargo grep-cli 0.1.12 wtr/impl#[StandardStream][WriteColor]reset().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
132 use selfrust-analyzer cargo grep-cli 0.1.12 wtr/::StandardStreamKindrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#::*;
133
134 match self.0rust-analyzer cargo grep-cli 0.1.12 wtr/StandardStream#0. {
135 LineBufferedrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#LineBuffered#(ref mut w) => w.resetrust-analyzer cargo termcolor 1.4.1 impl#[StandardStream][WriteColor]reset().(),
136 BlockBufferedrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#BlockBuffered#(ref mut w) => w.resetrust-analyzer cargo termcolor 1.4.1 impl#[BufferedStandardStream][WriteColor]reset().(),
137 }
138 }
139
140 #[inline]
141 fn is_synchronousrust-analyzer cargo grep-cli 0.1.12 wtr/impl#[StandardStream][WriteColor]is_synchronous().(&self) -> bool {
142 use selfrust-analyzer cargo grep-cli 0.1.12 wtr/::StandardStreamKindrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#::*;
143
144 match self.0rust-analyzer cargo grep-cli 0.1.12 wtr/StandardStream#0. {
145 LineBufferedrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#LineBuffered#(ref w) => w.is_synchronousrust-analyzer cargo termcolor 1.4.1 impl#[StandardStream][WriteColor]is_synchronous().(),
146 BlockBufferedrust-analyzer cargo grep-cli 0.1.12 wtr/StandardStreamKind#BlockBuffered#(ref w) => w.is_synchronousrust-analyzer cargo termcolor 1.4.1 impl#[BufferedStandardStream][WriteColor]is_synchronous().(),
147 }
148 }
149 }