-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Increase the output color of search results #10116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
45aa206
877b339
aa668b4
971618e
742710c
8682ec6
bd82153
1c8354c
ce0b6ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,19 @@ impl Shell { | |
} | ||
} | ||
|
||
/// Print the message to standard output, where the query will have the color `color`. | ||
pub fn print_stdout_with_part_color( | ||
&mut self, | ||
name_no_query: Vec<&str>, | ||
desc_no_query: Vec<&str>, | ||
query: &str, | ||
color: Color, | ||
justified: bool, | ||
) -> CargoResult<()> { | ||
self.output | ||
.message_stdout(name_no_query, desc_no_query, query, color, justified) | ||
} | ||
|
||
/// Sets whether the next print should clear the current line. | ||
pub fn set_needs_clear(&mut self, needs_clear: bool) { | ||
self.needs_clear = needs_clear; | ||
|
@@ -195,7 +208,7 @@ impl Shell { | |
} | ||
} | ||
|
||
/// Shortcut to right-align and color green a status message. | ||
/// Shortcut to right-align and color green a status message in stderr. | ||
pub fn status<T, U>(&mut self, status: T, message: U) -> CargoResult<()> | ||
where | ||
T: fmt::Display, | ||
|
@@ -204,6 +217,16 @@ impl Shell { | |
self.print(&status, Some(&message), Green, true) | ||
} | ||
|
||
/// Shortcut to right-align and paint the query part of the output message as a green in stdout. | ||
pub fn status_stdout_part_green( | ||
&mut self, | ||
name_no_query: Vec<&str>, | ||
desc_no_query: Vec<&str>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you document what these arguments are? I can't figure out what these are from the signature/name of the method... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added explanation and changed parameter naming. |
||
query: &str, | ||
) -> CargoResult<()> { | ||
self.print_stdout_with_part_color(name_no_query, desc_no_query, query, Green, true) | ||
} | ||
|
||
pub fn status_header<T>(&mut self, status: T) -> CargoResult<()> | ||
where | ||
T: fmt::Display, | ||
|
@@ -423,6 +446,66 @@ impl ShellOut { | |
Ok(()) | ||
} | ||
|
||
/// Prints out a message with a status to stdout. Output the specified color and bold for the query content. | ||
/// name_no_specific:This refers to the string array after the crate name separated by characters matched by a specific string. | ||
/// desc_no_specific:This refers to the string array after the crate description separated by characters matched by a specific string. | ||
fn message_stdout( | ||
&mut self, | ||
name_no_specific: Vec<&str>, | ||
desc_no_specific: Vec<&str>, | ||
specific: &str, | ||
color: Color, | ||
justified: bool, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is always There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
) -> CargoResult<()> { | ||
fn print_message( | ||
stdout: &mut StandardStream, | ||
messages_vec: Vec<&str>, | ||
specific: &str, | ||
color: Color, | ||
) -> CargoResult<()> { | ||
let mut count = 0; | ||
for message in messages_vec.iter() { | ||
count += 1; | ||
stdout.reset()?; | ||
write!(stdout, "{}", message)?; | ||
stdout.set_color(ColorSpec::new().set_bold(true).set_fg(Some(color)))?; | ||
if count != messages_vec.len() { | ||
write!(stdout, "{}", specific)?; | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
match *self { | ||
ShellOut::Stream { ref mut stdout, .. } => { | ||
print_message(stdout, name_no_specific, specific, color)?; | ||
|
||
if !desc_no_specific.is_empty() { | ||
print_message(stdout, desc_no_specific, specific, color)?; | ||
} else { | ||
write!(stdout, " ")?; | ||
} | ||
|
||
stdout.reset()?; | ||
write!(stdout, "{}", "\n")?; | ||
} | ||
|
||
ShellOut::Write(ref mut w) => { | ||
if justified { | ||
write!(w, "{:>12}", name_no_specific.join(specific))?; | ||
} else { | ||
write!(w, "{}:", name_no_specific.join(specific))?; | ||
} | ||
if !desc_no_specific.is_empty() { | ||
writeln!(w, " {}", desc_no_specific.join(specific))? | ||
} else { | ||
writeln!(w, " ")?; | ||
} | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
/// Gets stdout as a `io::Write`. | ||
fn stdout(&mut self) -> &mut dyn Write { | ||
match *self { | ||
|
Uh oh!
There was an error while loading. Please reload this page.