Skip to content

Commit

Permalink
show color name if any
Browse files Browse the repository at this point in the history
  • Loading branch information
danieledapo authored and sharkdp committed Sep 1, 2019
1 parent 944653f commit fdfaf9c
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions src/cli/commands/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,51 @@ pub fn show_color_tty(out: &mut dyn Write, config: &Config, color: &Color) -> Re
color,
);

let mut text_y_offset = 0;
let similar = similar_colors(&color);

for (i, nc) in similar.iter().enumerate().take(3) {
if nc.color == *color {
canvas.draw_text(
text_position_y,
text_position_x,
&format!("Name: {}", nc.name),
);
text_y_offset = 2;
continue;
}

canvas.draw_text(text_position_y + 10 + 2 * i, text_position_x + 7, nc.name);
canvas.draw_rect(
text_position_y + 10 + 2 * i,
text_position_x + 1,
2,
5,
&nc.color,
);
}

canvas.draw_text(
text_position_y + 0,
text_position_y + 0 + text_y_offset,
text_position_x,
&format!("Hex: {}", color.to_rgb_hex_string(true)),
);
canvas.draw_text(
text_position_y + 2,
text_position_y + 2 + text_y_offset,
text_position_x,
&format!("RGB: {}", color.to_rgb_string(Format::Spaces)),
);
canvas.draw_text(
text_position_y + 4,
text_position_y + 4 + text_y_offset,
text_position_x,
&format!("HSL: {}", color.to_hsl_string(Format::Spaces)),
);

canvas.draw_text(text_position_y + 8, text_position_x, "Most similar:");
let similar = similar_colors(&color);
for (i, nc) in similar.iter().enumerate().take(3) {
canvas.draw_text(text_position_y + 10 + 2 * i, text_position_x + 7, nc.name);
canvas.draw_rect(
text_position_y + 10 + 2 * i,
text_position_x + 1,
2,
5,
&nc.color,
);
}
canvas.draw_text(
text_position_y + 8 + text_y_offset,
text_position_x,
"Most similar:",
);

canvas.print(out)
}
Expand Down

0 comments on commit fdfaf9c

Please sign in to comment.