Skip to content

Commit 43dd097

Browse files
committed
Move the note function into util
Signed-off-by: Rustin170506 <29879298+Rustin170506@users.noreply.github.com>
1 parent 18be6d7 commit 43dd097

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

src/cargo/ops/registry/info/view.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::HashMap;
22
use std::io::Write;
33

4-
use crate::util::style::{ERROR, HEADER, LITERAL, NOP, NOTE, WARN};
4+
use crate::util::style::{note, ERROR, HEADER, LITERAL, NOP, NOTE, WARN};
55
use crate::{
66
core::{
77
dependency::DepKind, shell::Verbosity, Dependency, FeatureMap, Package, PackageId, SourceId,
@@ -405,15 +405,6 @@ fn suggest_cargo_tree(package_id: PackageId, stdout: &mut dyn Write) -> CargoRes
405405
), stdout)
406406
}
407407

408-
pub(super) fn note(msg: impl std::fmt::Display, stdout: &mut dyn Write) -> CargoResult<()> {
409-
let note = NOTE;
410-
let bold = anstyle::Style::new() | anstyle::Effects::BOLD;
411-
412-
writeln!(stdout, "{note}note{note:#}{bold}:{bold:#} {msg}",)?;
413-
414-
Ok(())
415-
}
416-
417408
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
418409
enum FeatureStatus {
419410
EnabledByUser,

src/cargo/ops/registry/search.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use anyhow::Context as _;
99
use url::Url;
1010

1111
use crate::util::style;
12+
use crate::util::style::note;
1213
use crate::util::style::LITERAL;
13-
use crate::util::style::NOTE;
1414
use crate::util::truncate_with_ellipsis;
1515
use crate::CargoResult;
1616
use crate::GlobalContext;
@@ -107,11 +107,3 @@ fn suggest_cargo_info(stdout: &mut dyn Write) -> CargoResult<()> {
107107
)
108108
}
109109

110-
pub(super) fn note(msg: impl std::fmt::Display, stdout: &mut dyn Write) -> CargoResult<()> {
111-
let note = NOTE;
112-
let bold = anstyle::Style::new() | anstyle::Effects::BOLD;
113-
114-
writeln!(stdout, "{note}note{note:#}{bold}:{bold:#} {msg}",)?;
115-
116-
Ok(())
117-
}

src/cargo/util/style.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
use std::io::Write;
2+
13
use anstyle::*;
24

5+
use super::CargoResult;
6+
37
pub const NOP: Style = Style::new();
48
pub const HEADER: Style = AnsiColor::Green.on_default().effects(Effects::BOLD);
59
pub const USAGE: Style = AnsiColor::Green.on_default().effects(Effects::BOLD);
@@ -11,3 +15,14 @@ pub const NOTE: Style = AnsiColor::Cyan.on_default().effects(Effects::BOLD);
1115
pub const GOOD: Style = AnsiColor::Green.on_default().effects(Effects::BOLD);
1216
pub const VALID: Style = AnsiColor::Cyan.on_default().effects(Effects::BOLD);
1317
pub const INVALID: Style = AnsiColor::Yellow.on_default().effects(Effects::BOLD);
18+
19+
20+
/// Write a note to the given writer.
21+
pub fn note(msg: impl std::fmt::Display, stdout: &mut dyn Write) -> CargoResult<()> {
22+
let note = NOTE;
23+
let bold = anstyle::Style::new() | anstyle::Effects::BOLD;
24+
25+
writeln!(stdout, "{note}note{note:#}{bold}:{bold:#} {msg}",)?;
26+
27+
Ok(())
28+
}

0 commit comments

Comments
 (0)