Skip to content
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

feat: add custom colors #18

Merged
merged 5 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ edition = "2021"
clap = { version = "4.5.4", features = ["derive"] }
clap-stdin = "0.4.0"
color-eyre = "0.6.3"
console = "0.15.8"
crossterm = "0.27.0"
textwrap = "0.16.1"
unicode-width = "0.1.12"
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ kittysay <message>
echo <message> | kittysay
```

You can customize the output colors.

```sh
# -c <message color> <cat color>
kittysay -c 2 5 <message>
echo <message> | kittysay -c 2 5
```

### `--width`

You can use the `--width` flag to change the width of the speech bubble. Defaults to `45`, maxes out at a little less than the width of your terminal if you try to pass a very large number.
Expand Down
32 changes: 25 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ struct Cli {
/// Enable kittythink mode (thought bubble)
#[clap(long, short)]
think: bool,
/// Use custom colors. The first colors the message, the second colors the cat
#[arg(long, short, num_args(2))]
colors: Option<Vec<u8>>,
}

fn main() -> Result<()> {
Expand All @@ -75,18 +78,13 @@ fn main() -> Result<()> {
let mut lines = wrap(&args.message, width as usize);
let longest = lines.iter().map(|line| line.width()).max().unwrap();

println!(
let msg = format!(
"
{}
{}
{}
{}
{}
/l、
(゚、 。 7
l ~ヽ
じしf_,)ノ
",
{}",
chars.top.repeat(longest),
if lines.len() == 1 {
format!("{} {} {}", chars.single_left, lines[0], chars.single_right)
Expand Down Expand Up @@ -126,5 +124,25 @@ fn main() -> Result<()> {
chars.arrow,
);

let mut msg_color = console::Color::White;
let mut cat_color = console::Color::White;
if let Some(colors) = args.colors {
msg_color = console::Color::Color256(colors[0]);
cat_color = console::Color::Color256(colors[1]);
}

let cat = "
/l、
(゚、 。 7
l ~ヽ
じしf_,)ノ
";

println!(
"{}{}",
console::style(msg).fg(msg_color),
console::style(cat).fg(cat_color)
);

Ok(())
}