Skip to content

Commit 8eca24a

Browse files
committed
bump yansi crate to 1.x, refactor for new API
1 parent 23a21aa commit 8eca24a

File tree

5 files changed

+33
-29
lines changed

5 files changed

+33
-29
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ itertools = "0.14"
2828
svg = "0.18"
2929
clap = {version = "4.0", optional = false, features = ["cargo"]}
3030
lazy_static = "1.4"
31-
yansi = "0.5"
31+
yansi = "1.0"
3232
atty = "0.2"
3333
platform-dirs = "0.3"
3434
crossterm = {version = "0.29", optional = false}

src/main.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,14 @@ fn from_args() -> Result<(), String> {
333333
match &mode[..] {
334334
"auto" => {
335335
atty::is(atty::Stream::Stdout)
336-
&& (!cfg!(windows) || yansi::Paint::enable_windows_ascii())
336+
&& (!cfg!(windows) || {
337+
yansi::enable();
338+
yansi::is_enabled()
339+
})
337340
}
338341
"always" => {
339342
if cfg!(windows) {
340-
yansi::Paint::enable_windows_ascii();
343+
yansi::enable();
341344
}
342345
true
343346
}
@@ -350,7 +353,11 @@ fn from_args() -> Result<(), String> {
350353
}
351354
}
352355
} else {
353-
atty::is(atty::Stream::Stdout) && (!cfg!(windows) || yansi::Paint::enable_windows_ascii())
356+
atty::is(atty::Stream::Stdout)
357+
&& (!cfg!(windows) || {
358+
yansi::enable();
359+
yansi::is_enabled()
360+
})
354361
};
355362

356363
let wrapping = if let Some(wrap_values) = matches.get_many::<String>("wrap") {

src/print/format.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ pub fn format_commit(
118118
add_line(&mut lines, &mut out, wrapping);
119119
} else {
120120
write!(out, "{}", &format[curr..start]).unwrap();
121+
let id = commit.id();
121122
match idx {
122123
HASH => {
123124
match mode {
@@ -126,9 +127,9 @@ pub fn format_commit(
126127
_ => {}
127128
}
128129
if let Some(color) = hash_color {
129-
write!(out, "{}", Paint::fixed(color, commit.id()))
130+
write!(out, "{}", id.to_string().fixed(color))
130131
} else {
131-
write!(out, "{}", commit.id())
132+
write!(out, "{}", id)
132133
}
133134
}
134135
HASH_ABBREV => {
@@ -138,13 +139,9 @@ pub fn format_commit(
138139
_ => {}
139140
}
140141
if let Some(color) = hash_color {
141-
write!(
142-
out,
143-
"{}",
144-
Paint::fixed(color, &commit.id().to_string()[..7])
145-
)
142+
write!(out, "{}", id.to_string()[..7].fixed(color))
146143
} else {
147-
write!(out, "{}", &commit.id().to_string()[..7])
144+
write!(out, "{}", &id.to_string()[..7])
148145
}
149146
}
150147
PARENT_HASHES => {
@@ -405,14 +402,11 @@ pub fn format_oneline(
405402
hash_color: Option<u8>,
406403
) -> Vec<String> {
407404
let mut out = String::new();
405+
let id = commit.id();
408406
if let Some(color) = hash_color {
409-
write!(
410-
out,
411-
"{}",
412-
Paint::fixed(color, &commit.id().to_string()[..7])
413-
)
407+
write!(out, "{}", id.to_string()[..7].fixed(color))
414408
} else {
415-
write!(out, "{}", &commit.id().to_string()[..7])
409+
write!(out, "{}", &id.to_string()[..7])
416410
}
417411
.unwrap();
418412

@@ -447,10 +441,11 @@ pub fn format(
447441
let mut out_vec = vec![];
448442
let mut out = String::new();
449443

444+
let id = commit.id();
450445
if let Some(color) = hash_color {
451-
write!(out, "commit {}", Paint::fixed(color, &commit.id()))
446+
write!(out, "commit {}", id.to_string().fixed(color))
452447
} else {
453-
write!(out, "commit {}", &commit.id())
448+
write!(out, "commit {}", &id)
454449
}
455450
.map_err(|err| err.to_string())?;
456451

src/print/unicode.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -618,10 +618,11 @@ fn print_graph(
618618

619619
if color {
620620
for cell in row {
621+
let chars = cell.char(characters);
621622
if cell.character == SPACE {
622-
write!(g_out, "{}", cell.char(characters))
623+
write!(g_out, "{}", chars)
623624
} else {
624-
write!(g_out, "{}", Paint::fixed(cell.color, cell.char(characters)))
625+
write!(g_out, "{}", chars.to_string().fixed(cell.color))
625626
}
626627
.unwrap();
627628
}
@@ -682,7 +683,7 @@ pub fn format_branches(
682683
if let Some(head) = head {
683684
if !head.is_branch {
684685
if color {
685-
write!(branch_str, " {}", Paint::fixed(HEAD_COLOR, head_str))
686+
write!(branch_str, " {}", head_str.fixed(HEAD_COLOR))
686687
} else {
687688
write!(branch_str, " {}", head_str)
688689
}
@@ -708,7 +709,7 @@ pub fn format_branches(
708709
if let Some(head) = head {
709710
if idx == 0 && head.is_branch {
710711
if color {
711-
write!(branch_str, "{} ", Paint::fixed(14, head_str))
712+
write!(branch_str, "{} ", head_str.fixed(14))
712713
} else {
713714
write!(branch_str, "{} ", head_str)
714715
}
@@ -717,7 +718,7 @@ pub fn format_branches(
717718
}
718719

719720
if color {
720-
write!(branch_str, "{}", Paint::fixed(branch_color, &branch.name))
721+
write!(branch_str, "{}", &branch.name.fixed(branch_color))
721722
} else {
722723
write!(branch_str, "{}", &branch.name)
723724
}
@@ -736,10 +737,11 @@ pub fn format_branches(
736737
let tag = &graph.all_branches[*tag_index];
737738
let tag_color = curr_color.unwrap_or(&tag.visual.term_color);
738739

740+
let tag_name = &tag.name[5..];
739741
if color {
740-
write!(branch_str, "{}", Paint::fixed(*tag_color, &tag.name[5..]))
742+
write!(branch_str, "{}", tag_name.fixed(*tag_color))
741743
} else {
742-
write!(branch_str, "{}", &tag.name[5..])
744+
write!(branch_str, "{}", tag_name)
743745
}
744746
.unwrap();
745747

0 commit comments

Comments
 (0)